shortUrlService = $this->createMock(ShortUrlServiceInterface::class); $this->stringifier = $this->createMock(ShortUrlStringifierInterface::class); $command = new EditShortUrlCommand($this->shortUrlService, $this->stringifier); $this->commandTester = CliTestUtils::testerForCommand($command); } #[Test] public function successMessageIsPrintedIfNoErrorOccurs(): void { $this->shortUrlService->expects($this->once())->method('updateShortUrl')->willReturn( ShortUrl::createFake(), ); $this->stringifier->expects($this->once())->method('stringify')->willReturn('https://s.test/foo'); $this->commandTester->execute(['short-code' => 'foobar']); $output = $this->commandTester->getDisplay(); $exitCode = $this->commandTester->getStatusCode(); self::assertStringContainsString('Short URL "https://s.test/foo" properly edited', $output); self::assertEquals(Command::SUCCESS, $exitCode); } #[Test] #[TestWith([OutputInterface::VERBOSITY_NORMAL])] #[TestWith([OutputInterface::VERBOSITY_VERBOSE])] #[TestWith([OutputInterface::VERBOSITY_VERY_VERBOSE])] #[TestWith([OutputInterface::VERBOSITY_DEBUG])] public function errorIsPrintedInCaseOfFailure(int $verbosity): void { $e = ShortUrlNotFoundException::fromNotFound(ShortUrlIdentifier::fromShortCodeAndDomain('foo')); $this->shortUrlService->expects($this->once())->method('updateShortUrl')->willThrowException($e); $this->stringifier->expects($this->never())->method('stringify'); $this->commandTester->execute(['short-code' => 'foo'], ['verbosity' => $verbosity]); $output = $this->commandTester->getDisplay(); $exitCode = $this->commandTester->getStatusCode(); self::assertStringContainsString('Short URL not found for "foo"', $output); if ($verbosity >= OutputInterface::VERBOSITY_VERBOSE) { self::assertStringContainsString('Exception trace:', $output); } else { self::assertStringNotContainsString('Exception trace:', $output); } self::assertEquals(Command::FAILURE, $exitCode); } }