diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index f9457c937d..b259337ee1 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -139,13 +139,10 @@ class DeprecationErrorHandler $group = 'unsilenced'; } elseif ($deprecation->isLegacy(self::$utilPrefix)) { $group = 'legacy'; + } elseif (!$deprecation->isSelf()) { + $group = $deprecation->isIndirect() ? 'remaining indirect' : 'remaining direct'; } else { - $group = [ - Deprecation::TYPE_SELF => 'remaining self', - Deprecation::TYPE_DIRECT => 'remaining direct', - Deprecation::TYPE_INDIRECT => 'remaining indirect', - Deprecation::TYPE_UNDETERMINED => 'other', - ][$deprecation->getType()]; + $group = 'remaining self'; } if ($this->getConfiguration()->shouldDisplayStackTrace($msg)) { diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php index 6d5b39fd54..ba9e753c7b 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php @@ -18,15 +18,6 @@ use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerFor; */ class Deprecation { - const PATH_TYPE_VENDOR = 'path_type_vendor'; - const PATH_TYPE_SELF = 'path_type_internal'; - const PATH_TYPE_UNDETERMINED = 'path_type_undetermined'; - - const TYPE_SELF = 'type_self'; - const TYPE_DIRECT = 'type_direct'; - const TYPE_INDIRECT = 'type_indirect'; - const TYPE_UNDETERMINED = 'type_undetermined'; - /** * @var array */ @@ -48,21 +39,13 @@ class Deprecation private $originMethod; /** - * @var string one of the PATH_TYPE_* constants + * @var bool */ - private $triggeringFilePathType; + private $self; /** @var string[] absolute paths to vendor directories */ private static $vendors; - /** - * @var string[] absolute paths to source or tests of the project. This - * excludes cache directories, because it is based on - * autoloading rules and cache systems typically do not use - * those. - */ - private static $internalPaths; - /** * @param string $message * @param string $file @@ -76,7 +59,7 @@ class Deprecation // No-op } $line = $trace[$i]; - $this->trigerringFilePathType = $this->getPathType($file); + $this->self = !$this->pathOriginatesFromVendor($file); if (isset($line['object']) || isset($line['class'])) { if (isset($line['class']) && 0 === strpos($line['class'], SymfonyTestsListenerFor::class)) { $parsedMsg = unserialize($this->message); @@ -87,9 +70,8 @@ class Deprecation // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest() // then we need to use the serialized information to determine // if the error has been triggered from vendor code. - if (isset($parsedMsg['triggering_file'])) { - $this->trigerringFilePathType = $this->getPathType($parsedMsg['triggering_file']); - } + $this->self = isset($parsedMsg['triggering_file']) + && $this->pathOriginatesFromVendor($parsedMsg['triggering_file']); return; } @@ -119,6 +101,14 @@ class Deprecation return isset($this->originClass); } + /** + * @return bool + */ + public function isSelf() + { + return $this->self; + } + /** * @return string */ @@ -173,16 +163,10 @@ class Deprecation * Tells whether both the calling package and the called package are vendor * packages. * - * @return string + * @return bool */ - public function getType() + public function isIndirect() { - if (self::PATH_TYPE_SELF === $this->trigerringFilePathType) { - return self::TYPE_SELF; - } - if (self::PATH_TYPE_UNDETERMINED === $this->trigerringFilePathType) { - return self::TYPE_UNDETERMINED; - } $erroringFile = $erroringPackage = null; foreach ($this->trace as $line) { if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) { @@ -195,16 +179,13 @@ class Deprecation if ('-' === $file || 'Standard input code' === $file || !realpath($file)) { continue; } - if (self::PATH_TYPE_SELF === $this->getPathType($file)) { - return self::TYPE_DIRECT; - } - if (self::PATH_TYPE_UNDETERMINED === $this->getPathType($file)) { - return self::TYPE_UNDETERMINED; + if (!$this->pathOriginatesFromVendor($file)) { + return false; } if (null !== $erroringFile && null !== $erroringPackage) { $package = $this->getPackage($file); if ('composer' !== $package && $package !== $erroringPackage) { - return self::TYPE_INDIRECT; + return true; } continue; } @@ -212,11 +193,11 @@ class Deprecation $erroringPackage = $this->getPackage($file); } - return self::TYPE_DIRECT; + return false; } /** - * getPathType() should always be called prior to calling this method. + * pathOriginatesFromVendor() should always be called prior to calling this method. * * @param string $path * @@ -256,15 +237,6 @@ class Deprecation $v = \dirname(\dirname($r->getFileName())); if (file_exists($v.'/composer/installed.json')) { self::$vendors[] = $v; - $loader = require $v.'/autoload.php'; - $paths = self::getSourcePathsFromPrefixes(array_merge($loader->getPrefixes(), $loader->getPrefixesPsr4())); - } - } - } - foreach ($paths as $path) { - foreach (self::$vendors as $vendor) { - if (0 !== strpos($path, $vendor)) { - self::$internalPaths[] = $path; } } } @@ -273,41 +245,24 @@ class Deprecation return self::$vendors; } - private static function getSourcePathsFromPrefixes(array $prefixesByNamespace) - { - foreach ($prefixesByNamespace as $prefixes) { - foreach ($prefixes as $prefix) { - if (false !== realpath($prefix)) { - yield realpath($prefix); - } - } - } - } - /** * @param string $path * - * @return string + * @return bool */ - private function getPathType($path) + private function pathOriginatesFromVendor($path) { $realPath = realpath($path); if (false === $realPath && '-' !== $path && 'Standard input code' !== $path) { - return self::PATH_TYPE_UNDETERMINED; + return true; } foreach (self::getVendors() as $vendor) { if (0 === strpos($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) { - return self::PATH_TYPE_VENDOR; + return true; } } - foreach (self::$internalPaths as $internalPath) { - if (0 === strpos($realPath, $internalPath)) { - return self::PATH_TYPE_SELF; - } - } - - return self::PATH_TYPE_UNDETERMINED; + return false; } /** @@ -326,4 +281,19 @@ class Deprecation "\n".str_replace(' '.getcwd().\DIRECTORY_SEPARATOR, ' ', $exception->getTraceAsString()). "\n"; } + + private function getPackageFromLine(array $line) + { + if (!isset($line['file'])) { + return 'internal function'; + } + if (!$this->pathOriginatesFromVendor($line['file'])) { + return 'source code'; + } + try { + return $this->getPackage($line['file']); + } catch (\RuntimeException $e) { + return 'unknown'; + } + } } diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php index 0c8708bb35..095f49c5c9 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php @@ -33,7 +33,7 @@ class DeprecationTest extends TestCase } $deprecation = new Deprecation('💩', $this->debugBacktrace(), __FILE__); - $this->assertSame(Deprecation::TYPE_SELF, $deprecation->getType()); + $this->assertTrue($deprecation->isSelf()); } public function testLegacyTestMethodIsDetectedAsSuch() @@ -52,7 +52,7 @@ class DeprecationTest extends TestCase public function testItRulesOutFilesOutsideVendorsAsIndirect() { $deprecation = new Deprecation('💩', $this->debugBacktrace(), __FILE__); - $this->assertNotSame(Deprecation::TYPE_INDIRECT, $deprecation->getType()); + $this->assertFalse($deprecation->isIndirect()); } /** diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt index 126d23389a..e9f7bec966 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt @@ -73,13 +73,15 @@ Unsilenced deprecation notices (3) 1x: unsilenced bar deprecation 1x in FooTestCase::testNonLegacyBar -Legacy deprecation notices (1) - -Other deprecation notices (2) - - 1x: root deprecation +Remaining self deprecation notices (1) 1x: silenced bar deprecation 1x in FooTestCase::testNonLegacyBar +Legacy deprecation notices (1) + +Other deprecation notices (1) + + 1x: root deprecation + I get precedence over any exit statements inside the deprecation error handler. diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/autoload.php b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/autoload.php index 3c4471bcbe..bf315f2eaa 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/autoload.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/autoload.php @@ -1,5 +1,3 @@