1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ShlinkioTest\Shlink\Rest\Action\Tag; |
6
|
|
|
|
7
|
|
|
use Laminas\Diactoros\ServerRequest; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Prophecy\PhpUnit\ProphecyTrait; |
10
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
11
|
|
|
use Shlinkio\Shlink\Core\Entity\Tag; |
12
|
|
|
use Shlinkio\Shlink\Core\Exception\ValidationException; |
13
|
|
|
use Shlinkio\Shlink\Core\Tag\TagServiceInterface; |
14
|
|
|
use Shlinkio\Shlink\Rest\Action\Tag\UpdateTagAction; |
15
|
|
|
|
16
|
|
|
class UpdateTagActionTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
use ProphecyTrait; |
19
|
|
|
|
20
|
|
|
private UpdateTagAction $action; |
21
|
|
|
private ObjectProphecy $tagService; |
22
|
|
|
|
23
|
|
|
public function setUp(): void |
24
|
|
|
{ |
25
|
|
|
$this->tagService = $this->prophesize(TagServiceInterface::class); |
26
|
|
|
$this->action = new UpdateTagAction($this->tagService->reveal()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @test |
31
|
|
|
* @dataProvider provideParams |
32
|
|
|
*/ |
33
|
|
|
public function whenInvalidParamsAreProvidedAnErrorIsReturned(array $bodyParams): void |
34
|
|
|
{ |
35
|
|
|
$request = (new ServerRequest())->withParsedBody($bodyParams); |
36
|
|
|
|
37
|
|
|
$this->expectException(ValidationException::class); |
38
|
|
|
|
39
|
|
|
$this->action->handle($request); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function provideParams(): iterable |
43
|
|
|
{ |
44
|
|
|
yield 'old name only' => [['oldName' => 'foo']]; |
45
|
|
|
yield 'new name only' => [['newName' => 'foo']]; |
46
|
|
|
yield 'no params' => [[]]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** @test */ |
50
|
|
|
public function correctInvocationRenamesTag(): void |
51
|
|
|
{ |
52
|
|
|
$request = (new ServerRequest())->withParsedBody([ |
53
|
|
|
'oldName' => 'foo', |
54
|
|
|
'newName' => 'bar', |
55
|
|
|
]); |
56
|
|
|
$rename = $this->tagService->renameTag('foo', 'bar')->willReturn(new Tag('bar')); |
57
|
|
|
|
58
|
|
|
$resp = $this->action->handle($request); |
59
|
|
|
|
60
|
|
|
self::assertEquals(204, $resp->getStatusCode()); |
61
|
|
|
$rename->shouldHaveBeenCalled(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|