* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Polyfill\Util; /** * @author Nicolas Grekas
*/
class TestListenerTrait
{
public static $enabledPolyfills;
public function startTestSuite($mainSuite)
{
if (null !== self::$enabledPolyfills) {
return;
}
self::$enabledPolyfills = false;
$SkippedTestError = class_exists('PHPUnit\Framework\SkippedTestError') ? 'PHPUnit\Framework\SkippedTestError' : 'PHPUnit_Framework_SkippedTestError';
$TestListener = class_exists('Symfony\Polyfill\Util\TestListener', false) ? 'Symfony\Polyfill\Util\TestListener' : 'Symfony\Polyfill\Util\LegacyTestListener';
foreach ($mainSuite->tests() as $suite) {
$testClass = $suite->getName();
if (!$tests = $suite->tests()) {
continue;
}
if (!preg_match('/^(.+)\\\\Tests(\\\\.*)Test$/', $testClass, $m)) {
$mainSuite->addTest($TestListener::warning('Unknown naming convention for '.$testClass));
continue;
}
if (!class_exists($m[1].$m[2])) {
continue;
}
$testedClass = new \ReflectionClass($m[1].$m[2]);
$bootstrap = new \SplFileObject(dirname($testedClass->getFileName()).'/bootstrap.php');
$warnings = array();
$defLine = null;
foreach (new \RegexIterator($bootstrap, '/return p\\\\'.$testedClass->getShortName().'::/') as $defLine) {
if (!preg_match('/^\s*function (?P