You are here

public function PHPUnit_Framework_TestSuite::__construct in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Framework/TestSuite.php \PHPUnit_Framework_TestSuite::__construct()

Constructs a new TestSuite:

  • 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.

Parameters

mixed $theClass:

string $name:

Throws

PHPUnit_Framework_Exception

2 methods override PHPUnit_Framework_TestSuite::__construct()
PHPUnit_Extensions_GroupTestSuite::__construct in vendor/phpunit/phpunit/src/Extensions/GroupTestSuite.php
Constructs a new TestSuite:
PHPUnit_Extensions_PhptTestSuite::__construct in vendor/phpunit/phpunit/src/Extensions/PhptTestSuite.php
Constructs a new TestSuite for .phpt test cases.

File

vendor/phpunit/phpunit/src/Framework/TestSuite.php, line 138

Class

PHPUnit_Framework_TestSuite
A TestSuite is a composite of Tests. It runs a collection of test cases.

Code

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;
}