PHPUnit_Framework_TestSuite::__construct PHP Method

__construct() public method

- PHPUnit_Framework_TestSuite() constructs an empty TestSuite. - PHPUnit_Framework_TestSuite(ReflectionClass) constructs a TestSuite from the given class. - PHPUnit_Framework_TestSuite(ReflectionClass, String) constructs a TestSuite from the given class with the given name. - PHPUnit_Framework_TestSuite(String) either constructs a TestSuite from the given class (if the passed string is the name of an existing class) or constructs an empty TestSuite with the given name.
public __construct ( mixed $theClass = '', string $name = '' )
$theClass mixed
$name string
    public function __construct($theClass = '', $name = '')
    {
        $argumentsValid = false;
        if (is_object($theClass) && $theClass instanceof ReflectionClass) {
            $argumentsValid = true;
        } elseif (is_string($theClass) && $theClass !== '' && class_exists($theClass, false)) {
            $argumentsValid = true;
            if ($name == '') {
                $name = $theClass;
            }
            $theClass = new ReflectionClass($theClass);
        } elseif (is_string($theClass)) {
            $this->setName($theClass);
            return;
        }
        if (!$argumentsValid) {
            throw new PHPUnit_Framework_Exception();
        }
        if (!$theClass->isSubclassOf('PHPUnit_Framework_TestCase')) {
            throw new PHPUnit_Framework_Exception('Class "' . $theClass->name . '" does not extend PHPUnit_Framework_TestCase.');
        }
        if ($name != '') {
            $this->setName($name);
        } else {
            $this->setName($theClass->getName());
        }
        $constructor = $theClass->getConstructor();
        if ($constructor !== null && !$constructor->isPublic()) {
            $this->addTest(self::warning(sprintf('Class "%s" has no public constructor.', $theClass->getName())));
            return;
        }
        foreach ($theClass->getMethods() as $method) {
            $this->addTestMethod($theClass, $method);
        }
        if (empty($this->tests)) {
            $this->addTest(self::warning(sprintf('No tests found in class "%s".', $theClass->getName())));
        }
        $this->testCase = true;
    }

Usage Example

Example #1
0
 /**
  * Basic constructor for test suite
  * 
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $this->setName('php-commit-hooks - base tests');
     $this->addTest(pchBaseRunnerTests::suite());
     $this->addTest(pchBaseStringStreamTests::suite());
 }
All Usage Examples Of PHPUnit_Framework_TestSuite::__construct