1111use App \Service \Localization ;
1212use Exception ;
1313use PHPUnit \Framework \Attributes \TestDox ;
14- use PHPUnit \Framework \MockObject \MockObject ;
1514use Psr \Log \LoggerInterface ;
1615use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
16+ use Symfony \Component \HttpFoundation \RequestStack ;
1717use Symfony \Contracts \Cache \CacheInterface ;
1818
1919/**
2222 */
2323class LocalizationTest extends KernelTestCase
2424{
25- #[TestDox('Test that `LoggerInterface::error` method is called when `CacheInterface ' )]
25+ #[TestDox('Test that `LoggerInterface::error` method is called when `CacheInterface` throws an exception ' )]
2626 public function testThatLoggerIsCalledWhenCacheThrowsAnException (): void
2727 {
2828 $ exception = new Exception ('test exception ' );
2929
30- $ cache = $ this ->getCache ();
31- $ logger = $ this ->getLogger ();
30+ $ cache = $ this ->getMockBuilder (CacheInterface::class)->getMock ();
31+ $ logger = $ this ->getMockBuilder (LoggerInterface::class)->getMock ();
32+ $ requestStack = new RequestStack ();
3233
3334 $ cache
3435 ->expects ($ this ->once ())
@@ -40,23 +41,7 @@ public function testThatLoggerIsCalledWhenCacheThrowsAnException(): void
4041 ->method ('error ' )
4142 ->with ($ exception ->getMessage (), $ exception ->getTrace ());
4243
43- (new Localization ($ cache , $ logger ))
44+ (new Localization ($ cache , $ logger, $ requestStack ))
4445 ->getTimezones ();
4546 }
46-
47- /**
48- * @phpstan-return MockObject&CacheInterface
49- */
50- private function getCache (): MockObject
51- {
52- return $ this ->getMockBuilder (CacheInterface::class)->getMock ();
53- }
54-
55- /**
56- * @phpstan-return MockObject&LoggerInterface
57- */
58- private function getLogger (): MockObject
59- {
60- return $ this ->getMockBuilder (LoggerInterface::class)->getMock ();
61- }
6247}
0 commit comments