Example #1
0
 /**
  * Crawl the codebase and validate if all used classes are available.
  */
 public function test_spider_codebase()
 {
     $analyzer = new PhpAnalyzer();
     $modules = Framework::getModules();
     foreach ($modules as $module) {
         if (file_exists($module['path'] . 'init.php')) {
             $analyzer->open($module['path'] . 'init.php');
         }
         if (file_exists($module['path'] . 'functions.php')) {
             $analyzer->open($module['path'] . 'functions.php');
         }
     }
     if (file_exists(\Sledgehammer\PATH . 'public/rewrite.php')) {
         $analyzer->open(\Sledgehammer\PATH . 'public/rewrite.php');
     }
     $definitionCount = 0;
     $passes = [];
     $failed = false;
     while ($definitionCount != count($analyzer->usedDefinitions)) {
         $newDefinitions = array_slice($analyzer->usedDefinitions, $definitionCount);
         $definitionCount = count($analyzer->usedDefinitions);
         foreach (array_keys($newDefinitions) as $definition) {
             if ($this->tryGetInfo($analyzer, $definition) == false) {
                 $failed = true;
             }
         }
         $passes[] = count($newDefinitions);
     }
     if ($failed == false) {
         $this->assertTrue(true, 'The ' . count($analyzer->usedDefinitions) . ' detected definitions are found');
     }
 }
 /**
  * Controleer of de php extenties geinstalleerd zijn.
  */
 public function test_missing_extentions()
 {
     if (!function_exists('token_get_all')) {
         $this->fail('PHP extention "tokenizer" is required for this UnitTest');
         return;
     }
     $whitelist = array();
     if ($this->onlyClassesFolder) {
         // Alleen de classes mappen van de modules inlezen
         $modules = Framework::getModules();
         foreach ($modules as $module) {
             $this->checkFolder($module['path'] . 'classes/');
         }
     } else {
         // check all php files within $path
         $this->checkFolder(\Sledgehammer\PATH);
     }
     foreach ($this->missingExtensions as $extension => $definition) {
         $files = $this->extensionUsedIn[$extension];
         foreach ($files as $i => $filename) {
             if (isset($whitelist[$extension]) && in_array($filename, $whitelist[$extension])) {
                 unset($files[$i]);
             }
         }
         if (count($files) > 0) {
             $this->fail('Missing php extension "' . $extension . '". Function or class "' . $definition . '" is used in ' . \Sledgehammer\quoted_human_implode(' and', $files));
         }
     }
     $this->assertTrue(true, 'All required extenstion are installed');
 }