Skip to content

Commit

Permalink
Merge branch '1.14.x' into 2.0.x
Browse files Browse the repository at this point in the history
* 1.14.x:
  Fix filemtime() warning because of eval'd code (#494)
  Test with Symfony Cache 7 (#499)
  • Loading branch information
derrabus committed Sep 5, 2024
2 parents 66d6765 + 253dca4 commit 901c2ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"doctrine/coding-standard": "^10",
"phpstan/phpstan": "^1.10.28",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"symfony/cache": "^5.4 || ^6",
"symfony/cache": "^5.4 || ^6.4 || ^7",
"vimeo/psalm": "^4.30 || ^5.14"
},
"suggest": {
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/Common/Annotations/PsrCachedReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use function array_merge;
use function assert;
use function filemtime;
use function is_file;
use function max;
use function rawurlencode;
use function time;
Expand Down Expand Up @@ -195,7 +196,7 @@ private function getLastModification(ReflectionClass $class): int
$parent = $class->getParentClass();

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

$lastModificationTime = max(array_merge(
[$fileName ? filemtime($fileName) : 0],
[$fileName !== false && is_file($fileName) ? filemtime($fileName) : 0],
array_map(function (ReflectionClass $reflectionTrait): int {
return $this->getTraitLastModificationTime($reflectionTrait);
}, $reflectionTrait->getTraits())
Expand Down
22 changes: 22 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/PsrCachedReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,28 @@ public function testReaderIsNotHitIfCacheIsFresh(): void
);
}

public function testReaderDoesNotCacheIfFileDoesNotExistSoLastModificationCannotBeDetermined(): void
{
$code = <<<'EOS'
namespace Doctrine\Tests\Common\Annotations;
/**
* @\Doctrine\Tests\Common\Annotations\Fixtures\AnnotationTargetClass("Some data")
*/
class PsrCachedEvalClass {
}
EOS;

eval($code);

$reader = new PsrCachedReader(new AnnotationReader(), new ArrayAdapter(), true);
// @phpstan-ignore class.notFound
$readAnnotations = $reader->getClassAnnotations(new ReflectionClass(PsrCachedEvalClass::class));

self::assertCount(1, $readAnnotations);
}

protected function doTestCacheStale(string $className, int $lastCacheModification): PsrCachedReader
{
$cacheKey = rawurlencode($className);
Expand Down

0 comments on commit 901c2ee

Please sign in to comment.