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 { yield 'all keys' => [ [$apiKey1 = ApiKey::create(), $apiKey2 = ApiKey::create(), $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((new Domain('example.com'))->setId('1'))]), $apiKey4 = ApiKey::create(), $apiKey5 = $this->apiKeyWithRoles([ RoleDefinition::forAuthoredShortUrls(), RoleDefinition::forDomain((new Domain('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; } }