Skip to content

Commit

Permalink
[Tests] Fixed SiteAccessLimitationMapperTest generate mock (#2087)
Browse files Browse the repository at this point in the history
* [Tests] Fixed SiteAccessLimitationMapperTest generate mock

* [CS] Fixed constructor call arguments alignment

Co-authored-by: Konrad Oboza <konrad.oboza@ez.no>

---------

Co-authored-by: Konrad Oboza <konrad.oboza@ez.no>
  • Loading branch information
alongosz and Konrad Oboza authored Feb 8, 2023
1 parent d2c9072 commit 635e494
Showing 1 changed file with 8 additions and 5 deletions.
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);
}
}

0 comments on commit 635e494

Please # to comment.