2018-10-16 18:21:51 +02:00
|
|
|
<?php
|
2019-10-05 17:26:10 +02:00
|
|
|
|
2018-10-16 18:21:51 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2022-09-23 19:03:32 +02:00
|
|
|
namespace ShlinkioTest\Shlink\Core\Visit\Entity;
|
2018-10-16 18:21:51 +02:00
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2018-10-16 18:21:51 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2022-09-23 19:03:32 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation;
|
2026-11-02 14:00:46 +01:00
|
|
|
use Shlinkio\Shlink\Geolocation\Model\Location;
|
2025-11-17 12:12:06 +01:00
|
|
|
use Shlinkio\Shlink\Importer\Model\ImportedShlinkVisitLocation;
|
2018-10-16 18:21:51 +02:00
|
|
|
|
|
|
|
|
class VisitLocationTest extends TestCase
|
|
|
|
|
{
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test, DataProvider('provideArgs')]
|
2019-02-26 22:39:26 +01:00
|
|
|
public function isEmptyReturnsTrueWhenAllValuesAreEmpty(array $args, bool $isEmpty): void
|
|
|
|
|
{
|
|
|
|
|
$payload = new Location(...$args);
|
2025-11-17 12:12:06 +01:00
|
|
|
$location = VisitLocation::fromLocation($payload);
|
2019-02-26 22:39:26 +01:00
|
|
|
|
2024-03-18 19:11:42 +01:00
|
|
|
self::assertEquals($isEmpty, $location->isEmpty);
|
2019-02-26 22:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 09:32:38 +01:00
|
|
|
public static function provideArgs(): iterable
|
2019-02-26 22:39:26 +01:00
|
|
|
{
|
|
|
|
|
yield [['', '', '', '', 0.0, 0.0, ''], true];
|
|
|
|
|
yield [['', '', '', '', 0.0, 0.0, 'dd'], false];
|
|
|
|
|
yield [['', '', '', 'dd', 0.0, 0.0, ''], false];
|
|
|
|
|
yield [['', '', 'dd', '', 0.0, 0.0, ''], false];
|
|
|
|
|
yield [['', 'dd', '', '', 0.0, 0.0, ''], false];
|
|
|
|
|
yield [['dd', '', '', '', 0.0, 0.0, ''], false];
|
|
|
|
|
yield [['', '', '', '', 1.0, 0.0, ''], false];
|
|
|
|
|
yield [['', '', '', '', 0.0, 1.0, ''], false];
|
|
|
|
|
}
|
2025-11-17 12:12:06 +01:00
|
|
|
|
|
|
|
|
#[Test]
|
|
|
|
|
public function jsonSerialization(): void
|
|
|
|
|
{
|
|
|
|
|
$location = VisitLocation::fromLocation(new ImportedShlinkVisitLocation(
|
|
|
|
|
countryCode: 'countryCode',
|
|
|
|
|
countryName: 'countryName',
|
|
|
|
|
regionName: 'regionName',
|
|
|
|
|
cityName: 'cityName',
|
|
|
|
|
timezone: 'timezone',
|
|
|
|
|
latitude: 1,
|
|
|
|
|
longitude: 2,
|
|
|
|
|
));
|
|
|
|
|
|
2026-05-22 08:42:47 +02:00
|
|
|
self::assertEquals(
|
|
|
|
|
[
|
|
|
|
|
'countryCode' => $location->countryCode,
|
|
|
|
|
'countryName' => $location->countryName,
|
|
|
|
|
'regionName' => $location->regionName,
|
|
|
|
|
'cityName' => $location->cityName,
|
|
|
|
|
'latitude' => $location->latitude,
|
|
|
|
|
'longitude' => $location->longitude,
|
|
|
|
|
'timezone' => $location->timezone,
|
|
|
|
|
'isEmpty' => $location->isEmpty,
|
|
|
|
|
],
|
|
|
|
|
$location->jsonSerialize(),
|
|
|
|
|
);
|
2025-11-17 12:12:06 +01:00
|
|
|
}
|
2018-10-16 18:21:51 +02:00
|
|
|
}
|