Skip to content

Commit dfac00a

Browse files
committed
[PhpUnitBridge] Fix language deprecations incorrectly marked as direct
1 parent ad0e25f commit dfac00a

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines 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

Lines changed: 16 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,18 @@ 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) {
235+
switch ($pathType) {
236+
case self::PATH_TYPE_VENDOR:
237+
return self::TYPE_INDIRECT;
238+
case self::PATH_TYPE_SELF:
239+
return self::TYPE_SELF;
240+
case self::PATH_TYPE_UNDETERMINED:
241+
return self::TYPE_UNDETERMINED;
242+
}
243+
}
244+
if (self::PATH_TYPE_SELF === $pathType) {
231245
return self::TYPE_SELF;
232246
}
233247
if (self::PATH_TYPE_UNDETERMINED === $pathType) {
Lines 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+
}
Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy