Completed
Push — master ( a30f79...cb6756 )
by Alejandro
27s queued 13s
created

MercureUpdatesGeneratorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
eloc 27
c 3
b 0
f 0
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A visitIsProperlySerializedIntoUpdate() 0 30 1
A provideMethod() 0 4 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\ShortUrlMeta;
12
use Shlinkio\Shlink\Core\Model\Visitor;
13
14
use function Shlinkio\Shlink\Common\json_decode;
15
16
class MercureUpdatesGeneratorTest extends TestCase
17
{
18
    private MercureUpdatesGenerator $generator;
19
20
    public function setUp(): void
21
    {
22
        $this->generator = new MercureUpdatesGenerator([]);
23
    }
24
25
    /**
26
     * @test
27
     * @dataProvider provideMethod
28
     */
29
    public function visitIsProperlySerializedIntoUpdate(string $method, string $expectedTopic): void
30
    {
31
        $shortUrl = new ShortUrl('', ShortUrlMeta::fromRawData(['customSlug' => 'foo']));
32
        $visit = new Visit($shortUrl, Visitor::emptyInstance());
33
34
        $update = $this->generator->{$method}($visit);
35
36
        $this->assertEquals([$expectedTopic], $update->getTopics());
37
        $this->assertEquals([
38
            'shortUrl' => [
39
                'shortCode' => $shortUrl->getShortCode(),
40
                'shortUrl' => 'http:/' . $shortUrl->getShortCode(),
41
                'longUrl' => '',
42
                'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
43
                'visitsCount' => 0,
44
                'tags' => [],
45
                'meta' => [
46
                    'validSince' => null,
47
                    'validUntil' => null,
48
                    'maxVisits' => null,
49
                ],
50
                'domain' => null,
51
            ],
52
            'visit' => [
53
                'referer' => '',
54
                'userAgent' => '',
55
                'visitLocation' => null,
56
                'date' => $visit->getDate()->toAtomString(),
57
            ],
58
        ], json_decode($update->getData()));
59
    }
60
61
    public function provideMethod(): iterable
62
    {
63
        yield 'newVisitUpdate' => ['newVisitUpdate', 'https://shlink.io/new-visit'];
64
        yield 'newShortUrlVisitUpdate' => ['newShortUrlVisitUpdate', 'https://shlink.io/new-visit/foo'];
65
    }
66
}
67