diff --git a/src/Knp/Snappy/AbstractGenerator.php b/src/Knp/Snappy/AbstractGenerator.php index 53e1594..1131739 100644 --- a/src/Knp/Snappy/AbstractGenerator.php +++ b/src/Knp/Snappy/AbstractGenerator.php @@ -510,9 +510,11 @@ protected function createTemporaryFile($content = null, $extension = null) if (null !== $content) { \file_put_contents($filename, $content); - $this->temporaryFiles[] = $filename; } + // track temp file even if we don't write to it, the method calling this creation may write to it + $this->temporaryFiles[] = $filename; + return $filename; } diff --git a/tests/Knp/Snappy/AbstractGeneratorTest.php b/tests/Knp/Snappy/AbstractGeneratorTest.php index 8c97ed8..8a0a016 100644 --- a/tests/Knp/Snappy/AbstractGeneratorTest.php +++ b/tests/Knp/Snappy/AbstractGeneratorTest.php @@ -888,7 +888,7 @@ public function testCleanupEmptyTemporaryFiles(): void $create->invoke($generator, null, null); $files = new ReflectionProperty($generator, 'temporaryFiles'); - $this->assertCount(0, $files->getValue($generator)); + $this->assertCount(1, $files->getValue($generator)); $remove = new ReflectionMethod($generator, 'removeTemporaryFiles'); $remove->invoke($generator);