diff --git a/src/Knp/Snappy/AbstractGenerator.php b/src/Knp/Snappy/AbstractGenerator.php index 529bc7c..0357a62 100644 --- a/src/Knp/Snappy/AbstractGenerator.php +++ b/src/Knp/Snappy/AbstractGenerator.php @@ -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 = []; } } diff --git a/tests/Knp/Snappy/AbstractGeneratorTest.php b/tests/Knp/Snappy/AbstractGeneratorTest.php index fe5e07c..e5728c2 100644 --- a/tests/Knp/Snappy/AbstractGeneratorTest.php +++ b/tests/Knp/Snappy/AbstractGeneratorTest.php @@ -861,6 +861,8 @@ public function testCleanupEmptyTemporaryFiles(): void $remove = new ReflectionMethod($generator, 'removeTemporaryFiles'); $remove->invoke($generator); + + $this->assertCount(0, $files->getValue($generator)); } public function testleanupTemporaryFiles(): void @@ -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