apiKeyService = $this->createMock(ApiKeyServiceInterface::class); $this->commandTester = $this->testerForCommand(new ListKeysCommand($this->apiKeyService)); } /** * @test * @dataProvider provideKeysAndOutputs */ public function returnsExpectedOutput(array $keys, bool $enabledOnly, string $expected): void { $this->apiKeyService->expects($this->once())->method('listKeys')->with($enabledOnly)->willReturn($keys); $this->commandTester->execute(['--enabled-only' => $enabledOnly]); $output = $this->commandTester->getDisplay(); self::assertEquals($expected, $output); } public static function provideKeysAndOutputs(): iterable { $dateInThePast = Chronos::createFromFormat('Y-m-d H:i:s', '2020-01-01 00:00:00'); yield 'all keys' => [ [ $apiKey1 = ApiKey::create()->disable(), $apiKey2 = ApiKey::fromMeta(ApiKeyMeta::withExpirationDate($dateInThePast)), $apiKey3 = ApiKey::create(), ], false, << [ [$apiKey1 = ApiKey::create()->disable(), $apiKey2 = ApiKey::create()], true, << [ [ $apiKey1 = ApiKey::create(), $apiKey2 = self::apiKeyWithRoles([RoleDefinition::forAuthoredShortUrls()]), $apiKey3 = self::apiKeyWithRoles( [RoleDefinition::forDomain(self::domainWithId(Domain::withAuthority('example.com')))], ), $apiKey4 = ApiKey::create(), $apiKey5 = self::apiKeyWithRoles([ RoleDefinition::forAuthoredShortUrls(), RoleDefinition::forDomain(self::domainWithId(Domain::withAuthority('example.com'))), ]), $apiKey6 = ApiKey::create(), ], true, << [ [ $apiKey1 = ApiKey::fromMeta(ApiKeyMeta::withName('Alice')), $apiKey2 = ApiKey::fromMeta(ApiKeyMeta::withName('Alice and Bob')), $apiKey3 = ApiKey::fromMeta(ApiKeyMeta::withName('')), $apiKey4 = ApiKey::create(), ], true, <<registerRole($role); } return $apiKey; } private static function domainWithId(Domain $domain): Domain { $domain->setId('1'); return $domain; } }