Skip to content

Navigation Menu

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 2e3ffe2

Browse filesBrowse files
committed
bug #48122 [PhpUnitBridge] Fix language deprecations incorrectly marked as direct (wouterj)
This PR was merged into the 4.4 branch. Discussion ---------- [PhpUnitBridge] Fix language deprecations incorrectly marked as direct | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - When using a vendor class that has a language deprecation (e.g. missing `__serialize` methods), these deprecations were incorrectly considered "direct". Commits ------- 481a8c7 [PhpUnitBridge] Fix language deprecations incorrectly marked as direct
2 parents 969f19b + 481a8c7 commit 2e3ffe2
Copy full SHA for 2e3ffe2

File tree

4 files changed

+69
-3
lines changed
Filter options

4 files changed

+69
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function handleError($type, $msg, $file, $line, $context = [])
139139
$msg = $trace[1]['args'][0];
140140
}
141141

142-
$deprecation = new Deprecation($msg, $trace, $file);
142+
$deprecation = new Deprecation($msg, $trace, $file, \E_DEPRECATED === $type);
143143
if ($deprecation->isMuted()) {
144144
return null;
145145
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Deprecation
3737

3838
private $trace = [];
3939
private $message;
40+
private $languageDeprecation;
4041
private $originClass;
4142
private $originMethod;
4243
private $triggeringFile;
@@ -56,11 +57,13 @@ class Deprecation
5657
/**
5758
* @param string $message
5859
* @param string $file
60+
* @param bool $languageDeprecation
5961
*/
60-
public function __construct($message, array $trace, $file)
62+
public function __construct($message, array $trace, $file, $languageDeprecation = false)
6163
{
6264
$this->trace = $trace;
6365
$this->message = $message;
66+
$this->languageDeprecation = $languageDeprecation;
6467

6568
$i = \count($trace);
6669
while (1 < $i && $this->lineShouldBeSkipped($trace[--$i])) {
@@ -227,7 +230,12 @@ public function isMuted()
227230
*/
228231
public function getType()
229232
{
230-
if (self::PATH_TYPE_SELF === $pathType = $this->getPathType($this->triggeringFile)) {
233+
$pathType = $this->getPathType($this->triggeringFile);
234+
if ($this->languageDeprecation && self::PATH_TYPE_VENDOR === $pathType) {
235+
// the triggering file must be used for language deprecations
236+
return self::TYPE_INDIRECT;
237+
}
238+
if (self::PATH_TYPE_SELF === $pathType) {
231239
return self::TYPE_SELF;
232240
}
233241
if (self::PATH_TYPE_UNDETERMINED === $pathType) {
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace acme\lib;
4+
5+
class PhpDeprecation implements \Serializable
6+
{
7+
public function serialize(): string
8+
{
9+
return serialize([]);
10+
}
11+
12+
public function unserialize($data): void
13+
{
14+
}
15+
}
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Test that a PHP deprecation from a vendor class autoload is considered indirect.
3+
--SKIPIF--
4+
<?php if (\PHP_VERSION_ID < 80100) echo 'skip'; ?>
5+
--FILE--
6+
<?php
7+
8+
$k = 'SYMFONY_DEPRECATIONS_HELPER';
9+
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=0');
10+
putenv('ANSICON');
11+
putenv('ConEmuANSI');
12+
putenv('TERM');
13+
14+
$vendor = __DIR__;
15+
while (!file_exists($vendor.'/vendor')) {
16+
$vendor = dirname($vendor);
17+
}
18+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
19+
require PHPUNIT_COMPOSER_INSTALL;
20+
require_once __DIR__.'/../../bootstrap.php';
21+
eval(<<<'EOPHP'
22+
namespace PHPUnit\Util;
23+
24+
class Test
25+
{
26+
public static function getGroups()
27+
{
28+
return array();
29+
}
30+
}
31+
EOPHP
32+
);
33+
require __DIR__.'/fake_vendor/autoload.php';
34+
35+
\Symfony\Component\ErrorHandler\DebugClassLoader::enable();
36+
new \acme\lib\PhpDeprecation();
37+
38+
?>
39+
--EXPECTF--
40+
Remaining indirect deprecation notices (1)
41+
42+
1x: acme\lib\PhpDeprecation implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary)
43+
1x in DebugClassLoader::loadClass from Symfony\Component\ErrorHandler

0 commit comments

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