diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 6d49e81916ac6..a56dbfd5f5c7e 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -76,7 +76,7 @@ jobs: # To run a PR with a patched phpunit-bridge, first submit the patch for the # phpunit-bridge as a separate PR against the next feature-branch then # uncomment and update the following line with that PR number - #SYMFONY_PHPUNIT_BRIDGE_PR=32886 + SYMFONY_PHPUNIT_BRIDGE_PR=47252 if [[ $SYMFONY_PHPUNIT_BRIDGE_PR ]]; then git fetch --depth=2 origin refs/pull/$SYMFONY_PHPUNIT_BRIDGE_PR/head diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php index bc46e4f447912..926423e0e3482 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php @@ -174,7 +174,9 @@ public function isBaselineDeprecation(Deprecation $deprecation) return false; } - if ($deprecation->originatesFromAnObject()) { + if ($deprecation->originatesFromDebugClassLoader()) { + $location = $deprecation->triggeringClass(); + } elseif ($deprecation->originatesFromAnObject()) { $location = $deprecation->originatingClass().'::'.$deprecation->originatingMethod(); } else { $location = 'procedural code'; diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php index 5eda2bafdfb10..8dc4824b112e4 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php @@ -40,6 +40,7 @@ class Deprecation private $originClass; private $originMethod; private $triggeringFile; + private $triggeringClass; /** @var string[] Absolute paths to vendor directories */ private static $vendors; @@ -59,6 +60,10 @@ class Deprecation */ public function __construct($message, array $trace, $file) { + if (isset($trace[2]['class']) && DebugClassLoader::class === $trace[2]['class']) { + $this->triggeringClass = $trace[2]['args'][0]; + } + if (isset($trace[2]['function']) && 'trigger_deprecation' === $trace[2]['function']) { $file = $trace[2]['file']; array_splice($trace, 1, 1); @@ -155,6 +160,26 @@ private function lineShouldBeSkipped(array $line) return 'ReflectionMethod' === $class || 0 === strpos($class, 'PHPUnit\\'); } + /** + * @return bool + */ + public function originatesFromDebugClassLoader() + { + return isset($this->triggeringClass); + } + + /** + * @return string + */ + public function triggeringClass() + { + if (null === $this->triggeringClass) { + throw new \LogicException('Check with originatesFromDebugClassLoader() before calling this method.'); + } + + return $this->triggeringClass; + } + /** * @return bool */ diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php index 5d36a43bff54f..3c26d82788281 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php @@ -15,6 +15,7 @@ use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\DeprecationGroup; +use Symfony\Component\ErrorHandler\DebugClassLoader; class ConfigurationTest extends TestCase { @@ -365,6 +366,43 @@ public function testExistingBaselineAndGeneration() $this->assertEquals(json_encode($expected_baseline, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename)); } + public function testBaselineGenerationWithDeprecationTriggeredByDebugClassLoader() + { + $filename = $this->createFile(); + $configuration = Configuration::fromUrlEncodedString('generateBaseline=true&baselineFile='.urlencode($filename)); + + $trace = debug_backtrace(); + $this->assertTrue($configuration->isBaselineDeprecation(new Deprecation('Regular deprecation', $trace, ''))); + + $trace[2] = [ + 'class' => DebugClassLoader::class, + 'function' => 'testBaselineGenerationWithDeprecationTriggeredByDebugClassLoader', + 'args' => [self::class] + ]; + + $deprecation = new Deprecation('Deprecation by debug class loader', $trace, ''); + + $this->assertTrue($deprecation->originatesFromDebugClassLoader()); + + $this->assertTrue($configuration->isBaselineDeprecation($deprecation)); + + $configuration->writeBaseline(); + $this->assertEquals($filename, $configuration->getBaselineFile()); + $expected_baseline = [ + [ + 'location' => 'Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler\ConfigurationTest::runTest', + 'message' => 'Regular deprecation', + 'count' => 1, + ], + [ + 'location' => self::class, + 'message' => 'Deprecation by debug class loader', + 'count' => 1, + ], + ]; + $this->assertEquals(json_encode($expected_baseline, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename)); + } + public function testBaselineArgumentException() { $this->expectException(\InvalidArgumentException::class);