Skip to content

Commit 901c2ee

Browse files
committed
Merge branch '1.14.x' into 2.0.x
* 1.14.x: Fix filemtime() warning because of eval'd code (#494) Test with Symfony Cache 7 (#499)
2 parents 66d6765 + 253dca4 commit 901c2ee

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"doctrine/coding-standard": "^10",
4343
"phpstan/phpstan": "^1.10.28",
4444
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
45-
"symfony/cache": "^5.4 || ^6",
45+
"symfony/cache": "^5.4 || ^6.4 || ^7",
4646
"vimeo/psalm": "^4.30 || ^5.14"
4747
},
4848
"suggest": {

lib/Doctrine/Common/Annotations/PsrCachedReader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use function array_merge;
1313
use function assert;
1414
use function filemtime;
15+
use function is_file;
1516
use function max;
1617
use function rawurlencode;
1718
use function time;
@@ -195,7 +196,7 @@ private function getLastModification(ReflectionClass $class): int
195196
$parent = $class->getParentClass();
196197

197198
$lastModification = max(array_merge(
198-
[$filename ? filemtime($filename) : 0],
199+
[$filename !== false && is_file($filename) ? filemtime($filename) : 0],
199200
array_map(function (ReflectionClass $reflectionTrait): int {
200201
return $this->getTraitLastModificationTime($reflectionTrait);
201202
}, $class->getTraits()),
@@ -219,7 +220,7 @@ private function getTraitLastModificationTime(ReflectionClass $reflectionTrait):
219220
}
220221

221222
$lastModificationTime = max(array_merge(
222-
[$fileName ? filemtime($fileName) : 0],
223+
[$fileName !== false && is_file($fileName) ? filemtime($fileName) : 0],
223224
array_map(function (ReflectionClass $reflectionTrait): int {
224225
return $this->getTraitLastModificationTime($reflectionTrait);
225226
}, $reflectionTrait->getTraits())

tests/Doctrine/Tests/Common/Annotations/PsrCachedReaderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,28 @@ public function testReaderIsNotHitIfCacheIsFresh(): void
220220
);
221221
}
222222

223+
public function testReaderDoesNotCacheIfFileDoesNotExistSoLastModificationCannotBeDetermined(): void
224+
{
225+
$code = <<<'EOS'
226+
namespace Doctrine\Tests\Common\Annotations;
227+
228+
/**
229+
* @\Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetClass("Some data")
230+
*/
231+
class PsrCachedEvalClass {
232+
233+
}
234+
EOS;
235+
236+
eval($code);
237+
238+
$reader = new PsrCachedReader(new AnnotationReader(), new ArrayAdapter(), true);
239+
// @phpstan-ignore class.notFound
240+
$readAnnotations = $reader->getClassAnnotations(new ReflectionClass(PsrCachedEvalClass::class));
241+
242+
self::assertCount(1, $readAnnotations);
243+
}
244+
223245
protected function doTestCacheStale(string $className, int $lastCacheModification): PsrCachedReader
224246
{
225247
$cacheKey = rawurlencode($className);

0 commit comments

Comments
 (0)