Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Tests] Fixed SiteAccessLimitationMapperTest generate mock #2087

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessServiceInterface;
use EzSystems\EzPlatformAdminUi\Limitation\Mapper\SiteAccessLimitationMapper;
use EzSystems\EzPlatformAdminUi\Siteaccess\SiteAccessKeyGenerator;
use EzSystems\EzPlatformAdminUi\Siteaccess\SiteAccessKeyGeneratorInterface;
use PHPUnit\Framework\TestCase;

class SiteAccessLimitationMapperTest extends TestCase
{
public function testMapLimitationValue()
public function testMapLimitationValue(): void
{
$siteAccessList = [
'2356372769' => 'foo',
Expand All @@ -40,14 +39,18 @@ static function (string $siteAccessName): SiteAccess {
$siteAccessesGeneratorInterface = $this->createMock(SiteAccessKeyGeneratorInterface::class);
$siteAccessesGeneratorInterface
->method('generate')
->willReturn(new SiteAccessKeyGenerator());
// re-map SiteAccess crc32 identifiers back to string, as the keys get stored as integers
->willReturnOnConsecutiveCalls(...array_map('strval', array_keys($siteAccessList)));

$siteAccessService = $this->createMock(SiteAccessServiceInterface::class);
$siteAccessService->method('getAll')->willReturn($siteAccesses);

$mapper = new SiteAccessLimitationMapper($siteAccessService, $siteAccessesGeneratorInterface);
$mapper = new SiteAccessLimitationMapper(
$siteAccessService,
$siteAccessesGeneratorInterface
);
$result = $mapper->mapLimitationValue($limitation);

$this->assertEquals(array_values($siteAccessList), $result);
self::assertEquals(array_values($siteAccessList), $result);
}
}