Migrated UpdateTagActionTest to use PHPUnit mocks

This commit is contained in:
Alejandro Celaya 2022-10-23 22:21:23 +02:00
parent 69e994c067
commit 28f26920dd

View File

@ -5,10 +5,8 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Rest\Action\Tag; namespace ShlinkioTest\Shlink\Rest\Action\Tag;
use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\ServerRequestFactory;
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 Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Shlinkio\Shlink\Core\Exception\ValidationException; use Shlinkio\Shlink\Core\Exception\ValidationException;
use Shlinkio\Shlink\Core\Tag\Entity\Tag; use Shlinkio\Shlink\Core\Tag\Entity\Tag;
@ -19,15 +17,13 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
class UpdateTagActionTest extends TestCase class UpdateTagActionTest extends TestCase
{ {
use ProphecyTrait;
private UpdateTagAction $action; private UpdateTagAction $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 UpdateTagAction($this->tagService->reveal()); $this->action = new UpdateTagAction($this->tagService);
} }
/** /**
@ -57,15 +53,14 @@ class UpdateTagActionTest extends TestCase
'oldName' => 'foo', 'oldName' => 'foo',
'newName' => 'bar', 'newName' => 'bar',
]); ]);
$rename = $this->tagService->renameTag( $this->tagService->expects($this->once())->method('renameTag')->with(
TagRenaming::fromNames('foo', 'bar'), TagRenaming::fromNames('foo', 'bar'),
Argument::type(ApiKey::class), $this->isInstanceOf(ApiKey::class),
)->willReturn(new Tag('bar')); )->willReturn(new Tag('bar'));
$resp = $this->action->handle($request); $resp = $this->action->handle($request);
self::assertEquals(204, $resp->getStatusCode()); self::assertEquals(204, $resp->getStatusCode());
$rename->shouldHaveBeenCalled();
} }
private function requestWithApiKey(): ServerRequestInterface private function requestWithApiKey(): ServerRequestInterface