From d8be3c28cbdbb99f43f711d4ae7c8636a38a8d28 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Oct 2022 13:21:54 +0200 Subject: [PATCH] Migrated ListDomainsCommandTest to use PHPUnit mocks --- .../test/Command/Domain/ListDomainsCommandTest.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php index efaa25ed..ef8b276c 100644 --- a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php +++ b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\Domain; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand; use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\Core\Config\NotFoundRedirects; @@ -21,12 +21,12 @@ class ListDomainsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private ObjectProphecy $domainService; + private MockObject $domainService; protected function setUp(): void { - $this->domainService = $this->prophesize(DomainServiceInterface::class); - $this->commandTester = $this->testerForCommand(new ListDomainsCommand($this->domainService->reveal())); + $this->domainService = $this->createMock(DomainServiceInterface::class); + $this->commandTester = $this->testerForCommand(new ListDomainsCommand($this->domainService)); } /** @@ -42,7 +42,7 @@ class ListDomainsCommandTest extends TestCase 'https://foo.com/baz-domain/invalid', )); - $listDomains = $this->domainService->listDomains()->willReturn([ + $this->domainService->expects($this->once())->method('listDomains')->with()->willReturn([ DomainItem::forDefaultDomain('foo.com', new NotFoundRedirectOptions( invalidShortUrl: 'https://foo.com/default/invalid', baseUrl: 'https://foo.com/default/base', @@ -55,7 +55,6 @@ class ListDomainsCommandTest extends TestCase self::assertEquals($expectedOutput, $this->commandTester->getDisplay()); self::assertEquals(ExitCodes::EXIT_SUCCESS, $this->commandTester->getStatusCode()); - $listDomains->shouldHaveBeenCalledOnce(); } public function provideInputsAndOutputs(): iterable