Completed
Pull Request — develop (#726)
by Alejandro
05:51
created

visitIsProperlySerializedIntoUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 30
rs 9.552
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Core\Mercure;
6
7
use PHPUnit\Framework\TestCase;
8
use Shlinkio\Shlink\Core\Entity\ShortUrl;
9
use Shlinkio\Shlink\Core\Entity\Visit;
10
use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGenerator;
11
use Shlinkio\Shlink\Core\Model\Visitor;
12
13
use function Shlinkio\Shlink\Common\json_decode;
14
15
class MercureUpdatesGeneratorTest extends TestCase
16
{
17
    private MercureUpdatesGenerator $generator;
18
19
    public function setUp(): void
20
    {
21
        $this->generator = new MercureUpdatesGenerator([]);
22
    }
23
24
    /** @test */
25
    public function visitIsProperlySerializedIntoUpdate(): void
26
    {
27
        $shortUrl = new ShortUrl('');
28
        $visit = new Visit($shortUrl, Visitor::emptyInstance());
29
30
        $update = $this->generator->newVisitUpdate($visit);
31
32
        $this->assertEquals(['https://shlink.io/new_visit'], $update->getTopics());
33
        $this->assertEquals([
34
            'shortUrl' => [
35
                'shortCode' => $shortUrl->getShortCode(),
36
                'shortUrl' => 'http:/' . $shortUrl->getShortCode(),
37
                'longUrl' => '',
38
                'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
39
                'visitsCount' => 0,
40
                'tags' => [],
41
                'meta' => [
42
                    'validSince' => null,
43
                    'validUntil' => null,
44
                    'maxVisits' => null,
45
                ],
46
                'domain' => null,
47
            ],
48
            'visit' => [
49
                'referer' => '',
50
                'userAgent' => '',
51
                'visitLocation' => null,
52
                'date' => $visit->getDate()->toAtomString(),
53
            ],
54
        ], json_decode($update->getData()));
55
    }
56
}
57