function test_if_case_provided_in_construct_autoruns()
 {
     ob_start();
     $CLI_runner = new LiteTest\TestRunnerCLI(new TestingTestCase());
     $result = ob_get_contents();
     ob_end_clean();
     $test_results = $CLI_runner->get_results();
     $this->assert_equals(2, sizeof($test_results["TestingTestCase"]));
 }
Пример #2
0
<?php

require dirname(__DIR__) . "/vendor/autoload.php";
require_once dirname(__FILE__) . "/.." . DIRECTORY_SEPARATOR . "LiteTestPHP.php";
$test_runner = new LiteTest\TestRunnerCLI();
require_once dirname(__FILE__) . "/battery.php";
$test_runner->print_results();
Пример #3
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();
 }
Пример #4
0
    }
    function test_1_my_class()
    {
        $my_class = new MyClass();
        $this->assert_true($my_class instanceof MyClass);
    }
    function test_2_my_class()
    {
        $my_class = new MyClass();
        $this->assert_true(false);
        $this->assert_true($my_class instanceof MyClass);
    }
    function test_3_my_class()
    {
        $my_class = new MyClass();
        $this->assert_true($my_class instanceof MyClass);
    }
    function test_4_my_class()
    {
        $my_class = new MyClass();
        $this->assert_true($my_class instanceof MyClass);
    }
}
// 3. Choose a TestRunner and add your TestCase (CLI runner in this case)
$runner = new LiteTest\TestRunnerCLI();
$runner->add_test_case(new TestCaseMyClass());
// 4. Run your tests
$runner->print_results();
class MyClass
{
}