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

MercureUpdatesGeneratorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A visitIsProperlySerializedIntoUpdate() 0 30 1
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