Completed
Push — master ( 67e465...aa77c9 )
by Alejandro
13s queued 10s
created

VisitTest::isProperlyJsonSerialized()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Core\Entity;
5
6
use Cake\Chronos\Chronos;
7
use PHPUnit\Framework\TestCase;
8
use Shlinkio\Shlink\Core\Entity\ShortUrl;
9
use Shlinkio\Shlink\Core\Entity\Visit;
10
use Shlinkio\Shlink\Core\Model\Visitor;
11
12
class VisitTest extends TestCase
13
{
14
    /**
15
     * @test
16
     * @dataProvider provideDates
17
     */
18
    public function isProperlyJsonSerialized(?Chronos $date)
19
    {
20
        $visit = new Visit(new ShortUrl(''), new Visitor('Chrome', 'some site', '1.2.3.4'), $date);
21
22
        $this->assertEquals([
23
            'referer' => 'some site',
24
            'date' => ($date ?? $visit->getDate())->toAtomString(),
25
            'userAgent' => 'Chrome',
26
            'visitLocation' => null,
27
28
            // Deprecated
29
            'remoteAddr' => null,
30
        ], $visit->jsonSerialize());
31
    }
32
33
    public function provideDates(): array
34
    {
35
        return [
36
            [null],
37
            [Chronos::now()->subDays(10)],
38
        ];
39
    }
40
}
41