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