Completed
Push — develop ( ae060f...1a4eee )
by Alejandro
08:12 queued 08:08
created

TagVisitsActionTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
dl 0
loc 23
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\Prophecy\ObjectProphecy;
13
use Shlinkio\Shlink\Core\Model\VisitsParams;
14
use Shlinkio\Shlink\Core\Service\VisitsTracker;
15
use Shlinkio\Shlink\Rest\Action\Visit\TagVisitsAction;
16
17
class TagVisitsActionTest extends TestCase
18
{
19
    private TagVisitsAction $action;
20
    private ObjectProphecy $visitsTracker;
21
22
    protected function setUp(): void
23
    {
24
        $this->visitsTracker = $this->prophesize(VisitsTracker::class);
25
        $this->action = new TagVisitsAction($this->visitsTracker->reveal());
26
    }
27
28
    /** @test */
29
    public function providingCorrectShortCodeReturnsVisits(): void
30
    {
31
        $tag = 'foo';
32
        $getVisits = $this->visitsTracker->visitsForTag($tag, Argument::type(VisitsParams::class))->willReturn(
33
            new Paginator(new ArrayAdapter([])),
34
        );
35
36
        $response = $this->action->handle((new ServerRequest())->withAttribute('tag', $tag));
37
38
        $this->assertEquals(200, $response->getStatusCode());
39
        $getVisits->shouldHaveBeenCalledOnce();
40
    }
41
}
42