2018-01-07 22:45:05 +03:00
|
|
|
<?php
|
2019-10-05 18:26:10 +03:00
|
|
|
|
2018-01-07 22:45:05 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-09-20 20:55:24 +03:00
|
|
|
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
2018-01-07 22:45:05 +03:00
|
|
|
|
2020-01-01 23:11:53 +03:00
|
|
|
use Laminas\Diactoros\ServerRequest;
|
2018-01-07 22:45:05 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Prophecy\Argument;
|
2020-11-02 13:50:19 +03:00
|
|
|
use Prophecy\PhpUnit\ProphecyTrait;
|
2018-01-07 22:45:05 +03:00
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
|
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
2019-11-25 01:45:40 +03:00
|
|
|
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
2018-01-07 22:45:05 +03:00
|
|
|
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
|
2018-09-20 20:55:24 +03:00
|
|
|
use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlAction;
|
2018-01-07 22:45:05 +03:00
|
|
|
|
2018-09-20 20:55:24 +03:00
|
|
|
class EditShortUrlActionTest extends TestCase
|
2018-01-07 22:45:05 +03:00
|
|
|
{
|
2020-11-02 13:50:19 +03:00
|
|
|
use ProphecyTrait;
|
|
|
|
|
2019-12-30 00:48:40 +03:00
|
|
|
private EditShortUrlAction $action;
|
|
|
|
private ObjectProphecy $shortUrlService;
|
2018-01-07 22:45:05 +03:00
|
|
|
|
2019-02-16 12:53:45 +03:00
|
|
|
public function setUp(): void
|
2018-01-07 22:45:05 +03:00
|
|
|
{
|
|
|
|
$this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class);
|
2018-11-18 18:28:04 +03:00
|
|
|
$this->action = new EditShortUrlAction($this->shortUrlService->reveal());
|
2018-01-07 22:45:05 +03:00
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2019-11-25 01:45:40 +03:00
|
|
|
public function invalidDataThrowsError(): void
|
2018-01-07 22:45:05 +03:00
|
|
|
{
|
2018-12-26 01:01:30 +03:00
|
|
|
$request = (new ServerRequest())->withParsedBody([
|
2018-01-07 22:45:05 +03:00
|
|
|
'maxVisits' => 'invalid',
|
|
|
|
]);
|
|
|
|
|
2019-11-25 01:45:40 +03:00
|
|
|
$this->expectException(ValidationException::class);
|
2018-01-07 22:45:05 +03:00
|
|
|
|
2019-11-25 01:45:40 +03:00
|
|
|
$this->action->handle($request);
|
2018-01-07 22:45:05 +03:00
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2019-11-24 14:41:12 +03:00
|
|
|
public function correctShortCodeReturnsSuccess(): void
|
2018-01-07 22:45:05 +03:00
|
|
|
{
|
2018-12-26 01:01:30 +03:00
|
|
|
$request = (new ServerRequest())->withAttribute('shortCode', 'abc123')
|
|
|
|
->withParsedBody([
|
|
|
|
'maxVisits' => 5,
|
|
|
|
]);
|
2018-10-28 18:00:54 +03:00
|
|
|
$updateMeta = $this->shortUrlService->updateMetadataByShortCode(Argument::cetera())->willReturn(
|
2020-01-01 22:48:31 +03:00
|
|
|
new ShortUrl(''),
|
2018-10-28 18:00:54 +03:00
|
|
|
);
|
2018-01-07 22:45:05 +03:00
|
|
|
|
2018-03-26 20:02:41 +03:00
|
|
|
$resp = $this->action->handle($request);
|
2018-01-07 22:45:05 +03:00
|
|
|
|
2020-10-04 01:35:14 +03:00
|
|
|
self::assertEquals(204, $resp->getStatusCode());
|
2018-01-07 22:45:05 +03:00
|
|
|
$updateMeta->shouldHaveBeenCalled();
|
|
|
|
}
|
|
|
|
}
|