Skip to content

[PhpUnitBridge] Fix language deprecations incorrectly marked as direct #48122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function handleError($type, $msg, $file, $line, $context = [])
$msg = $trace[1]['args'][0];
}

$deprecation = new Deprecation($msg, $trace, $file);
$deprecation = new Deprecation($msg, $trace, $file, \E_DEPRECATED === $type);
if ($deprecation->isMuted()) {
return null;
}
Expand Down
12 changes: 10 additions & 2 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Deprecation

private $trace = [];
private $message;
private $languageDeprecation;
private $originClass;
private $originMethod;
private $triggeringFile;
Expand All @@ -56,11 +57,13 @@ class Deprecation
/**
* @param string $message
* @param string $file
* @param bool $languageDeprecation
*/
public function __construct($message, array $trace, $file)
public function __construct($message, array $trace, $file, $languageDeprecation = false)
{
$this->trace = $trace;
$this->message = $message;
$this->languageDeprecation = $languageDeprecation;

$i = \count($trace);
while (1 < $i && $this->lineShouldBeSkipped($trace[--$i])) {
Expand Down Expand Up @@ -227,7 +230,12 @@ public function isMuted()
*/
public function getType()
{
if (self::PATH_TYPE_SELF === $pathType = $this->getPathType($this->triggeringFile)) {
$pathType = $this->getPathType($this->triggeringFile);
if ($this->languageDeprecation && self::PATH_TYPE_VENDOR === $pathType) {
// the triggering file must be used for language deprecations
return self::TYPE_INDIRECT;
}
if (self::PATH_TYPE_SELF === $pathType) {
return self::TYPE_SELF;
}
if (self::PATH_TYPE_UNDETERMINED === $pathType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace acme\lib;

class PhpDeprecation implements \Serializable
{
public function serialize(): string
{
return serialize([]);
}

public function unserialize($data): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
Test that a PHP deprecation from a vendor class autoload is considered indirect.
--SKIPIF--
<?php if (\PHP_VERSION_ID < 80100) echo 'skip'; ?>
--FILE--
<?php

$k = 'SYMFONY_DEPRECATIONS_HELPER';
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=0');
putenv('ANSICON');
putenv('ConEmuANSI');
putenv('TERM');

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = dirname($vendor);
}
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
require_once __DIR__.'/../../bootstrap.php';
eval(<<<'EOPHP'
namespace PHPUnit\Util;

class Test
{
public static function getGroups()
{
return array();
}
}
EOPHP
);
require __DIR__.'/fake_vendor/autoload.php';

\Symfony\Component\ErrorHandler\DebugClassLoader::enable();
new \acme\lib\PhpDeprecation();

?>
--EXPECTF--
Remaining indirect deprecation notices (1)

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)
1x in DebugClassLoader::loadClass from Symfony\Component\ErrorHandler