Skip to content

Commit aeae705

Browse files
Merge branch '6.4' into 7.3
* 6.4: [HttpClient] Fix ever growing $maxHostConnections Fix typo [DependencyInjection] Fix referencing build-time array parameters cs fix [FrameworkBundle] Fix cache:pool:prune exit code on failure [Form] Always normalize CRLF and CR to LF in `TextareaType` [Cache] Fix stampede protection when forcing item recomputation [Console] Fix EofShortcut instruction when using a modern terminal on Windows [Console] Fix choice autocomplete issue when string has spaces [Serializer] Fix inconsistent field naming from accessors when using groups [Finder] Fix converting unanchored glob patterns to regex
2 parents 5d2e60f + 0ab60c0 commit aeae705

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

Command/CachePoolPruneCommand.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,21 @@ protected function configure(): void
5050
protected function execute(InputInterface $input, OutputInterface $output): int
5151
{
5252
$io = new SymfonyStyle($input, $output);
53+
$exitCode = Command::SUCCESS;
5354

5455
foreach ($this->pools as $name => $pool) {
5556
$io->comment(\sprintf('Pruning cache pool: <info>%s</info>', $name));
56-
$pool->prune();
57+
58+
if (!$pool->prune()) {
59+
$io->error(\sprintf('Cache pool "%s" could not be pruned.', $name));
60+
$exitCode = Command::FAILURE;
61+
}
5762
}
5863

59-
$io->success('Successfully pruned cache pool(s).');
64+
if (Command::SUCCESS === $exitCode) {
65+
$io->success('Successfully pruned cache pool(s).');
66+
}
6067

61-
return 0;
68+
return $exitCode;
6269
}
6370
}

Tests/Command/CachePruneCommandTest.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,44 @@ public function testCommandWithNoPools()
3535
$tester->execute([]);
3636
}
3737

38+
public function testCommandFailsOnPruneError()
39+
{
40+
$failedPool = $this->createMock(PruneableInterface::class);
41+
$failedPool->expects($this->once())->method('prune')->willReturn(false);
42+
43+
$generator = new RewindableGenerator(static function () use ($failedPool) {
44+
yield 'failed_pool' => $failedPool;
45+
}, 1);
46+
47+
$tester = $this->getCommandTester($this->getKernel(), $generator);
48+
$tester->execute([]);
49+
50+
$this->assertSame(1, $tester->getStatusCode());
51+
$this->assertStringContainsString('[ERROR] Cache pool "failed_pool" could not be pruned.', $tester->getDisplay());
52+
}
53+
54+
public function testCommandContinuesOnFailure()
55+
{
56+
$failedPool = $this->createMock(PruneableInterface::class);
57+
$failedPool->expects($this->once())->method('prune')->willReturn(false);
58+
59+
$successPool = $this->createMock(PruneableInterface::class);
60+
$successPool->expects($this->once())->method('prune')->willReturn(true);
61+
62+
$generator = new RewindableGenerator(static function () use ($failedPool, $successPool) {
63+
yield 'failed_pool' => $failedPool;
64+
yield 'success_pool' => $successPool;
65+
}, 2);
66+
67+
$tester = $this->getCommandTester($this->getKernel(), $generator);
68+
$tester->execute([]);
69+
70+
$this->assertSame(1, $tester->getStatusCode());
71+
$display = $tester->getDisplay();
72+
$this->assertStringContainsString('[ERROR] Cache pool "failed_pool" could not be pruned.', $display);
73+
$this->assertStringContainsString('Pruning cache pool: success_pool', $display);
74+
}
75+
3876
private function getRewindableGenerator(): RewindableGenerator
3977
{
4078
return new RewindableGenerator(function () {
@@ -45,7 +83,7 @@ private function getRewindableGenerator(): RewindableGenerator
4583

4684
private function getEmptyRewindableGenerator(): RewindableGenerator
4785
{
48-
return new RewindableGenerator(fn () => new \ArrayIterator([]), 0);
86+
return new RewindableGenerator(static fn () => new \ArrayIterator([]), 0);
4987
}
5088

5189
private function getKernel(): MockObject&KernelInterface

0 commit comments

Comments
 (0)