Skip to content

Commit be36b4e

Browse files
committed
Refactored Localization service integration tests
1 parent be12b56 commit be36b4e

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

tests/Integration/Service/LocalizationTest.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use App\Service\Localization;
1212
use Exception;
1313
use PHPUnit\Framework\Attributes\TestDox;
14-
use PHPUnit\Framework\MockObject\MockObject;
1514
use Psr\Log\LoggerInterface;
1615
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
16+
use Symfony\Component\HttpFoundation\RequestStack;
1717
use Symfony\Contracts\Cache\CacheInterface;
1818

1919
/**
@@ -22,13 +22,14 @@
2222
*/
2323
class 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

Comments
 (0)