Skip to content
Open
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
8 changes: 6 additions & 2 deletions src/Knp/Snappy/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,12 @@ public function getCommand($input, $output, array $options = [])
*/
public function removeTemporaryFiles()
{
foreach ($this->temporaryFiles as $file) {
$this->unlink($file);
try {
foreach ($this->temporaryFiles as $file) {
$this->unlink($file);
}
} finally {
$this->temporaryFiles = [];
}
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Knp/Snappy/AbstractGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ public function testCleanupEmptyTemporaryFiles(): void

$remove = new ReflectionMethod($generator, 'removeTemporaryFiles');
$remove->invoke($generator);

$this->assertCount(0, $files->getValue($generator));
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case that verifies the temporaryFiles array is cleared even when unlink throws an exception. This would fully validate the purpose of the finally block introduced in this PR. The test could mock unlink to throw an exception and then verify that temporaryFiles is still emptied despite the exception.

Copilot uses AI. Check for mistakes.
}

public function testleanupTemporaryFiles(): void
Expand All @@ -887,6 +889,8 @@ public function testleanupTemporaryFiles(): void

$remove = new ReflectionMethod($generator, 'removeTemporaryFiles');
$remove->invoke($generator);

$this->assertCount(0, $files->getValue($generator));
}

public function testResetOptions(): void
Expand Down
Loading