1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace TheCodingMachine \GraphQLite \Discovery \Cache ;
4
6
5
7
use PHPUnit \Framework \Attributes \CoversClass ;
6
8
use PHPUnit \Framework \TestCase ;
9
+ use ReflectionClass ;
7
10
use Symfony \Component \Cache \Adapter \ArrayAdapter ;
8
11
use Symfony \Component \Cache \Psr16Cache ;
9
12
use TheCodingMachine \GraphQLite \Discovery \StaticClassFinder ;
10
13
use TheCodingMachine \GraphQLite \Fixtures \TestType ;
11
- use TheCodingMachine \GraphQLite \Fixtures \Types \EnumType ;
12
14
use TheCodingMachine \GraphQLite \Fixtures \Types \FooExtendType ;
13
15
use TheCodingMachine \GraphQLite \Fixtures \Types \FooType ;
14
16
use TheCodingMachine \GraphQLite \Loggers \ExceptionLogger ;
15
17
16
- use function Safe \touch ;
18
+ use function array_values ;
19
+ use function clearstatcache ;
17
20
use function Safe \filemtime ;
21
+ use function Safe \touch ;
18
22
19
23
#[CoversClass(SnapshotClassFinderComputedCache::class)]
20
24
class SnapshotClassFinderComputedCacheTest extends TestCase
21
25
{
22
- public function testCachesIndividualEntries (): void
26
+ public function testCachesIndividualEntriesSameList (): void
23
27
{
24
28
$ arrayAdapter = new ArrayAdapter ();
25
29
$ arrayAdapter ->setLogger (new ExceptionLogger ());
26
30
$ cache = new Psr16Cache ($ arrayAdapter );
27
31
28
32
$ classFinderComputedCache = new SnapshotClassFinderComputedCache ($ cache );
29
33
34
+ $ classList = [
35
+ FooType::class,
36
+ FooExtendType::class,
37
+ TestType::class,
38
+ ];
30
39
[$ result ] = $ classFinderComputedCache ->compute (
31
- new StaticClassFinder ([
32
- FooType::class,
33
- FooExtendType::class,
34
- TestType::class,
35
- ]),
40
+ new StaticClassFinder ($ classList ),
36
41
'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 )],
39
44
);
40
45
41
46
$ this ->assertSame ([
@@ -45,14 +50,10 @@ public function testCachesIndividualEntries(): void
45
50
], $ result );
46
51
47
52
[$ result ] = $ classFinderComputedCache ->compute (
48
- new StaticClassFinder ([
49
- FooType::class,
50
- FooExtendType::class,
51
- TestType::class,
52
- ]),
53
+ new StaticClassFinder ($ classList ),
53
54
'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 )],
56
57
);
57
58
58
59
$ this ->assertSame ([
@@ -61,23 +62,19 @@ public function testCachesIndividualEntries(): void
61
62
'TestType ' ,
62
63
], $ result );
63
64
64
- $ this ->touch ((new \ ReflectionClass (FooType::class))->getFileName ());
65
+ $ this ->touch ((new ReflectionClass (FooType::class))->getFileName ());
65
66
66
67
[$ result ] = $ classFinderComputedCache ->compute (
67
- new StaticClassFinder ([
68
- FooType::class,
69
- TestType::class,
70
- EnumType::class,
71
- ]),
68
+ new StaticClassFinder ($ classList ),
72
69
'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 )],
75
72
);
76
73
77
74
$ this ->assertSame ([
78
75
'FooType Modified ' ,
76
+ 'FooExtendType ' ,
79
77
'TestType ' ,
80
- 'EnumType Modified ' ,
81
78
], $ result );
82
79
}
83
80
@@ -86,4 +83,4 @@ private function touch(string $fileName): void
86
83
touch ($ fileName , filemtime ($ fileName ) + 1 );
87
84
clearstatcache ();
88
85
}
89
- }
86
+ }
0 commit comments