Created MercureUpdatesGeneratorTest

This commit is contained in:
Alejandro Celaya 2020-04-12 18:01:13 +02:00
parent e97dfbfdda
commit 7f888c49b4
6 changed files with 61 additions and 5 deletions

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\EventDispatcher;
namespace ShlinkioTest\Shlink\Rest\EventDispatcher;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Core\EventDispatcher;
namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use Doctrine\DBAL\Connection;
use PHPUnit\Framework\TestCase;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Core\EventDispatcher;
namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;

View File

@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Mercure;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\Mercure\MercureUpdatesGenerator;
use Shlinkio\Shlink\Core\Model\Visitor;
use function Shlinkio\Shlink\Common\json_decode;
class MercureUpdatesGeneratorTest extends TestCase
{
private MercureUpdatesGenerator $generator;
public function setUp(): void
{
$this->generator = new MercureUpdatesGenerator([]);
}
/** @test */
public function visitIsProperlySerializedIntoUpdate(): void
{
$shortUrl = new ShortUrl('');
$visit = new Visit($shortUrl, Visitor::emptyInstance());
$update = $this->generator->newVisitUpdate($visit);
$this->assertEquals(['https://shlink.io/new_visit'], $update->getTopics());
$this->assertEquals([
'shortUrl' => [
'shortCode' => $shortUrl->getShortCode(),
'shortUrl' => 'http:/' . $shortUrl->getShortCode(),
'longUrl' => '',
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
'visitsCount' => 0,
'tags' => [],
'meta' => [
'validSince' => null,
'validUntil' => null,
'maxVisits' => null,
],
'domain' => null,
],
'visit' => [
'referer' => '',
'userAgent' => '',
'visitLocation' => null,
'date' => $visit->getDate()->toAtomString(),
],
], json_decode($update->getData()));
}
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\Action;
namespace ShlinkioTest\Shlink\Rest\Action;
use Cake\Chronos\Chronos;
use Laminas\Diactoros\Response\JsonResponse;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace ShlinkioApiTest\Shlink\Rest\Middleware\ShortUrl;
namespace ShlinkioTest\Shlink\Rest\Middleware\ShortUrl;
use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequestFactory;