shlink/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php

44 lines
1.3 KiB
PHP
Raw Normal View History

2018-09-15 12:56:17 +02:00
<?php
2019-10-05 17:26:10 +02:00
2018-09-15 12:56:17 +02:00
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
2018-09-15 12:56:17 +02:00
use Laminas\Diactoros\ServerRequestFactory;
2018-09-15 12:56:17 +02:00
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
2020-11-02 11:50:19 +01:00
use Prophecy\PhpUnit\ProphecyTrait;
2018-09-15 12:56:17 +02:00
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface;
use Shlinkio\Shlink\Rest\Action\ShortUrl\DeleteShortUrlAction;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
2018-09-15 12:56:17 +02:00
class DeleteShortUrlActionTest extends TestCase
2018-09-15 12:56:17 +02:00
{
2020-11-02 11:50:19 +01:00
use ProphecyTrait;
private DeleteShortUrlAction $action;
private ObjectProphecy $service;
2018-09-15 12:56:17 +02:00
2019-02-16 10:53:45 +01:00
public function setUp(): void
2018-09-15 12:56:17 +02:00
{
$this->service = $this->prophesize(DeleteShortUrlServiceInterface::class);
2018-11-18 16:28:04 +01:00
$this->action = new DeleteShortUrlAction($this->service->reveal());
2018-09-15 12:56:17 +02:00
}
2019-02-17 20:28:34 +01:00
/** @test */
public function emptyResponseIsReturnedIfProperlyDeleted(): void
2018-09-15 12:56:17 +02:00
{
$apiKey = new ApiKey();
$deleteByShortCode = $this->service->deleteByShortCode(Argument::any(), false, $apiKey)->will(
function (): void {
},
);
2018-09-15 12:56:17 +02:00
$resp = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey));
2018-09-15 12:56:17 +02:00
2020-10-04 00:35:14 +02:00
self::assertEquals(204, $resp->getStatusCode());
2018-11-11 13:18:21 +01:00
$deleteByShortCode->shouldHaveBeenCalledOnce();
2018-09-15 12:56:17 +02:00
}
}