mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-23 07:33:58 -06:00
Migrated ShortUrlTitleResolutionHelperTest to use PHPUnit mocks
This commit is contained in:
parent
5aaf50d68e
commit
162e913cc4
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user