8000 [PhpUnitBridge] fix reporting deprecations from DebugClassLoader · symfony/symfony@cb68aea · GitHub
[go: up one dir, main page]

Skip to content

Commit cb68aea

Browse files
[PhpUnitBridge] fix reporting deprecations from DebugClassLoader
1 parent a78fb18 commit cb68aea

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
@@ -76,6 +76,11 @@ public function __construct($message, array $trace, $file)
7676
$this->triggeringFile = isset($trace[1 + $j]['args'][1]) ? realpath($trace[1 + $j]['args'][1]) : (new \ReflectionClass($class))->getFileName();
7777
$this->getOriginalFilesStack();
7878
array_splice($this->originalFilesStack, 0, $j, [$this->triggeringFile]);
79+
80+
if (preg_match('/(?|"([^"]++)" that is deprecated|should implement method "([^:]++))/', $message, $m) || preg_match('/^(?:The|Method) "([^":]++)/', $message, $m)) {
81+
$this->triggeringFile = (new \ReflectionClass($m[1]))->getFileName();
82+
array_unshift($this->originalFilesStack, $this->triggeringFile);
83+
}
7984
}
8085

8186
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