urlResolver = $this->prophesize(ShortUrlResolverInterface::class); $command = new ResolveUrlCommand($this->urlResolver->reveal()); $app = new Application(); $app->add($command); $this->commandTester = new CommandTester($command); } /** @test */ public function correctShortCodeResolvesUrl(): void { $shortCode = 'abc123'; $expectedUrl = 'http://domain.com/foo/bar'; $shortUrl = new ShortUrl($expectedUrl); $this->urlResolver->resolveShortUrl(new ShortUrlIdentifier($shortCode))->willReturn($shortUrl) ->shouldBeCalledOnce(); $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); $this->assertEquals('Long URL: ' . $expectedUrl . PHP_EOL, $output); } /** @test */ public function incorrectShortCodeOutputsErrorMessage(): void { $identifier = new ShortUrlIdentifier('abc123'); $shortCode = $identifier->shortCode(); $this->urlResolver->resolveShortUrl($identifier) ->willThrow(ShortUrlNotFoundException::fromNotFound($identifier)) ->shouldBeCalledOnce(); $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString(sprintf('No URL found with short code "%s"', $shortCode), $output); } }