From 162e913cc4dbf7bb48ad1197cddd1e2fca4df6d7 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Oct 2022 17:38:04 +0200 Subject: [PATCH] Migrated ShortUrlTitleResolutionHelperTest to use PHPUnit mocks --- .../ShortUrlTitleResolutionHelperTest.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php b/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php index b2cbfd85..61618eda 100644 --- a/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php +++ b/module/Core/test/ShortUrl/Helper/ShortUrlTitleResolutionHelperTest.php @@ -4,24 +4,21 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Core\ShortUrl\Helper; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlTitleResolutionHelper; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\Util\UrlValidatorInterface; class ShortUrlTitleResolutionHelperTest extends TestCase { - use ProphecyTrait; - private ShortUrlTitleResolutionHelper $helper; - private ObjectProphecy $urlValidator; + private MockObject $urlValidator; protected function setUp(): void { - $this->urlValidator = $this->prophesize(UrlValidatorInterface::class); - $this->helper = new ShortUrlTitleResolutionHelper($this->urlValidator->reveal()); + $this->urlValidator = $this->createMock(UrlValidatorInterface::class); + $this->helper = new ShortUrlTitleResolutionHelper($this->urlValidator); } /** @@ -31,14 +28,18 @@ class ShortUrlTitleResolutionHelperTest extends TestCase public function urlIsProperlyShortened(?string $title, int $validateWithTitleCallsNum, int $validateCallsNum): void { $longUrl = 'http://foobar.com/12345/hello?foo=bar'; + $this->urlValidator->expects($this->exactly($validateWithTitleCallsNum))->method('validateUrlWithTitle')->with( + $this->equalTo($longUrl), + $this->isFalse(), + ); + $this->urlValidator->expects($this->exactly($validateCallsNum))->method('validateUrl')->with( + $this->equalTo($longUrl), + $this->isFalse(), + ); + $this->helper->processTitleAndValidateUrl( ShortUrlCreation::fromRawData(['longUrl' => $longUrl, 'title' => $title]), ); - - $this->urlValidator->validateUrlWithTitle($longUrl, false)->shouldHaveBeenCalledTimes( - $validateWithTitleCallsNum, - ); - $this->urlValidator->validateUrl($longUrl, false)->shouldHaveBeenCalledTimes($validateCallsNum); } public function provideTitles(): iterable