mirror of
https://github.com/shlinkio/shlink.git
synced 2025-01-11 00:22:04 -06:00
Migrated DeleteTagsActionTest to use PHPUnit mocks
This commit is contained in:
parent
9ac6a50e66
commit
ab9ea887d2
@ -5,25 +5,21 @@ declare(strict_types=1);
|
|||||||
namespace ShlinkioTest\Shlink\Rest\Action\Tag;
|
namespace ShlinkioTest\Shlink\Rest\Action\Tag;
|
||||||
|
|
||||||
use Laminas\Diactoros\ServerRequest;
|
use Laminas\Diactoros\ServerRequest;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Argument;
|
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
|
use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
|
||||||
use Shlinkio\Shlink\Rest\Action\Tag\DeleteTagsAction;
|
use Shlinkio\Shlink\Rest\Action\Tag\DeleteTagsAction;
|
||||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||||
|
|
||||||
class DeleteTagsActionTest extends TestCase
|
class DeleteTagsActionTest extends TestCase
|
||||||
{
|
{
|
||||||
use ProphecyTrait;
|
|
||||||
|
|
||||||
private DeleteTagsAction $action;
|
private DeleteTagsAction $action;
|
||||||
private ObjectProphecy $tagService;
|
private MockObject $tagService;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->tagService = $this->prophesize(TagServiceInterface::class);
|
$this->tagService = $this->createMock(TagServiceInterface::class);
|
||||||
$this->action = new DeleteTagsAction($this->tagService->reveal());
|
$this->action = new DeleteTagsAction($this->tagService);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,12 +31,14 @@ class DeleteTagsActionTest extends TestCase
|
|||||||
$request = (new ServerRequest())
|
$request = (new ServerRequest())
|
||||||
->withQueryParams(['tags' => $tags])
|
->withQueryParams(['tags' => $tags])
|
||||||
->withAttribute(ApiKey::class, ApiKey::create());
|
->withAttribute(ApiKey::class, ApiKey::create());
|
||||||
$deleteTags = $this->tagService->deleteTags($tags ?: [], Argument::type(ApiKey::class));
|
$this->tagService->expects($this->once())->method('deleteTags')->with(
|
||||||
|
$tags ?? [],
|
||||||
|
$this->isInstanceOf(ApiKey::class),
|
||||||
|
);
|
||||||
|
|
||||||
$response = $this->action->handle($request);
|
$response = $this->action->handle($request);
|
||||||
|
|
||||||
self::assertEquals(204, $response->getStatusCode());
|
self::assertEquals(204, $response->getStatusCode());
|
||||||
$deleteTags->shouldHaveBeenCalled();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideTags(): iterable
|
public function provideTags(): iterable
|
||||||
|
Loading…
Reference in New Issue
Block a user