diff --git a/composer.json b/composer.json index 1f5db2ec..90fdb87b 100644 --- a/composer.json +++ b/composer.json @@ -125,7 +125,11 @@ "infect": "infection --threads=4 --min-msi=60 --log-verbosity=2 --only-covered", "infect:ci": "infection --threads=4 --min-msi=60 --log-verbosity=2 --only-covered --coverage=build", - "infect:show": "infection --threads=4 --min-msi=60 --log-verbosity=2 --only-covered --show-mutations" + "infect:show": "infection --threads=4 --min-msi=60 --log-verbosity=2 --only-covered --show-mutations", + "infect:test": [ + "@test:unit:ci", + "@infect:ci" + ] }, "scripts-descriptions": { "check": "Alias for \"cs\", \"stan\", \"test\" and \"infect\"", diff --git a/infection.json b/infection.json index a4579d63..44fdf228 100644 --- a/infection.json +++ b/infection.json @@ -4,7 +4,7 @@ "module/*/src" ] }, - "timeout": 10, + "timeout": 5, "logs": { "text": "build/infection/infection-log.txt", "summary": "build/infection/summary-log.txt", diff --git a/module/CLI/src/Command/Api/ListKeysCommand.php b/module/CLI/src/Command/Api/ListKeysCommand.php index ef1c5c29..aabad7ec 100644 --- a/module/CLI/src/Command/Api/ListKeysCommand.php +++ b/module/CLI/src/Command/Api/ListKeysCommand.php @@ -57,12 +57,11 @@ class ListKeysCommand extends Command $enabledOnly = $input->getOption('enabledOnly'); $rows = array_map(function (ApiKey $apiKey) use ($enabledOnly) { - $key = (string) $apiKey; $expiration = $apiKey->getExpirationDate(); $messagePattern = $this->determineMessagePattern($apiKey); // Set columns for this row - $rowData = [sprintf($messagePattern, $key)]; + $rowData = [sprintf($messagePattern, $apiKey)]; if (! $enabledOnly) { $rowData[] = sprintf($messagePattern, $this->getEnabledSymbol($apiKey)); } diff --git a/module/CLI/test/Command/Api/DisableKeyCommandTest.php b/module/CLI/test/Command/Api/DisableKeyCommandTest.php index c910ea85..dacfcf91 100644 --- a/module/CLI/test/Command/Api/DisableKeyCommandTest.php +++ b/module/CLI/test/Command/Api/DisableKeyCommandTest.php @@ -39,10 +39,14 @@ class DisableKeyCommandTest extends TestCase { $apiKey = 'abcd1234'; $this->apiKeyService->disable($apiKey)->shouldBeCalledOnce(); + $this->commandTester->execute([ 'command' => 'api-key:disable', 'apiKey' => $apiKey, ]); + $output = $this->commandTester->getDisplay(); + + $this->assertContains('API key "abcd1234" properly disabled', $output); } /** @@ -51,14 +55,15 @@ class DisableKeyCommandTest extends TestCase public function errorIsReturnedIfServiceThrowsException() { $apiKey = 'abcd1234'; - $this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class) - ->shouldBeCalledOnce(); + $disable = $this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class); $this->commandTester->execute([ 'command' => 'api-key:disable', 'apiKey' => $apiKey, ]); $output = $this->commandTester->getDisplay(); + $this->assertContains('API key "abcd1234" does not exist.', $output); + $disable->shouldHaveBeenCalledOnce(); } } diff --git a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php index 78fcf4d5..104b6e70 100644 --- a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php +++ b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php @@ -39,11 +39,15 @@ class GenerateKeyCommandTest extends TestCase */ public function noExpirationDateIsDefinedIfNotProvided() { - $this->apiKeyService->create(null)->shouldBeCalledOnce() - ->willReturn(new ApiKey()); + $create = $this->apiKeyService->create(null)->willReturn(new ApiKey()); + $this->commandTester->execute([ 'command' => 'api-key:generate', ]); + $output = $this->commandTester->getDisplay(); + + $this->assertContains('Generated API key: ', $output); + $create->shouldHaveBeenCalledOnce(); } /** diff --git a/module/CLI/test/Command/Api/ListKeysCommandTest.php b/module/CLI/test/Command/Api/ListKeysCommandTest.php index 72485ebe..da5908ef 100644 --- a/module/CLI/test/Command/Api/ListKeysCommandTest.php +++ b/module/CLI/test/Command/Api/ListKeysCommandTest.php @@ -35,30 +35,46 @@ class ListKeysCommandTest extends TestCase /** * @test */ - public function ifEnabledOnlyIsNotProvidedEverythingIsListed() + public function everythingIsListedIfEnabledOnlyIsNotProvided() { $this->apiKeyService->listKeys(false)->willReturn([ new ApiKey(), new ApiKey(), new ApiKey(), ])->shouldBeCalledOnce(); + $this->commandTester->execute([ - 'command' => 'api-key:list', + 'command' => ListKeysCommand::NAME, ]); + $output = $this->commandTester->getDisplay(); + + $this->assertContains('Key', $output); + $this->assertContains('Is enabled', $output); + $this->assertContains(' +++ ', $output); + $this->assertNotContains(' --- ', $output); + $this->assertContains('Expiration date', $output); } /** * @test */ - public function ifEnabledOnlyIsProvidedOnlyThoseKeysAreListed() + public function onlyEnabledKeysAreListedIfEnabledOnlyIsProvided() { $this->apiKeyService->listKeys(true)->willReturn([ - new ApiKey(), + (new ApiKey())->disable(), new ApiKey(), ])->shouldBeCalledOnce(); + $this->commandTester->execute([ - 'command' => 'api-key:list', + 'command' => ListKeysCommand::NAME, '--enabledOnly' => true, ]); + $output = $this->commandTester->getDisplay(); + + $this->assertContains('Key', $output); + $this->assertNotContains('Is enabled', $output); + $this->assertNotContains(' +++ ', $output); + $this->assertNotContains(' --- ', $output); + $this->assertContains('Expiration date', $output); } }