apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $this->commandTester = $this->testerForCommand(new ListKeysCommand($this->apiKeyService->reveal())); } /** * @test * @dataProvider provideKeysAndOutputs */ public function returnsExpectedOutput(array $keys, bool $enabledOnly, string $expected): void { $listKeys = $this->apiKeyService->listKeys($enabledOnly)->willReturn($keys); $this->commandTester->execute(['--enabled-only' => $enabledOnly]); $output = $this->commandTester->getDisplay(); self::assertEquals($expected, $output); $listKeys->shouldHaveBeenCalledOnce(); } public 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 = $this->apiKeyWithRoles([RoleDefinition::forAuthoredShortUrls()]), $apiKey3 = $this->apiKeyWithRoles( [RoleDefinition::forDomain(Domain::withAuthority('example.com')->setId('1'))], ), $apiKey4 = ApiKey::create(), $apiKey5 = $this->apiKeyWithRoles([ RoleDefinition::forAuthoredShortUrls(), RoleDefinition::forDomain(Domain::withAuthority('example.com')->setId('1')), ]), $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; } }