urlShortener = $this->prophesize(UrlShortener::class); $command = new ResolveUrlCommand($this->urlShortener->reveal(), Translator::factory([])); $app = new Application(); $app->add($command); $this->commandTester = new CommandTester($command); } /** * @test */ public function correctShortCodeResolvesUrl() { $shortCode = 'abc123'; $expectedUrl = 'http://domain.com/foo/bar'; $this->urlShortener->shortCodeToUrl($shortCode)->willReturn($expectedUrl) ->shouldBeCalledTimes(1); $this->commandTester->execute([ 'command' => 'shortcode:parse', 'shortCode' => $shortCode, ]); $output = $this->commandTester->getDisplay(); $this->assertEquals('Long URL: ' . $expectedUrl . PHP_EOL, $output); } /** * @test */ public function incorrectShortCodeOutputsErrorMessage() { $shortCode = 'abc123'; $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class) ->shouldBeCalledTimes(1); $this->commandTester->execute([ 'command' => 'shortcode:parse', 'shortCode' => $shortCode, ]); $output = $this->commandTester->getDisplay(); $this->assertEquals('Provided short code "' . $shortCode . '" could not be found.' . PHP_EOL, $output); } /** * @test */ public function wrongShortCodeFormatOutputsErrorMessage() { $shortCode = 'abc123'; $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(new InvalidShortCodeException()) ->shouldBeCalledTimes(1); $this->commandTester->execute([ 'command' => 'shortcode:parse', 'shortCode' => $shortCode, ]); $output = $this->commandTester->getDisplay(); $this->assertEquals('Provided short code "' . $shortCode . '" has an invalid format.' . PHP_EOL, $output); } }