Beispiel #1
0
 function execute($cli, array $options, array $args)
 {
     $this->cli = $cli;
     $this->args = $cli->getArguments();
     $this->cwd = getcwd();
     $this->debug = false;
     $this->debug = $cli->getOptionValue('debug');
     // print_r($cli->getOptions());
     // print_r($cli->getArguments());
     $this->setup();
     if ($this->debug) {
         print __METHOD__ . " after setup \n";
     }
     //
     // Load the bootstrap file
     //
     $before_classes = get_declared_classes();
     // if( DEBUG ) print_r($this);
     try {
         if ($this->debug) {
             print "Loading files ... \n";
         }
         if (!is_null($this->bootstrap_file)) {
             if ($this->debug) {
                 print "Loading bootstrap : {$this->bootstrap_file}\n";
             }
             include $this->bootstrap_file;
         }
         foreach ($this->tests as $test_file) {
             $fn = $this->tests_relative_to . "/" . $test_file;
             if ($this->debug) {
                 print "loading : {$fn} \n";
             }
             error_reporting(-1);
             include $fn;
             if ($this->debug) {
                 print "loaded : {$fn} \n";
             }
         }
     } catch (\Exception $e) {
         $this->throw_fatal_error($e->getMessage(), $e);
     }
     $testClasses = [];
     $after = array_diff(get_declared_classes(), [__CLASS__]);
     $classes_to_test = array_diff($after, $before_classes);
     // print __METHOD__."\n";
     // print_r($classes_to_test);
     // print __METHOD__."\n";
     foreach ($classes_to_test as $klass) {
         // if( preg_match("/^Test/", $klass) )
         if (preg_match(self::TEST_CLASS_REGEX, $klass)) {
             $testClasses[] = $klass;
             if ($this->debug) {
                 print " class : {$klass} added as test case \n";
             }
         } else {
             if ($this->debug) {
                 print " class : {$klass} REJECTED as test case \n";
             }
         }
     }
     $runner = new \LiteTest\TestRunnerCLI();
     $runner->setOutputDebug($this->cli->getOptionValue('debug'));
     $runner->setOutputVerbose($this->cli->getOptionValue('verbose'));
     foreach ($testClasses as $suite) {
         $suite_obj = new $suite();
         $suite_obj->setOutputDebug($this->cli->getOptionValue('debug'));
         $suite_obj->setOutputVerbose($this->cli->getOptionValue('verbose'));
         $runner->add_test_case($suite_obj);
     }
     //
     // Test for empty set of tests
     //
     $cc = new Colors\Color();
     if (count($testClasses) == 0) {
         echo $cc("WARNING ")->red()->bold();
         echo $cc("  No classes have been named to be test Suites (Test????) - ")->reset();
         echo $cc(" is this correct !!")->white()->bold();
         echo "\n";
     } else {
         foreach ($runner->get_test_cases() as $obj) {
             $arr = $obj->get_tests();
             if (count($arr) == 0) {
                 echo $cc("WARNING")->red()->bold();
                 echo $cc(" class ")->reset();
                 echo $cc(get_class($obj))->cyan()->bold();
                 echo $cc(" has no tests method (test_???) - ")->reset();
                 echo $cc(" is this correct ")->white()->bold();
                 echo "\n ";
             }
         }
     }
     $runner->print_results();
 }