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 b263050

Browse filesBrowse files
committed
Introduce weak_lagging_vendors mode
In this mode, failures coming from vendors that call other vendors in a deprecated way are not taken into account when deciding to make the build fail. They also appear in a separate group.
1 parent b476479 commit b263050
Copy full SHA for b263050

File tree

5 files changed

+165
-6
lines changed
Filter options

5 files changed

+165
-6
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
+68-6Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class DeprecationErrorHandler
2020
{
2121
const MODE_WEAK = 'weak';
2222
const MODE_WEAK_VENDORS = 'weak_vendors';
23+
const MODE_WEAK_LAGGING_VENDORS = 'weak_lagging_vendors';
2324
const MODE_DISABLED = 'disabled';
2425

2526
private static $isRegistered = false;
@@ -30,6 +31,8 @@ class DeprecationErrorHandler
3031
* The following reporting modes are supported:
3132
* - use "weak" to hide the deprecation report but keep a global count;
3233
* - use "weak_vendors" to act as "weak" but only for vendors;
34+
* - use "weak_lagging_vendors" to act as "weak" but only for vendors that
35+
* failed to keep up with their upstream dependencies deprecations;
3336
* - use "/some-regexp/" to stop the test suite whenever a deprecation
3437
* message matches the given regular expression;
3538
* - use a number to define the upper bound of allowed deprecations,
@@ -54,7 +57,11 @@ public static function register($mode = 0)
5457
if (false === $mode) {
5558
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
5659
}
57-
if (DeprecationErrorHandler::MODE_WEAK !== $mode && DeprecationErrorHandler::MODE_WEAK_VENDORS !== $mode && (!isset($mode[0]) || '/' !== $mode[0])) {
60+
if (!in_array($mode, array(
61+
DeprecationErrorHandler::MODE_WEAK,
62+
DeprecationErrorHandler::MODE_WEAK_VENDORS,
63+
DeprecationErrorHandler::MODE_WEAK_LAGGING_VENDORS
64+
), true) && (!isset($mode[0]) || '/' !== $mode[0])) {
5865
$mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0;
5966
}
6067

@@ -67,11 +74,13 @@ public static function register($mode = 0)
6774
'remainingCount' => 0,
6875
'legacyCount' => 0,
6976
'otherCount' => 0,
77+
'lagging vendorCount' => 0,
7078
'remaining vendorCount' => 0,
7179
'unsilenced' => array(),
7280
'remaining' => array(),
7381
'legacy' => array(),
7482
'other' => array(),
83+
'lagging vendor' => array(),
7584
'remaining vendor' => array(),
7685
);
7786
$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix) {
@@ -85,8 +94,9 @@ public static function register($mode = 0)
8594
$trace = debug_backtrace(true);
8695
$group = 'other';
8796

88-
$isWeak = DeprecationErrorHandler::MODE_WEAK === $mode || (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor = self::inVendors($file));
89-
97+
$isWeak = DeprecationErrorHandler::MODE_WEAK === $mode ||
98+
(DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor = self::inVendors($file)) ||
99+
(DeprecationErrorHandler::MODE_WEAK_LAGGING_VENDORS === $mode && $isLaggingVendor = self::isLaggingVendor($trace));
90100
$i = count($trace);
91101
while (1 < $i && (!isset($trace[--$i]['class']) || ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_') || 0 === strpos($trace[$i]['class'], 'PHPUnit\\')))) {
92102
// No-op
@@ -114,6 +124,8 @@ public static function register($mode = 0)
114124
|| in_array('legacy', $Test::getGroups($class, $method), true)
115125
) {
116126
$group = 'legacy';
127+
} elseif (DeprecationErrorHandler::MODE_WEAK_LAGGING_VENDORS === $mode && $isLaggingVendor) {
128+
$group = 'lagging vendor';
117129
} elseif (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor) {
118130
$group = 'remaining vendor';
119131
} else {
@@ -188,13 +200,16 @@ public static function register($mode = 0)
188200
if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) {
189201
$groups[] = 'remaining vendor';
190202
}
203+
if (DeprecationErrorHandler::MODE_WEAK_LAGGING_VENDORS === $mode) {
204+
$groups[] = 'lagging vendor';
205+
}
191206
array_push($groups, 'legacy', 'other');
192207

193208
foreach ($groups as $group) {
194209
if ($deprecations[$group.'Count']) {
195210
echo "\n", $colorize(
196211
sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']),
197-
'legacy' !== $group && 'remaining vendor' !== $group
212+
!in_array($group, ['legacy', 'remaining vendor', 'lagging vendor'], true)
198213
), "\n";
199214

200215
uasort($deprecations[$group], $cmp);
@@ -223,10 +238,51 @@ public static function register($mode = 0)
223238
}
224239
}
225240

226-
private static function inVendors(string $path): bool
241+
private static function isLaggingVendor(array $trace): bool
242+
{
243+
foreach ($trace as $line) {
244+
if (isset($line['file'])) {
245+
$file = $line['file'];
246+
if ('-' === $file) {
247+
continue;
248+
}
249+
if (!self::inVendors($file)) {
250+
return false;
251+
}
252+
if (isset($erroringFile, $erroringPackage)) {
253+
if (self::getPackage($file) !== $erroringPackage) {
254+
return true;
255+
}
256+
} else {
257+
$erroringFile = $file;
258+
$erroringPackage = self::getPackage($file);
259+
}
260+
}
261+
}
262+
263+
return false;
264+
}
265+
266+
/**
267+
* inVendors() should always be called prior to calling this method
268+
*/
269+
private static function getPackage(string $path): string
270+
{
271+
$path = realpath($path) ?: $path;
272+
foreach (self::getVendors() as $vendorRoot) {
273+
if (0 === strpos($path, $vendorRoot)) {
274+
$relativePath = substr($path, strlen($vendorRoot) + 1);
275+
$vendor = strstr($relativePath, DIRECTORY_SEPARATOR, true);
276+
return $vendor.'/'.strstr(substr($relativePath, strlen($vendor) + 1), DIRECTORY_SEPARATOR, true);
277+
}
278+
}
279+
}
280+
281+
private static function getVendors(): ?array
227282
{
228283
/** @var string[] absolute paths to vendor directories */
229284
static $vendors;
285+
230286
if (null === $vendors) {
231287
foreach (get_declared_classes() as $class) {
232288
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
@@ -238,8 +294,14 @@ private static function inVendors(string $path): bool
238294
}
239295
}
240296
}
297+
298+
return $vendors;
299+
}
300+
301+
private static function inVendors(string $path): bool
302+
{
241303
$path = realpath($path) ?: $path;
242-
foreach ($vendors as $vendor) {
304+
foreach (self::getVendors() as $vendor) {
243305
if (0 === strpos($path, $vendor) && false !== strpbrk(substr($path, strlen($vendor), 1), '/'.DIRECTORY_SEPARATOR)) {
244306
return true;
245307
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/* We have not caught up on the deprecations yet and still call the other lib
3+
in a deprecated way. */
4+
5+
include __DIR__.'/../lib/deprecated_api.php';
6+
$defraculator = new \Acme\Lib\SomeService();
7+
$defraculator->deprecatedApi();
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
namespace Acme\Lib;
3+
4+
class SomeService
5+
{
6+
public function deprecatedApi()
7+
{
8+
@trigger_error(
9+
__FUNCTION__.' is deprecated! You should stop relying on it!',
10+
E_USER_DEPRECATED
11+
);
12+
}
13+
}
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Test DeprecationErrorHandler in weak vendors mode when calling deprecated api
3+
--FILE--
4+
<?php
5+
6+
putenv('SYMFONY_DEPRECATIONS_HELPER=weak_lagging_vendors');
7+
putenv('ANSICON');
8+
putenv('ConEmuANSI');
9+
putenv('TERM');
10+
11+
$vendor = __DIR__;
12+
while (!file_exists($vendor.'/vendor')) {
13+
$vendor = dirname($vendor);
14+
}
15+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
16+
require PHPUNIT_COMPOSER_INSTALL;
17+
require_once __DIR__.'/../../bootstrap.php';
18+
eval(<<<'EOPHP'
19+
namespace PHPUnit\Util;
20+
21+
class Test
22+
{
23+
public static function getGroups()
24+
{
25+
return array();
26+
}
27+
}
28+
EOPHP
29+
);
30+
require __DIR__.'/fake_vendor/autoload.php';
31+
require __DIR__.'/fake_vendor/acme/lib/deprecated_api.php';
32+
$defraculator = new \Acme\Lib\SomeService();
33+
$defraculator->deprecatedApi();
34+
35+
36+
?>
37+
--EXPECTF--
38+
Remaining deprecation notices (1)
39+
40+
deprecatedApi is deprecated! You should stop relying on it!: 1x
41+
1x in SomeService::deprecatedApi from Acme\Lib
42+
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Test DeprecationErrorHandler in weak vendors mode on vendor file
3+
--FILE--
4+
<?php
5+
6+
putenv('SYMFONY_DEPRECATIONS_HELPER=weak_lagging_vendors');
7+
putenv('ANSICON');
8+
putenv('ConEmuANSI');
9+
putenv('TERM');
10+
11+
$vendor = __DIR__;
12+
while (!file_exists($vendor.'/vendor')) {
13+
$vendor = dirname($vendor);
14+
}
15+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
16+
require PHPUNIT_COMPOSER_INSTALL;
17+
require_once __DIR__.'/../../bootstrap.php';
18+
eval(<<<'EOPHP'
19+
namespace PHPUnit\Util;
20+
21+
class Test
22+
{
23+
public static function getGroups()
24+
{
25+
return array();
26+
}
27+
}
28+
EOPHP
29+
);
30+
require __DIR__.'/fake_vendor/autoload.php';
31+
require __DIR__.'/fake_vendor/acme/lagging-lib/lagging_file.php';
32+
33+
?>
34+
--EXPECTF--
35+
Lagging vendor deprecation notices (1)

0 commit comments

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