public function PHPUnit_Framework_TestSuite::addTestFile

Wraps both <code>addTest()</code> and <code>addTestSuite</code> as well as the separate import statements for the user's convenience.

If the named file cannot be read or there are no new tests that can be added, a <code>PHPUnit_Framework_Warning</code> will be created instead, leaving the current test run untouched.

@since Method available since Release 2.3.0 @author Stefano F. Rausch <stefano@rausch-e.net>

Parameters

string $filename:

array $phptOptions Array with ini settings for the php instance: run, key being the name if the setting, value the ini value.

Throws

PHPUnit_Framework_Exception

2 calls to PHPUnit_Framework_TestSuite::addTestFile()
PHPUnit_Extensions_PhptTestSuite::__construct in drupal/core/vendor/phpunit/phpunit/PHPUnit/Extensions/PhptTestSuite.php
Constructs a new TestSuite for .phpt test cases.
PHPUnit_Framework_TestSuite::addTestFiles in drupal/core/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php
Wrapper for addTestFile() that adds multiple test files.

File

drupal/core/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php, line 340

Class

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

Code

public function addTestFile($filename, $phptOptions = array()) {
  if (!is_string($filename)) {
    throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  }
  if (file_exists($filename) && substr($filename, -5) == '.phpt') {
    $this
      ->addTest(new PHPUnit_Extensions_PhptTestCase($filename, $phptOptions));
    return;
  }
  PHPUnit_Util_Class::collectStart();
  $filename = PHPUnit_Util_Fileloader::checkAndLoad($filename);
  $newClasses = PHPUnit_Util_Class::collectEnd();
  $baseName = str_replace('.php', '', basename($filename));
  foreach ($newClasses as $className) {
    if (substr($className, 0 - strlen($baseName)) == $baseName) {
      $class = new ReflectionClass($className);
      if ($class
        ->getFileName() == $filename) {
        $newClasses = array(
          $className,
        );
        break;
      }
    }
  }
  $testsFound = FALSE;
  foreach ($newClasses as $className) {
    $class = new ReflectionClass($className);
    if (!$class
      ->isAbstract()) {
      if ($class
        ->hasMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME)) {
        $method = $class
          ->getMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME);
        if ($method
          ->isStatic()) {
          $this
            ->addTest($method
            ->invoke(NULL, $className));
          $testsFound = TRUE;
        }
      }
      else {
        if ($class
          ->implementsInterface('PHPUnit_Framework_Test')) {
          $this
            ->addTestSuite($class);
          $testsFound = TRUE;
        }
      }
    }
  }
  $this->numTests = -1;
}