File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
src/Symfony/Component/RateLimiter Expand file tree Collapse file tree 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
4242 public function fetch (string $ limiterStateId ): ?LimiterStateInterface
4343 {
4444 $ 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 ;
4748 }
4849
49- return $ cacheItem -> get () ;
50+ return null ;
5051 }
5152
5253 public function delete (string $ limiterStateId ): void
Original file line number Diff line number Diff line change @@ -55,6 +55,18 @@ public function testFetchExistingState()
5555 $ this ->assertEquals ($ window , $ this ->storage ->fetch ('test ' ));
5656 }
5757
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+
5870 public function testFetchNonExistingState ()
5971 {
6072 $ cacheItem = $ this ->createMock (CacheItemInterface::class);
You can’t perform that action at this time.
0 commit comments