From d5302cb5d25138fada872719b244eeed5fcef85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 5 Feb 2020 08:22:07 +0100 Subject: [PATCH] Provide current file as file path --- .../PhpUnit/DeprecationErrorHandler.php | 9 ++--- .../DeprecationErrorHandler/Deprecation.php | 34 +++++++++---------- .../DeprecationTest.php | 2 +- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 84a2f464c5d9..cbe405fa22bd 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -104,16 +104,13 @@ public static function collectDeprecations($outputFile) return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context); } - $trace = debug_backtrace(); $filesStack = []; - foreach ($trace as $line) { - if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) { + foreach (debug_backtrace() as $frame) { + if (!isset($frame['file']) || \in_array($frame['function'], ['require', 'require_once', 'include', 'include_once'], true)) { continue; } - if (isset($line['file'])) { - $filesStack[] = $line['file']; - } + $filesStack[] = $frame['file']; } $deprecations[] = [error_reporting(), $msg, $file, $filesStack]; diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php index 55909ee6cf3a..af9b4a539fae 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php @@ -165,24 +165,6 @@ public function isMuted() return false !== strpos($this->triggeringFile, \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR.'phpunit'.\DIRECTORY_SEPARATOR); } - private function getOriginalFilesStack(): array - { - if (null === $this->originalFilesStack) { - $this->originalFilesStack = []; - foreach ($this->trace as $line) { - if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) { - continue; - } - if (!isset($line['file'])) { - continue; - } - $this->originalFilesStack[] = $line['file']; - } - } - - return $this->originalFilesStack; - } - /** * Tells whether both the calling package and the called package are vendor * packages. @@ -224,6 +206,22 @@ public function getType() return self::TYPE_DIRECT; } + private function getOriginalFilesStack(): array + { + if (null === $this->originalFilesStack) { + $this->originalFilesStack = []; + foreach ($this->trace as $frame) { + if (!isset($frame['file']) || \in_array($frame['function'], ['require', 'require_once', 'include', 'include_once'], true)) { + continue; + } + + $this->originalFilesStack[] = $frame['file']; + } + } + + return $this->originalFilesStack; + } + /** * getPathType() should always be called prior to calling this method. * diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php index af3f688d5d2d..d1faa0cad850 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php @@ -157,7 +157,7 @@ public function providerGetTypeDetectsSelf(): array } return [ - 'not_from_vendors_file' => [Deprecation::TYPE_SELF, '', 'MyClass1', ''], + 'not_from_vendors_file' => [Deprecation::TYPE_SELF, '', 'MyClass1', __FILE__], 'nonexistent_file' => [Deprecation::TYPE_UNDETERMINED, '', 'MyClass1', 'dummy_vendor_path'], 'serialized_trace_with_nonexistent_triggering_file' => [ Deprecation::TYPE_UNDETERMINED,