mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-29 13:03:52 +03:00
Migrated ResolveShortUrlActionTest to use PHPUnit mocks
This commit is contained in:
parent
01829c82ee
commit
acc9cb94b5
1 changed files with 6 additions and 10 deletions
|
@ -5,9 +5,8 @@ declare(strict_types=1);
|
||||||
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
||||||
|
|
||||||
use Laminas\Diactoros\ServerRequest;
|
use Laminas\Diactoros\ServerRequest;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
|
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
||||||
|
@ -18,15 +17,13 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||||
|
|
||||||
class ResolveShortUrlActionTest extends TestCase
|
class ResolveShortUrlActionTest extends TestCase
|
||||||
{
|
{
|
||||||
use ProphecyTrait;
|
|
||||||
|
|
||||||
private ResolveShortUrlAction $action;
|
private ResolveShortUrlAction $action;
|
||||||
private ObjectProphecy $urlResolver;
|
private MockObject $urlResolver;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->urlResolver = $this->prophesize(ShortUrlResolverInterface::class);
|
$this->urlResolver = $this->createMock(ShortUrlResolverInterface::class);
|
||||||
$this->action = new ResolveShortUrlAction($this->urlResolver->reveal(), new ShortUrlDataTransformer(
|
$this->action = new ResolveShortUrlAction($this->urlResolver, new ShortUrlDataTransformer(
|
||||||
new ShortUrlStringifier([]),
|
new ShortUrlStringifier([]),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -36,11 +33,10 @@ class ResolveShortUrlActionTest extends TestCase
|
||||||
{
|
{
|
||||||
$shortCode = 'abc123';
|
$shortCode = 'abc123';
|
||||||
$apiKey = ApiKey::create();
|
$apiKey = ApiKey::create();
|
||||||
$this->urlResolver->resolveShortUrl(
|
$this->urlResolver->expects($this->once())->method('resolveShortUrl')->with(
|
||||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||||
$apiKey,
|
$apiKey,
|
||||||
)->willReturn(ShortUrl::withLongUrl('http://domain.com/foo/bar'))
|
)->willReturn(ShortUrl::withLongUrl('http://domain.com/foo/bar'));
|
||||||
->shouldBeCalledOnce();
|
|
||||||
|
|
||||||
$request = (new ServerRequest())->withAttribute('shortCode', $shortCode)->withAttribute(ApiKey::class, $apiKey);
|
$request = (new ServerRequest())->withAttribute('shortCode', $shortCode)->withAttribute(ApiKey::class, $apiKey);
|
||||||
$response = $this->action->handle($request);
|
$response = $this->action->handle($request);
|
||||||
|
|
Loading…
Add table
Reference in a new issue