Example #1
0
 protected function handleCustomTestSuite()
 {
     $modulesTests = -1;
     /*
     $this->options[0] is an array of all options '--xxx'.
       each values is an array(0=>'optionname', 1=>'value if given')
     $this->options[1] is a list of parameters given after options
       it can be array(0=>'test name', 1=>'filename')
     */
     foreach ($this->options[0] as $option) {
         switch ($option[0]) {
             case '--entrypoint':
                 $this->entryPoint = $option[1];
                 break;
             case '--all-modules':
                 $modulesTests = 0;
                 break;
             case '--module':
                 $modulesTests = 1;
                 // test is the module name
                 // testFile is the test file inside the module
                 break;
             case '--testtype':
                 $this->testType = $option[1];
                 break;
         }
     }
     if (isset($this->options[1][1]) && $modulesTests != 0) {
         // a specifique test file
         $this->arguments['testFile'] = $this->options[1][1];
     } else {
         $this->arguments['testFile'] = '';
     }
     $appInstaller = new jInstallerApplication();
     $this->epInfo = $appInstaller->getEntryPointInfo($this->entryPoint);
     // let's load configuration now, and coordinator. it could be needed by tests
     // (during load of their php files or during execution)
     jApp::setConfig(jConfigCompiler::readAndCache($this->epInfo->configFile, null, $this->entryPoint));
     jApp::setCoord(new jCoordinator('', false));
     if ($modulesTests == 0) {
         // we add all modules in the test list
         $suite = $this->getAllModulesTestSuites();
         if (count($suite)) {
             $this->arguments['test'] = $suite;
             unset($this->arguments['testFile']);
         } else {
             $this->showMessage("Error: no tests in modules\n");
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
     } else {
         if ($modulesTests == 1 && !$this->version36) {
             $suite = $this->getModuleTestSuite($this->options[1][0]);
             if (count($suite)) {
                 $this->arguments['test'] = $suite;
                 if (isset($this->options[1][1])) {
                     // a specifique test file
                     $this->arguments['testFile'] = $this->options[1][1];
                 } else {
                     $this->arguments['testFile'] = '';
                 }
             } else {
                 $this->showMessage("Error: no tests in the module\n");
                 exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
             }
         } else {
             if ($modulesTests == 1) {
                 if (isset($this->options[1][1])) {
                     // a specifique test file
                     $suite = $this->getModuleTestSuite($this->options[1][0], $this->options[1][1]);
                 } else {
                     $suite = $this->getModuleTestSuite($this->options[1][0]);
                 }
                 if (count($suite)) {
                     $this->arguments['test'] = $suite;
                 } else {
                     $this->showMessage("Error: no tests in the module\n");
                     exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
                 }
             }
         }
     }
 }
Example #2
0
 protected function getModuleTestSuite($module)
 {
     $appInstaller = new jInstallerApplication();
     $ep = $appInstaller->getEntryPointInfo($this->entryPoint);
     $moduleList = $ep->getModulesList();
     $topsuite = new PHPUnit_Framework_TestSuite();
     if (isset($moduleList[$module])) {
         $type = ($this->testType ? '.' . $this->testType : '') . '.pu.php';
         $suite = new JelixTestSuite($module);
         $testCollector = new PHPUnit_Runner_IncludePathTestCollector(array($moduleList[$module]), $type);
         $suite->addTestFiles($testCollector->collectTests());
         if (count($suite->tests()) > 0) {
             $topsuite->addTestSuite($suite);
         }
     }
     return $topsuite;
 }