123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- declare(strict_types=1);
- namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
- use Laminas\Diactoros\ServerRequest;
- use PHPUnit\Framework\TestCase;
- use Prophecy\Argument;
- use Prophecy\PhpUnit\ProphecyTrait;
- use Prophecy\Prophecy\ObjectProphecy;
- use Shlinkio\Shlink\Core\Entity\ShortUrl;
- use Shlinkio\Shlink\Core\Exception\ValidationException;
- use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
- use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlAction;
- use Shlinkio\Shlink\Rest\Entity\ApiKey;
- class EditShortUrlActionTest extends TestCase
- {
- use ProphecyTrait;
- private EditShortUrlAction $action;
- private ObjectProphecy $shortUrlService;
- public function setUp(): void
- {
- $this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class);
- $this->action = new EditShortUrlAction($this->shortUrlService->reveal());
- }
- /** @test */
- public function invalidDataThrowsError(): void
- {
- $request = (new ServerRequest())->withParsedBody([
- 'maxVisits' => 'invalid',
- ]);
- $this->expectException(ValidationException::class);
- $this->action->handle($request);
- }
- /** @test */
- public function correctShortCodeReturnsSuccess(): void
- {
- $request = (new ServerRequest())->withAttribute('shortCode', 'abc123')
- ->withAttribute(ApiKey::class, new ApiKey())
- ->withParsedBody([
- 'maxVisits' => 5,
- ]);
- $updateMeta = $this->shortUrlService->updateMetadataByShortCode(Argument::cetera())->willReturn(
- new ShortUrl(''),
- );
- $resp = $this->action->handle($request);
- self::assertEquals(204, $resp->getStatusCode());
- $updateMeta->shouldHaveBeenCalled();
- }
- }
|