Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7b889fb

Browse filesBrowse files
committed
[PhpUnitBridge] Fix qualification of deprecations triggered by the debug class loader
1 parent b60bb6e commit 7b889fb
Copy full SHA for 7b889fb

File tree

7 files changed

+108
-4
lines changed
Filter options

7 files changed

+108
-4
lines changed

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ install:
169169
# To run a PR with a patched phpunit-bridge, first submit the patch for the
170170
# phpunit-bridge as a separate PR against the next feature-branch then
171171
# uncomment and update the following line with that PR number
172-
#SYMFONY_PHPUNIT_BRIDGE_PR=32886
172+
SYMFONY_PHPUNIT_BRIDGE_PR=38597
173173
174174
if [[ $SYMFONY_PHPUNIT_BRIDGE_PR ]]; then
175175
git fetch --depth=2 origin refs/pull/$SYMFONY_PHPUNIT_BRIDGE_PR/head

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use PHPUnit\Util\Test;
1515
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerFor;
16+
use Symfony\Component\Debug\DebugClassLoader as LegacyDebugClassLoader;
17+
use Symfony\Component\ErrorHandler\DebugClassLoader;
1618

1719
/**
1820
* @internal
@@ -53,6 +55,18 @@ class Deprecation
5355
public function __construct($message, array $trace, $file)
5456
{
5557
$this->trace = $trace;
58+
59+
if ('trigger_error' === ($trace[1]['function'] ?? null)
60+
&& (DebugClassLoader::class === ($class = $trace[2]['class'] ?? null) || LegacyDebugClassLoader::class === $class)
61+
&& 'checkClass' === ($trace[2]['function'] ?? null)
62+
&& null !== ($extraFile = $trace[2]['args'][1] ?? null)
63+
&& '' !== $extraFile
64+
&& false !== $extraFile = realpath($extraFile)
65+
) {
66+
$this->getOriginalFilesStack();
67+
array_splice($this->originalFilesStack, 2, 1, $extraFile);
68+
}
69+
5670
$this->message = $message;
5771
$i = \count($trace);
5872
while (1 < $i && $this->lineShouldBeSkipped($trace[--$i])) {
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Test that a deprecation from the DebugClassLoader on a vendor class autoload triggered by an app class is considered indirect.
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+
// We need the real DebugClassLoader FQCN but in a vendor path.
34+
$realDebugClassLoaderPath = __DIR__.'/../../../../Component/ErrorHandler/DebugClassLoader.php';
35+
$fakeDebugClassLoadPath = __DIR__.'/fake_vendor/symfony/error-handler/DebugClassLoader.php';
36+
file_put_contents($fakeDebugClassLoadPath, file_get_contents($realDebugClassLoaderPath));
37+
require $fakeDebugClassLoadPath;
38+
39+
\Symfony\Component\ErrorHandler\DebugClassLoader::enable();
40+
new \App\Services\BarService();
41+
42+
?>
43+
--EXPECTF--
44+
Remaining indirect deprecation notices (1)
45+
46+
1x: The "acme\lib\ExtendsDeprecatedClassFromOtherVendor" class extends "fcy\lib\DeprecatedClass" that is deprecated.
47+
1x in BarService::__construct from App\Services
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Services;
4+
5+
use acme\lib\ExtendsDeprecatedClassFromOtherVendor;
6+
7+
final class BarService
8+
{
9+
public function __construct()
10+
{
11+
ExtendsDeprecatedClassFromOtherVendor::FOO;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace acme\lib;
4+
5+
use fcy\lib\DeprecatedClass;
6+
7+
final class ExtendsDeprecatedClassFromOtherVendor extends DeprecatedClass
8+
{
9+
public const FOO = 'bar';
10+
}

‎src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/composer/autoload_real.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/composer/autoload_real.php
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,33 @@ public function getPrefixesPsr4()
1212
return [
1313
'App\\Services\\' => [__DIR__.'/../../fake_app/'],
1414
'acme\\lib\\' => [__DIR__.'/../acme/lib/'],
15+
'fcy\\lib\\' => [__DIR__.'/../fcy/lib/'],
1516
];
1617
}
1718

1819
public function loadClass($className)
20+
{
21+
if ($file = $this->findFile($className)) {
22+
require $file;
23+
}
24+
}
25+
26+
public function findFile($class)
1927
{
2028
foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) {
21-
if (strpos($className, $prefix) !== 0) {
29+
if (strpos($class, $prefix) !== 0) {
2230
continue;
2331
}
2432

2533
foreach ($baseDirs as $baseDir) {
26-
$file = str_replace([$prefix, '\\'], [$baseDir, '/'], $className.'.php');
34+
$file = str_replace([$prefix, '\\'], [$baseDir, '/'], $class.'.php');
2735
if (file_exists($file)) {
28-
require $file;
36+
return $file;
2937
}
3038
}
3139
}
40+
41+
return false;
3242
}
3343
}
3444

+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace fcy\lib;
4+
5+
/**
6+
* @deprecated
7+
*/
8+
class DeprecatedClass
9+
{
10+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.