8000 bug #40508 [PhpUnitBridge] fix reporting deprecations from DebugClass… · symfony/symfony@0830672 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0830672

Browse files
bug #40508 [PhpUnitBridge] fix reporting deprecations from DebugClassLoader (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [PhpUnitBridge] fix reporting deprecations from DebugClassLoader | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #40400 | License | MIT | Doc PR | - Commits ------- cb68aea [PhpUnitBridge] fix reporting deprecations from DebugClassLoader
2 parents 5dd56a6 + cb68aea commit 0830672

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public function __construct($message, array $trace, $file)
7878
$this->triggeringFile = isset($trace[1 + $j]['args'][1]) ? realpath($trace[1 + $j]['args'][1]) : (new \ReflectionClass($class))->getFileName();
7979
$this->getOriginalFilesStack();
8080
array_splice($this->originalFilesStack, 0, $j, [$this->triggeringFile]);
81+
82+
if (preg_match('/(?|"([^"]++)" that is deprecated|should implement method "([^:]++))/', $message, $m) || preg_match('/^(?:The|Method) "([^":]++)/', $message, $m)) {
83+
$this->triggeringFile = (new \ReflectionClass($m[1]))->getFileName();
84+
array_unshift($this->originalFilesStack, $this->triggeringFile);
85+
}
8186
}
8287

8388
break;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Test that a deprecation from the DebugClassLoader triggered by an app class extending a vendor one is considered direct.
3+
--FILE--
4+
<?php
5+
6+
$k = 'SYMFONY_DEPRECATIONS_HELPER';
7+
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=0');
8+
putenv('ANSICON');
9+
putenv('ConEmuANSI');
10+
putenv('TERM');
11+
12+
$vendor = __DIR__;
13+
while (!file_exists($vendor.'/vendor')) {
14+
$vendor = dirname($vendor);
15+
}
16+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
17+
require PHPUNIT_COMPOSER_INSTALL;
18+
require_once __DIR__.'/../../bootstrap.php';
19+
eval(<<<'EOPHP'
20+
namespace PHPUnit\Util;
21+
22+
class Test
23+
{
24+
public static function getGroups()
25+
{
26+
return array();
27+
}
28+
}
29+
EOPHP
30+
);
31+
require __DIR__.'/fake_vendor/autoload.php';
32+
33+
\Symfony\Component\ErrorHandler\DebugClassLoader::enable();
34+
new \App\Services\ExtendsDeprecatedFromVendor();
35+
36+
?>
37+
--EXPECTF--
38+
Remaining direct deprecation notices (1)
39+
40+
1x: The "App\Services\ExtendsDeprecatedFromVendor" class extends "fcy\lib\DeprecatedClass" that is deprecated.
41+
1x in DebugClassLoader::loadClass from Symfony\Component\ErrorHandler
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
use fcy\lib\DeprecatedClass;
6+
7+
final class ExtendsDeprecatedFromVendor extends DeprecatedClass
8+
{
9+
}

0 commit comments

Comments
 (0)
0