Skip to content

Commit e020e1e

Browse files
Merge branch '6.2' into 6.3
* 6.2: [PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s [Intl] fix test [Intl] Use VarExporter::export() in PhpBundleWriter Use triggering class to generate baseline for deprecation messages from DebugClassLoader [Security] Fix false-string handling in RememberMeAuthenticator [CssSelector] Tests on Xpath translator will always pass [Serializer] Fix Normalizer not utilizing converted name for index variadic param [DepdencyInjection] Fix costly logic when checking errored definitions Fix merge fix children cond [DoctrineBridge] Load refreshed user proxy [DependencyInjection] Don't ignore attributes on the actual decorator [FrameworkBundle] Prevent `cache:clear` to lose files on subsequent runs
2 parents 0b0bf59 + eaf41b1 commit e020e1e

File tree

4 files changed

+95
-7
lines changed

4 files changed

+95
-7
lines changed

DeprecationErrorHandler/Configuration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ public function isBaselineDeprecation(Deprecation $deprecation): bool
230230
return false;
231231
}
232232

233-
if ($deprecation->originatesFromAnObject()) {
233+
if ($deprecation->originatesFromDebugClassLoader()) {
234+
$location = $deprecation->triggeringClass();
235+
} elseif ($deprecation->originatesFromAnObject()) {
234236
$location = $deprecation->originatingClass().'::'.$deprecation->originatingMethod();
235237
} else {
236238
$location = 'procedural code';

DeprecationErrorHandler/Deprecation.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Deprecation
4141
private $originClass;
4242
private $originMethod;
4343
private $triggeringFile;
44+
private $triggeringClass;
4445

4546
/** @var string[] Absolute paths to vendor directories */
4647
private static $vendors;
@@ -61,6 +62,10 @@ class Deprecation
6162
*/
6263
public function __construct($message, array $trace, $file, $languageDeprecation = false)
6364
{
65+
if (DebugClassLoader::class === ($trace[2]['class'] ?? '')) {
66+
$this->triggeringClass = $trace[2]['args'][0];
67+
}
68+
6469
switch ($trace[2]['function'] ?? '') {
6570
case 'trigger_deprecation':
6671
$file = $trace[2]['file'];
@@ -167,6 +172,26 @@ private function lineShouldBeSkipped(array $line)
167172
return 'ReflectionMethod' === $class || 0 === strpos($class, 'PHPUnit\\');
168173
}
169174

175+
/**
176+
* @return bool
177+
*/
178+
public function originatesFromDebugClassLoader()
179+
{
180+
return isset($this->triggeringClass);
181+
}
182+
183+
/**
184+
* @return string
185+
*/
186+
public function triggeringClass()
187+
{
188+
if (null === $this->triggeringClass) {
189+
throw new \LogicException('Check with originatesFromDebugClassLoader() before calling this method.');
190+
}
191+
192+
return $this->triggeringClass;
193+
}
194+
170195
/**
171196
* @return bool
172197
*/

Tests/DeprecationErrorHandler/ConfigurationTest.php

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration;
1616
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
1717
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\DeprecationGroup;
18+
use Symfony\Component\ErrorHandler\DebugClassLoader;
1819

1920
class ConfigurationTest extends TestCase
2021
{
@@ -356,7 +357,7 @@ public function testBaselineGenerationEmptyFile()
356357
$this->assertTrue($configuration->isBaselineDeprecation(new Deprecation('Test message 1', $trace, '')));
357358
$configuration->writeBaseline();
358359
$this->assertEquals($filename, $configuration->getBaselineFile());
359-
$expected_baseline = [
360+
$expected = [
360361
[
361362
'location' => 'Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler\ConfigurationTest::runTest',
362363
'message' => 'Test message 1',
@@ -368,7 +369,7 @@ public function testBaselineGenerationEmptyFile()
368369
'count' => 1,
369370
],
370371
];
371-
$this->assertEquals(json_encode($expected_baseline, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename));
372+
$this->assertEquals(json_encode($expected, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename));
372373
}
373374

374375
public function testBaselineGenerationNoFile()
@@ -383,7 +384,7 @@ public function testBaselineGenerationNoFile()
383384
$this->assertTrue($configuration->isBaselineDeprecation(new Deprecation('Test message 1', $trace, '')));
384385
$configuration->writeBaseline();
385386
$this->assertEquals($filename, $configuration->getBaselineFile());
386-
$expected_baseline = [
387+
$expected = [
387388
[
388389
'location' => 'Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler\ConfigurationTest::runTest',
389390
'message' => 'Test message 1',
@@ -395,7 +396,7 @@ public function testBaselineGenerationNoFile()
395396
'count' => 2,
396397
],
397398
];
398-
$this->assertEquals(json_encode($expected_baseline, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename));
399+
$this->assertEquals(json_encode($expected, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename));
399400
}
400401

401402
public function testExistingBaseline()
@@ -447,7 +448,7 @@ public function testExistingBaselineAndGeneration()
447448
$this->assertTrue($configuration->isBaselineDeprecation(new Deprecation('Test message 3', $trace, '')));
448449
$configuration->writeBaseline();
449450
$this->assertEquals($filename, $configuration->getBaselineFile());
450-
$expected_baseline = [
451+
$expected = [
451452
[
452453
'location' => 'Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler\ConfigurationTest::runTest',
453454
'message' => 'Test message 2',
@@ -459,7 +460,44 @@ public function testExistingBaselineAndGeneration()
459460
'count' => 1,
460461
],
461462
];
462-
$this->assertEquals(json_encode($expected_baseline, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename));
463+
$this->assertEquals(json_encode($expected, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename));
464+
}
465+
466+
public function testBaselineGenerationWithDeprecationTriggeredByDebugClassLoader()
467+
{
468+
$filename = $this->createFile();
469+
$configuration = Configuration::fromUrlEncodedString('generateBaseline=true&baselineFile='.urlencode($filename));
470+
471+
$trace = debug_backtrace();
472+
$this->assertTrue($configuration->isBaselineDeprecation(new Deprecation('Regular deprecation', $trace, '')));
473+
474+
$trace[2] = [
475+
'class' => DebugClassLoader::class,
476+
'function' => 'testBaselineGenerationWithDeprecationTriggeredByDebugClassLoader',
477+
'args' => [self::class]
478+
];
479+
480+
$deprecation = new Deprecation('Deprecation by debug class loader', $trace, '');
481+
482+
$this->assertTrue($deprecation->originatesFromDebugClassLoader());
483+
484+
$this->assertTrue($configuration->isBaselineDeprecation($deprecation));
485+
486+
$configuration->writeBaseline();
487+
$this->assertEquals($filename, $configuration->getBaselineFile());
488+
$expected = [
489+
[
490+
'location' => 'Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler\ConfigurationTest::runTest',
491+
'message' => 'Regular deprecation',
492+
'count' => 1,
493+
],
494+
[
495+
'location' => self::class,
496+
'message' => 'Deprecation by debug class loader',
497+
'count' => 1,
498+
],
499+
];
500+
$this->assertEquals(json_encode($expected, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename));
463501
}
464502

465503
public function testBaselineArgumentException()

bin/simple-phpunit.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
401401
}
402402
}
403403

404+
$lastOutput = null;
405+
$lastOutputTime = null;
406+
404407
while ($runningProcs) {
405408
usleep(300000);
406409
$terminatedProcs = [];
@@ -413,6 +416,26 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
413416
}
414417
}
415418

419+
if (!$terminatedProcs && 1 === count($runningProcs)) {
420+
$component = key($runningProcs);
421+
422+
$output = file_get_contents("$component/phpunit.stdout");
423+
$output .= file_get_contents("$component/phpunit.stderr");
424+
425+
if ($lastOutput !== $output) {
426+
$lastOutput = $output;
427+
$lastOutputTime = microtime(true);
428+
} elseif (microtime(true) - $lastOutputTime > 60) {
429+
echo "\033[41mTimeout\033[0m $component\n\n";
430+
431+
if ('\\' === \DIRECTORY_SEPARATOR) {
432+
exec(sprintf('taskkill /F /T /PID %d 2>&1', $procStatus['pid']), $output, $exitCode);
433+
} else {
434+
proc_terminate(current($runningProcs));
435+
}
436+
}
437+
}
438+
416439
foreach ($terminatedProcs as $component => $procStatus) {
417440
foreach (['out', 'err'] as $file) {
418441
$file = "$component/phpunit.std$file";

0 commit comments

Comments
 (0)