apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $command = new ListKeysCommand($this->apiKeyService->reveal()); $app = new Application(); $app->add($command); $this->commandTester = new CommandTester($command); } /** * @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' => [ [ApiKey::withKey('foo'), ApiKey::withKey('bar'), ApiKey::withKey('baz')], false, << [ [ApiKey::withKey('foo')->disable(), ApiKey::withKey('bar')], true, << [ [ ApiKey::withKey('foo'), $this->apiKeyWithRoles('bar', [RoleDefinition::forAuthoredShortUrls()]), $this->apiKeyWithRoles('baz', [RoleDefinition::forDomain((new Domain('example.com'))->setId('1'))]), ApiKey::withKey('foo2'), $this->apiKeyWithRoles('baz2', [ RoleDefinition::forAuthoredShortUrls(), RoleDefinition::forDomain((new Domain('example.com'))->setId('1')), ]), ApiKey::withKey('foo3'), ], true, << [ [ ApiKey::withKey('abc', null, 'Alice'), ApiKey::withKey('def', null, 'Alice and Bob'), ApiKey::withKey('ghi', null, ''), ApiKey::withKey('jkl', null, null), ], true, <<registerRole($role); } return $apiKey; } }