Skip to content

Commit f581295

Browse files
committed
[Tests] IBX-9619: Fixed ActionMenuBuilder tests
1 parent 5971105 commit f581295

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

tests/lib/Menu/Action/BaseActionMenuBuilderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use PHPUnit\Framework\TestCase;
2626
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2727
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
28+
use Symfony\Contracts\Translation\TranslatorInterface;
2829

2930
abstract class BaseActionMenuBuilderTest extends TestCase
3031
{
@@ -52,6 +53,9 @@ abstract class BaseActionMenuBuilderTest extends TestCase
5253
/** @var \Ibexa\Contracts\Core\Repository\ContentService&\PHPUnit\Framework\MockObject\MockObject */
5354
protected ContentService $contentService;
5455

56+
/** @var \Symfony\Contracts\Translation\TranslatorInterface&\PHPUnit\Framework\MockObject\MockObject */
57+
protected TranslatorInterface $translator;
58+
5559
/** @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface&\PHPUnit\Framework\MockObject\MockObject */
5660
protected UrlGeneratorInterface $urlGenerator;
5761

@@ -69,6 +73,7 @@ protected function setUp(): void
6973
);
7074
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
7175
$this->contentService = $this->createMock(ContentService::class);
76+
$this->translator = $this->createMock(TranslatorInterface::class);
7277
$this->urlGenerator = $this->createMock(UrlGeneratorInterface::class);
7378
$this->userService = $this->createMock(UserService::class);
7479
}
@@ -162,6 +167,15 @@ protected function mockUserServiceIsUser(
162167
->willReturn($isUser);
163168
}
164169

170+
protected function mockTranslatorTranslate(): void
171+
{
172+
$this->translator
173+
->method('trans')
174+
->willReturnCallback(function (string $id): string {
175+
return $id;
176+
});
177+
}
178+
165179
/**
166180
* @param array<string, mixed> $parameters
167181
*/

tests/lib/Menu/Action/DraftListActionMenuBuilderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function setUp(): void
3131
$this->menuItemFactory,
3232
$this->eventDispatcher,
3333
$this->contentService,
34-
$this->createMock(TranslatorInterface::class),
34+
$this->translator,
3535
$this->urlGenerator,
3636
$this->userService
3737
);
@@ -53,6 +53,7 @@ public function testThrowsInvalidArgumentException(): void
5353
public function testBuildDraftListActionMenu(): void
5454
{
5555
$this->mockUrlGeneratorGenerate();
56+
$this->mockTranslatorTranslate();
5657

5758
$menu = $this->actionMenuBuilder->build(['versionInfo' => $this->createVersionInfo()]);
5859

@@ -76,6 +77,7 @@ public function testAddUserUpdateItemAction(): void
7677
$this->mockUrlGeneratorGenerate();
7778
$this->mockContentServiceLoadContentByVersionInfo($versionInfo, $user);
7879
$this->mockUserServiceIsUser($user);
80+
$this->mockTranslatorTranslate();
7981

8082
$menu = $this->actionMenuBuilder->build(['versionInfo' => $versionInfo]);
8183

tests/lib/Menu/Action/VersionListActionMenuBuilderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function setUp(): void
3838
$this->menuItemFactory,
3939
$this->eventDispatcher,
4040
$this->contentService,
41-
$this->createMock(TranslatorInterface::class),
41+
$this->translator,
4242
$this->urlGenerator,
4343
$this->userService
4444
);
@@ -72,6 +72,7 @@ public function testBuildVersionListActionMenu(
7272
array $attributes
7373
): void {
7474
$this->mockUrlGeneratorGenerate();
75+
$this->mockTranslatorTranslate();
7576

7677
$menu = $this->versionListActionMenuBuilder->build($options);
7778

@@ -155,6 +156,7 @@ public function testAddUserUpdateItemAction(): void
155156
$this->mockUrlGeneratorGenerate();
156157
$this->mockContentServiceLoadContentByVersionInfo($versionInfo, $user);
157158
$this->mockUserServiceIsUser($user);
159+
$this->mockTranslatorTranslate();
158160

159161
$menu = $this->versionListActionMenuBuilder->build(['versionInfo' => $versionInfo]);
160162

0 commit comments

Comments
 (0)