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