TagVisitsActionTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
dl 0
loc 25
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A providingCorrectShortCodeReturnsVisits() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Rest\Action\Visit;
6
7
use Laminas\Diactoros\ServerRequest;
8
use Laminas\Paginator\Adapter\ArrayAdapter;
9
use Laminas\Paginator\Paginator;
10
use PHPUnit\Framework\TestCase;
11
use Prophecy\Argument;
12
use Prophecy\PhpUnit\ProphecyTrait;
13
use Prophecy\Prophecy\ObjectProphecy;
14
use Shlinkio\Shlink\Core\Model\VisitsParams;
15
use Shlinkio\Shlink\Core\Service\VisitsTracker;
16
use Shlinkio\Shlink\Rest\Action\Visit\TagVisitsAction;
17
18
class TagVisitsActionTest extends TestCase
19
{
20
    use ProphecyTrait;
21
22
    private TagVisitsAction $action;
23
    private ObjectProphecy $visitsTracker;
24
25
    protected function setUp(): void
26
    {
27
        $this->visitsTracker = $this->prophesize(VisitsTracker::class);
28
        $this->action = new TagVisitsAction($this->visitsTracker->reveal());
29
    }
30
31
    /** @test */
32
    public function providingCorrectShortCodeReturnsVisits(): void
33
    {
34
        $tag = 'foo';
35
        $getVisits = $this->visitsTracker->visitsForTag($tag, Argument::type(VisitsParams::class))->willReturn(
36
            new Paginator(new ArrayAdapter([])),
37
        );
38
39
        $response = $this->action->handle((new ServerRequest())->withAttribute('tag', $tag));
40
41
        self::assertEquals(200, $response->getStatusCode());
42
        $getVisits->shouldHaveBeenCalledOnce();
43
    }
44
}
45