Completed
Push — develop ( 397f7d...ae636a )
by Alejandro
24s queued 13s
created

Rest/test/Action/Tag/CreateTagsActionTest.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Rest\Action\Tag;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Laminas\Diactoros\ServerRequest;
9
use PHPUnit\Framework\TestCase;
10
use Prophecy\Prophecy\ObjectProphecy;
11
use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
12
use Shlinkio\Shlink\Rest\Action\Tag\CreateTagsAction;
13
14
class CreateTagsActionTest extends TestCase
15
{
16
    private CreateTagsAction $action;
17
    private ObjectProphecy $tagService;
18
19
    public function setUp(): void
20
    {
21
        $this->tagService = $this->prophesize(TagServiceInterface::class);
22
        $this->action = new CreateTagsAction($this->tagService->reveal());
0 ignored issues
show
Deprecated Code introduced by
The class Shlinkio\Shlink\Rest\Action\Tag\CreateTagsAction has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
        $this->action = /** @scrutinizer ignore-deprecated */ new CreateTagsAction($this->tagService->reveal());
Loading history...
23
    }
24
25
    /**
26
     * @test
27
     * @dataProvider provideTags
28
     */
29
    public function processDelegatesIntoService(?array $tags): void
30
    {
31
        $request = (new ServerRequest())->withParsedBody(['tags' => $tags]);
32
        $deleteTags = $this->tagService->createTags($tags ?: [])->willReturn(new ArrayCollection());
33
34
        $response = $this->action->handle($request);
35
36
        self::assertEquals(200, $response->getStatusCode());
37
        $deleteTags->shouldHaveBeenCalled();
38
    }
39
40
    public function provideTags(): iterable
41
    {
42
        yield 'three tags' => [['foo', 'bar', 'baz']];
43
        yield 'two tags' => [['some', 'thing']];
44
        yield 'null tags' => [null];
45
        yield 'empty tags' => [[]];
46
    }
47
}
48