Skip to content

Commit 6b03f0c

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [PhpUnitBridge] Fix qualification of deprecations triggered by the debug class loader Improve return phpdoc for Normalizer Use a partial buffer in SymfonyStyle Fix console closing tag Fix typo in comment [VarDumper] fix casting resources turned into objects on PHP 8
2 parents 1c1b79b + cf620b6 commit 6b03f0c

File tree

9 files changed

+114
-4
lines changed

9 files changed

+114
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor/
22
composer.lock
33
phpunit.xml
4+
Tests/DeprecationErrorHandler/fake_vendor/symfony/error-handler/DebugClassLoader.php

DeprecationErrorHandler/Deprecation.php

+14
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
@@ -58,6 +60,18 @@ public function __construct($message, array $trace, $file)
5860
}
5961

6062
$this->trace = $trace;
63+
64+
if ('trigger_error' === ($trace[1]['function'] ?? null)
65+
&& (DebugClassLoader::class === ($class = $trace[2]['class'] ?? null) || LegacyDebugClassLoader::class === $class)
66+
&& 'checkClass' === ($trace[2]['function'] ?? null)
67+
&& null !== ($extraFile = $trace[2]['args'][1] ?? null)
68+
&& '' !== $extraFile
69+
&& false !== $extraFile = realpath($extraFile)
70+
) {
71+
$this->getOriginalFilesStack();
72+
array_splice($this->originalFilesStack, 2, 1, $extraFile);
73+
}
74+
6175
$this->message = $message;
6276
$i = \count($this->trace);
6377
while (1 < $i && $this->lineShouldBeSkipped($this->trace[--$i])) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
if (!file_exists($errorHandlerRootDir = __DIR__.'/../../../../Component/ErrorHandler')) {
35+
if (!file_exists($errorHandlerRootDir = __DIR__.'/../../vendor/symfony/error-handler')) {
36+
die('Could not find the ErrorHandler component root directory.');
37+
}
38+
}
39+
40+
file_put_contents($fakeDebugClassLoadPath = __DIR__.'/fake_vendor/symfony/error-handler/DebugClassLoader.php', file_get_contents($errorHandlerRootDir.'/DebugClassLoader.php'));
41+
require $fakeDebugClassLoadPath;
42+
43+
\Symfony\Component\ErrorHandler\DebugClassLoader::enable();
44+
new \App\Services\BarService();
45+
46+
?>
47+
--EXPECTF--
48+
Remaining indirect deprecation notices (1)
49+
50+
1x: The "acme\lib\ExtendsDeprecatedClassFromOtherVendor" class extends "fcy\lib\DeprecatedClass" that is deprecated.
51+
1x in BarService::__construct from App\Services
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+
}

Tests/DeprecationErrorHandler/fake_vendor/composer/autoload_real.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,33 @@ public function getPrefixesPsr4()
1313
'App\\Services\\' => [__DIR__.'/../../fake_app/'],
1414
'acme\\lib\\' => [__DIR__.'/../acme/lib/'],
1515
'bar\\lib\\' => [__DIR__.'/../bar/lib/'],
16+
'fcy\\lib\\' => [__DIR__.'/../fcy/lib/'],
1617
];
1718
}
1819

1920
public function loadClass($className)
21+
{
22+
if ($file = $this->findFile($className)) {
23+
require $file;
24+
}
25+
}
26+
27+
public function findFile($class)
2028
{
2129
foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) {
22-
if (strpos($className, $prefix) !== 0) {
30+
if (strpos($class, $prefix) !== 0) {
2331
continue;
2432
}
2533

2634
foreach ($baseDirs as $baseDir) {
27-
$file = str_replace([$prefix, '\\'], [$baseDir, '/'], $className.'.php');
35+
$file = str_replace([$prefix, '\\'], [$baseDir, '/'], $class.'.php');
2836
if (file_exists($file)) {
29-
require $file;
37+
return $file;
3038
}
3139
}
3240
}
41+
42+
return false;
3343
}
3444
}
3545

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+
}

Tests/DeprecationErrorHandler/fake_vendor/symfony/error-handler/.gitkeep

Whitespace-only changes.

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"php": ">=5.5.9"
2222
},
2323
"require-dev": {
24-
"symfony/deprecation-contracts": "^2.1"
24+
"symfony/deprecation-contracts": "^2.1",
25+
"symfony/error-handler": "^4.4|^5.0"
2526
},
2627
"suggest": {
2728
"symfony/error-handler": "For tracking deprecated interfaces usages at runtime with DebugClassLoader"

0 commit comments

Comments
 (0)