11<?php
22
3+ declare (strict_types=1 );
4+
35namespace TheCodingMachine \GraphQLite \Discovery \Cache ;
46
57use PHPUnit \Framework \Attributes \CoversClass ;
68use PHPUnit \Framework \TestCase ;
9+ use ReflectionClass ;
710use Symfony \Component \Cache \Adapter \ArrayAdapter ;
811use Symfony \Component \Cache \Psr16Cache ;
912use TheCodingMachine \GraphQLite \Discovery \StaticClassFinder ;
1013use TheCodingMachine \GraphQLite \Fixtures \TestType ;
11- use TheCodingMachine \GraphQLite \Fixtures \Types \EnumType ;
1214use TheCodingMachine \GraphQLite \Fixtures \Types \FooExtendType ;
1315use TheCodingMachine \GraphQLite \Fixtures \Types \FooType ;
1416use TheCodingMachine \GraphQLite \Loggers \ExceptionLogger ;
1517
16- use function Safe \touch ;
18+ use function array_values ;
19+ use function clearstatcache ;
1720use function Safe \filemtime ;
21+ use function Safe \touch ;
1822
1923#[CoversClass(SnapshotClassFinderComputedCache::class)]
2024class SnapshotClassFinderComputedCacheTest extends TestCase
2125{
22- public function testCachesIndividualEntries (): void
26+ public function testCachesIndividualEntriesSameList (): void
2327 {
2428 $ arrayAdapter = new ArrayAdapter ();
2529 $ arrayAdapter ->setLogger (new ExceptionLogger ());
2630 $ cache = new Psr16Cache ($ arrayAdapter );
2731
2832 $ classFinderComputedCache = new SnapshotClassFinderComputedCache ($ cache );
2933
34+ $ classList = [
35+ FooType::class,
36+ FooExtendType::class,
37+ TestType::class,
38+ ];
3039 [$ result ] = $ classFinderComputedCache ->compute (
31- new StaticClassFinder ([
32- FooType::class,
33- FooExtendType::class,
34- TestType::class,
35- ]),
40+ new StaticClassFinder ($ classList ),
3641 'key ' ,
37- fn (\ ReflectionClass $ reflection ) => $ reflection ->getShortName (),
38- fn (array $ entries ) => [array_values ($ entries )],
42+ static fn (ReflectionClass $ reflection ) => $ reflection ->getShortName (),
43+ static fn (array $ entries ) => [array_values ($ entries )],
3944 );
4045
4146 $ this ->assertSame ([
@@ -45,14 +50,10 @@ public function testCachesIndividualEntries(): void
4550 ], $ result );
4651
4752 [$ result ] = $ classFinderComputedCache ->compute (
48- new StaticClassFinder ([
49- FooType::class,
50- FooExtendType::class,
51- TestType::class,
52- ]),
53+ new StaticClassFinder ($ classList ),
5354 'key ' ,
54- fn (\ ReflectionClass $ reflection ) => self ::fail ('Should not be called. ' ),
55- fn (array $ entries ) => [array_values ($ entries )],
55+ static fn (ReflectionClass $ reflection ) => self ::fail ('Should not be called. ' ),
56+ static fn (array $ entries ) => [array_values ($ entries )],
5657 );
5758
5859 $ this ->assertSame ([
@@ -61,23 +62,19 @@ public function testCachesIndividualEntries(): void
6162 'TestType ' ,
6263 ], $ result );
6364
64- $ this ->touch ((new \ ReflectionClass (FooType::class))->getFileName ());
65+ $ this ->touch ((new ReflectionClass (FooType::class))->getFileName ());
6566
6667 [$ result ] = $ classFinderComputedCache ->compute (
67- new StaticClassFinder ([
68- FooType::class,
69- TestType::class,
70- EnumType::class,
71- ]),
68+ new StaticClassFinder ($ classList ),
7269 'key ' ,
73- fn (\ ReflectionClass $ reflection ) => $ reflection ->getShortName () . ' Modified ' ,
74- fn (array $ entries ) => [array_values ($ entries )],
70+ static fn (ReflectionClass $ reflection ) => $ reflection ->getShortName () . ' Modified ' ,
71+ static fn (array $ entries ) => [array_values ($ entries )],
7572 );
7673
7774 $ this ->assertSame ([
7875 'FooType Modified ' ,
76+ 'FooExtendType ' ,
7977 'TestType ' ,
80- 'EnumType Modified ' ,
8178 ], $ result );
8279 }
8380
@@ -86,4 +83,4 @@ private function touch(string $fileName): void
8683 touch ($ fileName , filemtime ($ fileName ) + 1 );
8784 clearstatcache ();
8885 }
89- }
86+ }
0 commit comments