mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-25 18:30:23 -06:00
Migrated EditShortUrlActionTest to use PHPUnit mocks
This commit is contained in:
parent
d202538581
commit
9c02ea8799
@ -5,10 +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\Argument;
|
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
||||||
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;
|
||||||
@ -19,15 +17,13 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
|||||||
|
|
||||||
class EditShortUrlActionTest extends TestCase
|
class EditShortUrlActionTest extends TestCase
|
||||||
{
|
{
|
||||||
use ProphecyTrait;
|
|
||||||
|
|
||||||
private EditShortUrlAction $action;
|
private EditShortUrlAction $action;
|
||||||
private ObjectProphecy $shortUrlService;
|
private MockObject $shortUrlService;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class);
|
$this->shortUrlService = $this->createMock(ShortUrlServiceInterface::class);
|
||||||
$this->action = new EditShortUrlAction($this->shortUrlService->reveal(), new ShortUrlDataTransformer(
|
$this->action = new EditShortUrlAction($this->shortUrlService, new ShortUrlDataTransformer(
|
||||||
new ShortUrlStringifier([]),
|
new ShortUrlStringifier([]),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -38,6 +34,7 @@ class EditShortUrlActionTest extends TestCase
|
|||||||
$request = (new ServerRequest())->withParsedBody([
|
$request = (new ServerRequest())->withParsedBody([
|
||||||
'maxVisits' => 'invalid',
|
'maxVisits' => 'invalid',
|
||||||
]);
|
]);
|
||||||
|
$this->shortUrlService->expects($this->never())->method('updateShortUrl');
|
||||||
|
|
||||||
$this->expectException(ValidationException::class);
|
$this->expectException(ValidationException::class);
|
||||||
|
|
||||||
@ -52,13 +49,10 @@ class EditShortUrlActionTest extends TestCase
|
|||||||
->withParsedBody([
|
->withParsedBody([
|
||||||
'maxVisits' => 5,
|
'maxVisits' => 5,
|
||||||
]);
|
]);
|
||||||
$updateMeta = $this->shortUrlService->updateShortUrl(Argument::cetera())->willReturn(
|
$this->shortUrlService->expects($this->once())->method('updateShortUrl')->willReturn(ShortUrl::createEmpty());
|
||||||
ShortUrl::createEmpty(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$resp = $this->action->handle($request);
|
$resp = $this->action->handle($request);
|
||||||
|
|
||||||
self::assertEquals(200, $resp->getStatusCode());
|
self::assertEquals(200, $resp->getStatusCode());
|
||||||
$updateMeta->shouldHaveBeenCalled();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user