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>
string $filename:
array $phptOptions Array with ini settings for the php instance: run, key being the name if the setting, value the ini value.
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;
}