Skip to content

Commit eaf41b1

Browse files
Merge branch '5.4' into 6.2
* 5.4: [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 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 c24bec9 + d04639b commit eaf41b1

File tree

4 files changed

+95
-7
lines changed

4 files changed

+95
-7
lines changed

Diff for: DeprecationErrorHandler/Configuration.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ public function isBaselineDeprecation(Deprecation $deprecation)
238238
return false;
239239
}
240240

241-
if ($deprecation->originatesFromAnObject()) {
241+
if ($deprecation->originatesFromDebugClassLoader()) {
242+
$location = $deprecation->triggeringClass();
243+
} elseif ($deprecation->originatesFromAnObject()) {
242244
$location = $deprecation->originatingClass().'::'.$deprecation->originatingMethod();
243245
} else {
244246
$location = 'procedural code';

Diff for: DeprecationErrorHandler/Deprecation.php

+25
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Deprecation
4040
private $originClass;
4141
private $originMethod;
4242
private $triggeringFile;
43+
private $triggeringClass;
4344

4445
/** @var string[] Absolute paths to vendor directories */
4546
private static $vendors;
@@ -60,6 +61,10 @@ class Deprecation
6061
*/
6162
public function __construct($message, array $trace, $file, $languageDeprecation = false)
6263
{
64+
if (isset($trace[2]['class']) && \in_array($trace[2]['class'], [DebugClassLoader::class, LegacyDebugClassLoader::class], true)) {
65+
$this->triggeringClass = $trace[2]['args'][0];
66+
}
67+
6368
if (isset($trace[2]['function']) && 'trigger_deprecation' === $trace[2]['function']) {
6469
$file = $trace[2]['file'];
6570
array_splice($trace, 1, 1);
@@ -157,6 +162,26 @@ private function lineShouldBeSkipped(array $line)
157162
return 'ReflectionMethod' === $class || 0 === strpos($class, 'PHPUnit\\');
158163
}
159164

165+
/**
166+
* @return bool
167+
*/
168+
public function originatesFromDebugClassLoader()
169+
{
170+
return isset($this->triggeringClass);
171+
}
172+
173+
/**
174+
* @return string
175+
*/
176+
public function triggeringClass()
177+
{
178+
if (null === $this->triggeringClass) {
179+
throw new \LogicException('Check with originatesFromDebugClassLoader() before calling this method.');
180+
}
181+
182+
return $this->triggeringClass;
183+
}
184+
160185
/**
161186
* @return bool
162187
*/

Diff for: Tests/DeprecationErrorHandler/ConfigurationTest.php

+44-6
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()

Diff for: bin/simple-phpunit.php

+23
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
398398
}
399399
}
400400

401+
$lastOutput = null;
402+
$lastOutputTime = null;
403+
401404
while ($runningProcs) {
402405
usleep(300000);
403406
$terminatedProcs = [];
@@ -410,6 +413,26 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
410413
}
411414
}
412415

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

0 commit comments

Comments
 (0)