|
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
|
|
|
|