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