2018-01-07 20:45:05 +01:00
|
|
|
<?php
|
2019-10-05 17:26:10 +02:00
|
|
|
|
2018-01-07 20:45:05 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2018-09-20 19:55:24 +02:00
|
|
|
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
2018-01-07 20:45:05 +01:00
|
|
|
|
2026-05-04 10:50:44 +02:00
|
|
|
use CuyZ\Valinor\MapperBuilder;
|
|
|
|
|
use Laminas\Diactoros\ServerRequestFactory;
|
2023-02-09 20:42:18 +01:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2022-10-23 22:12:27 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-01-07 20:45:05 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2022-09-23 19:03:32 +02:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
2021-02-01 22:55:52 +01:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
|
2022-09-23 18:42:38 +02:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\ShortUrlServiceInterface;
|
2021-02-01 22:55:52 +01:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Transformer\ShortUrlDataTransformer;
|
2018-09-20 19:55:24 +02:00
|
|
|
use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlAction;
|
2021-01-03 16:41:44 +01:00
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
2018-01-07 20:45:05 +01:00
|
|
|
|
2018-09-20 19:55:24 +02:00
|
|
|
class EditShortUrlActionTest extends TestCase
|
2018-01-07 20:45:05 +01:00
|
|
|
{
|
2019-12-29 22:48:40 +01:00
|
|
|
private EditShortUrlAction $action;
|
2026-05-22 08:42:47 +02:00
|
|
|
private MockObject&ShortUrlServiceInterface $shortUrlService;
|
2018-01-07 20:45:05 +01:00
|
|
|
|
2022-09-11 12:02:49 +02:00
|
|
|
protected function setUp(): void
|
2018-01-07 20:45:05 +01:00
|
|
|
{
|
2022-10-23 22:12:27 +02:00
|
|
|
$this->shortUrlService = $this->createMock(ShortUrlServiceInterface::class);
|
2026-05-04 10:50:44 +02:00
|
|
|
$this->action = new EditShortUrlAction(
|
|
|
|
|
$this->shortUrlService,
|
|
|
|
|
new ShortUrlDataTransformer(new ShortUrlStringifier()),
|
|
|
|
|
new MapperBuilder()->mapper(),
|
|
|
|
|
);
|
2018-01-07 20:45:05 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test]
|
2019-11-24 12:41:12 +01:00
|
|
|
public function correctShortCodeReturnsSuccess(): void
|
2018-01-07 20:45:05 +01:00
|
|
|
{
|
2026-05-22 08:42:47 +02:00
|
|
|
$request = ServerRequestFactory::fromGlobals()
|
|
|
|
|
->withAttribute('shortCode', 'abc123')
|
|
|
|
|
->withAttribute(ApiKey::class, ApiKey::create())
|
|
|
|
|
->withParsedBody(['maxVisits' => 5]);
|
2023-01-22 11:27:16 +01:00
|
|
|
$this->shortUrlService->expects($this->once())->method('updateShortUrl')->willReturn(ShortUrl::createFake());
|
2018-01-07 20:45:05 +01:00
|
|
|
|
2018-03-26 19:02:41 +02:00
|
|
|
$resp = $this->action->handle($request);
|
2018-01-07 20:45:05 +01:00
|
|
|
|
2021-01-31 13:21:23 +01:00
|
|
|
self::assertEquals(200, $resp->getStatusCode());
|
2018-01-07 20:45:05 +01:00
|
|
|
}
|
|
|
|
|
}
|