| @@ 49-61 (lines=13) @@ | ||
| 46 | /** |
|
| 47 | * @test |
|
| 48 | */ |
|
| 49 | public function errorIsReturnedIfServiceThrowsException() |
|
| 50 | { |
|
| 51 | $apiKey = 'abcd1234'; |
|
| 52 | $this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class) |
|
| 53 | ->shouldBeCalledTimes(1); |
|
| 54 | ||
| 55 | $this->commandTester->execute([ |
|
| 56 | 'command' => 'api-key:disable', |
|
| 57 | 'apiKey' => $apiKey, |
|
| 58 | ]); |
|
| 59 | $output = $this->commandTester->getDisplay(); |
|
| 60 | $this->assertEquals('API key "abcd1234" does not exist.' . PHP_EOL, $output); |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||
| @@ 37-50 (lines=14) @@ | ||
| 34 | /** |
|
| 35 | * @test |
|
| 36 | */ |
|
| 37 | public function correctShortCodeResolvesUrl() |
|
| 38 | { |
|
| 39 | $shortCode = 'abc123'; |
|
| 40 | $expectedUrl = 'http://domain.com/foo/bar'; |
|
| 41 | $this->urlShortener->shortCodeToUrl($shortCode)->willReturn($expectedUrl) |
|
| 42 | ->shouldBeCalledTimes(1); |
|
| 43 | ||
| 44 | $this->commandTester->execute([ |
|
| 45 | 'command' => 'shortcode:parse', |
|
| 46 | 'shortCode' => $shortCode, |
|
| 47 | ]); |
|
| 48 | $output = $this->commandTester->getDisplay(); |
|
| 49 | $this->assertEquals('Long URL: ' . $expectedUrl . PHP_EOL, $output); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @test |
|
| @@ 55-67 (lines=13) @@ | ||
| 52 | /** |
|
| 53 | * @test |
|
| 54 | */ |
|
| 55 | public function incorrectShortCodeOutputsErrorMessage() |
|
| 56 | { |
|
| 57 | $shortCode = 'abc123'; |
|
| 58 | $this->urlShortener->shortCodeToUrl($shortCode)->willReturn(null) |
|
| 59 | ->shouldBeCalledTimes(1); |
|
| 60 | ||
| 61 | $this->commandTester->execute([ |
|
| 62 | 'command' => 'shortcode:parse', |
|
| 63 | 'shortCode' => $shortCode, |
|
| 64 | ]); |
|
| 65 | $output = $this->commandTester->getDisplay(); |
|
| 66 | $this->assertEquals('No URL found for short code "' . $shortCode . '"' . PHP_EOL, $output); |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * @test |
|
| @@ 72-84 (lines=13) @@ | ||
| 69 | /** |
|
| 70 | * @test |
|
| 71 | */ |
|
| 72 | public function wrongShortCodeFormatOutputsErrorMessage() |
|
| 73 | { |
|
| 74 | $shortCode = 'abc123'; |
|
| 75 | $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(new InvalidShortCodeException()) |
|
| 76 | ->shouldBeCalledTimes(1); |
|
| 77 | ||
| 78 | $this->commandTester->execute([ |
|
| 79 | 'command' => 'shortcode:parse', |
|
| 80 | 'shortCode' => $shortCode, |
|
| 81 | ]); |
|
| 82 | $output = $this->commandTester->getDisplay(); |
|
| 83 | $this->assertEquals('Provided short code "' . $shortCode . '" has an invalid format.' . PHP_EOL, $output); |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||