/usr/share/php/PHPUnit/Runner/StandardTestSuiteLoader.php is in phpunit 6.5.5-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | <?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Runner;
use PHPUnit\Framework\TestCase;
use PHPUnit\Util\Fileloader;
use PHPUnit\Util\Filesystem;
use ReflectionClass;
/**
* The standard test suite loader.
*/
class StandardTestSuiteLoader implements TestSuiteLoader
{
/**
* @param string $suiteClassName
* @param string $suiteClassFile
*
* @return ReflectionClass
*
* @throws Exception
*/
public function load($suiteClassName, $suiteClassFile = '')
{
$suiteClassName = \str_replace('.php', '', $suiteClassName);
if (empty($suiteClassFile)) {
$suiteClassFile = Filesystem::classNameToFilename(
$suiteClassName
);
}
if (!\class_exists($suiteClassName, false)) {
$loadedClasses = \get_declared_classes();
$filename = Fileloader::checkAndLoad($suiteClassFile);
$loadedClasses = \array_values(
\array_diff(\get_declared_classes(), $loadedClasses)
);
}
if (!\class_exists($suiteClassName, false) && !empty($loadedClasses)) {
$offset = 0 - \strlen($suiteClassName);
foreach ($loadedClasses as $loadedClass) {
$class = new ReflectionClass($loadedClass);
if (\substr($loadedClass, $offset) === $suiteClassName &&
$class->getFileName() == $filename) {
$suiteClassName = $loadedClass;
break;
}
}
}
if (!\class_exists($suiteClassName, false) && !empty($loadedClasses)) {
$testCaseClass = TestCase::class;
foreach ($loadedClasses as $loadedClass) {
$class = new ReflectionClass($loadedClass);
$classFile = $class->getFileName();
if ($class->isSubclassOf($testCaseClass) && !$class->isAbstract()) {
$suiteClassName = $loadedClass;
$testCaseClass = $loadedClass;
if ($classFile == \realpath($suiteClassFile)) {
break;
}
}
if ($class->hasMethod('suite')) {
$method = $class->getMethod('suite');
if (!$method->isAbstract() && $method->isPublic() && $method->isStatic()) {
$suiteClassName = $loadedClass;
if ($classFile == \realpath($suiteClassFile)) {
break;
}
}
}
}
}
if (\class_exists($suiteClassName, false)) {
$class = new ReflectionClass($suiteClassName);
if ($class->getFileName() == \realpath($suiteClassFile)) {
return $class;
}
}
throw new Exception(
\sprintf(
"Class '%s' could not be found in '%s'.",
$suiteClassName,
$suiteClassFile
)
);
}
/**
* @param ReflectionClass $aClass
*
* @return ReflectionClass
*/
public function reload(ReflectionClass $aClass)
{
return $aClass;
}
}
|