From 9f6cb3072800a24bb6d0bde441fa4560a8747a81 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 8 May 2020 14:25:07 +0200 Subject: [PATCH] [PhpUnitBridge] fix bad test --- .../DeprecationTest.php | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/Tests/DeprecationErrorHandler/DeprecationTest.php b/Tests/DeprecationErrorHandler/DeprecationTest.php index fd6d059e..403d23cd 100644 --- a/Tests/DeprecationErrorHandler/DeprecationTest.php +++ b/Tests/DeprecationErrorHandler/DeprecationTest.php @@ -22,6 +22,7 @@ class DeprecationTest extends TestCase use SetUpTearDownTrait; private static $vendorDir; + private static $prefixDirsPsr4; private static function getVendorDir() { @@ -151,22 +152,6 @@ public function testItTakesMutesDeprecationFromPhpUnitFiles() public function providerGetTypeDetectsSelf() { - foreach (get_declared_classes() as $class) { - if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) { - $r = new \ReflectionClass($class); - $v = \dirname(\dirname($r->getFileName())); - if (file_exists($v.'/composer/installed.json')) { - $loader = require $v.'/autoload.php'; - $reflection = new \ReflectionClass($loader); - $prop = $reflection->getProperty('prefixDirsPsr4'); - $prop->setAccessible(true); - $currentValue = $prop->getValue($loader); - $currentValue['Symfony\\Bridge\\PhpUnit\\'] = [realpath(__DIR__.'/../..')]; - $prop->setValue($loader, $currentValue); - } - } - } - return [ 'not_from_vendors_file' => [Deprecation::TYPE_SELF, '', 'MyClass1', __FILE__], 'nonexistent_file' => [Deprecation::TYPE_UNDETERMINED, '', 'MyClass1', 'dummy_vendor_path'], @@ -276,8 +261,32 @@ private static function removeDir($dir) rmdir($dir); } + private static function doSetupBeforeClass() + { + foreach (get_declared_classes() as $class) { + if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) { + $r = new \ReflectionClass($class); + $v = \dirname(\dirname($r->getFileName())); + if (file_exists($v.'/composer/installed.json')) { + $loader = require $v.'/autoload.php'; + $reflection = new \ReflectionClass($loader); + $prop = $reflection->getProperty('prefixDirsPsr4'); + $prop->setAccessible(true); + $currentValue = $prop->getValue($loader); + self::$prefixDirsPsr4[] = [$prop, $loader, $currentValue]; + $currentValue['Symfony\\Bridge\\PhpUnit\\'] = [realpath(__DIR__.'/../..')]; + $prop->setValue($loader, $currentValue); + } + } + } + } + private static function doTearDownAfterClass() { + foreach (self::$prefixDirsPsr4 as [$prop, $loader, $prefixDirsPsr4]) { + $prop->setValue($loader, $prefixDirsPsr4); + } + self::removeDir(self::getVendorDir().'/myfakevendor'); } }