File tree 2 files changed +16
-3
lines changed
src/Symfony/Component/RateLimiter
2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -42,11 +42,12 @@ public function save(LimiterStateInterface $limiterState): void
42
42
public function fetch (string $ limiterStateId ): ?LimiterStateInterface
43
43
{
44
44
$ cacheItem = $ this ->pool ->getItem (sha1 ($ limiterStateId ));
45
- if (!$ cacheItem ->isHit ()) {
46
- return null ;
45
+ $ value = $ cacheItem ->get ();
46
+ if ($ value instanceof LimiterStateInterface) {
47
+ return $ value ;
47
48
}
48
49
49
- return $ cacheItem -> get () ;
50
+ return null ;
50
51
}
51
52
52
53
public function delete (string $ limiterStateId ): void
Original file line number Diff line number Diff line change @@ -55,6 +55,18 @@ public function testFetchExistingState()
55
55
$ this ->assertEquals ($ window , $ this ->storage ->fetch ('test ' ));
56
56
}
57
57
58
+ public function testFetchExistingJunk ()
59
+ {
60
+ $ cacheItem = $ this ->createMock (CacheItemInterface::class);
61
+
62
+ $ cacheItem ->expects ($ this ->any ())->method ('get ' )->willReturn ('junk ' );
63
+ $ cacheItem ->expects ($ this ->any ())->method ('isHit ' )->willReturn (true );
64
+
65
+ $ this ->pool ->expects ($ this ->any ())->method ('getItem ' )->with (sha1 ('test ' ))->willReturn ($ cacheItem );
66
+
67
+ $ this ->assertNull ($ this ->storage ->fetch ('test ' ));
68
+ }
69
+
58
70
public function testFetchNonExistingState ()
59
71
{
60
72
$ cacheItem = $ this ->createMock (CacheItemInterface::class);
You can’t perform that action at this time.
0 commit comments