PHPUnit_Framework_TestSuite::addTest PHP Method

addTest() public method

Adds a test to the suite.
public addTest ( PHPUnit_Framework_Test $test, array $groups = [] )
$test PHPUnit_Framework_Test
$groups array
    public function addTest(PHPUnit_Framework_Test $test, $groups = [])
    {
        $class = new ReflectionClass($test);
        if (!$class->isAbstract()) {
            $this->tests[] = $test;
            $this->numTests = -1;
            if ($test instanceof self && empty($groups)) {
                $groups = $test->getGroups();
            }
            if (empty($groups)) {
                $groups = ['default'];
            }
            foreach ($groups as $group) {
                if (!isset($this->groups[$group])) {
                    $this->groups[$group] = [$test];
                } else {
                    $this->groups[$group][] = $test;
                }
            }
            if ($test instanceof PHPUnit_Framework_TestCase) {
                $test->setGroups($groups);
            }
        }
    }

Usage Example

Example #1
0
 public function addCest($file)
 {
     $name = $this->relativeName($file);
     $this->tests[$name] = $file;
     $loaded_classes = get_declared_classes();
     require_once $file;
     $extra_loaded_classes = get_declared_classes();
     $testClasses = array_diff($extra_loaded_classes, $loaded_classes);
     foreach ($testClasses as $testClass) {
         $unit = new $testClass();
         $reflected = new \ReflectionClass($testClass);
         $methods = $reflected->getMethods(\ReflectionMethod::IS_PUBLIC);
         foreach ($methods as $method) {
             if ($method->isConstructor()) {
                 continue;
             }
             if ($method->isDestructor()) {
                 continue;
             }
             if (isset($unit->class)) {
                 $target = $unit->class;
                 $target .= $method->isStatic() ? '::' . $method->name : '.' . $method->name;
             } else {
                 $target = get_class($unit) . '::' . $method->name;
             }
             $this->suite->addTest(new \Codeception\TestCase\Cest($this->dispatcher, array('name' => $name . ':' . $target, 'class' => $unit, 'method' => $method->name, 'static' => $method->isStatic(), 'signature' => $target, 'file' => $file, 'bootstrap' => $this->settings['bootstrap'])));
         }
     }
 }
All Usage Examples Of PHPUnit_Framework_TestSuite::addTest