2022-09-18 19:44:01 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\EventDispatcher;
|
|
|
|
|
2023-02-09 22:42:18 +03:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2022-10-22 08:34:38 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2022-09-18 19:44:01 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\EventDispatcher\Event\GeoLiteDbCreated;
|
|
|
|
use Shlinkio\Shlink\Core\EventDispatcher\LocateUnlocatedVisits;
|
2022-09-23 20:03:32 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
2022-09-23 15:50:26 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocatorInterface;
|
|
|
|
use Shlinkio\Shlink\Core\Visit\Geolocation\VisitToLocationHelperInterface;
|
2022-09-23 19:05:17 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
2022-09-18 19:44:01 +03:00
|
|
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
|
|
|
|
|
|
|
class LocateUnlocatedVisitsTest extends TestCase
|
|
|
|
{
|
|
|
|
private LocateUnlocatedVisits $listener;
|
2022-10-24 20:59:03 +03:00
|
|
|
private MockObject & VisitLocatorInterface $locator;
|
|
|
|
private MockObject & VisitToLocationHelperInterface $visitToLocation;
|
2022-09-18 19:44:01 +03:00
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
2022-10-22 08:34:38 +03:00
|
|
|
$this->locator = $this->createMock(VisitLocatorInterface::class);
|
|
|
|
$this->visitToLocation = $this->createMock(VisitToLocationHelperInterface::class);
|
2022-09-18 19:44:01 +03:00
|
|
|
|
2022-10-22 08:34:38 +03:00
|
|
|
$this->listener = new LocateUnlocatedVisits($this->locator, $this->visitToLocation);
|
2022-09-18 19:44:01 +03:00
|
|
|
}
|
|
|
|
|
2023-02-09 22:42:18 +03:00
|
|
|
#[Test]
|
2022-09-18 19:44:01 +03:00
|
|
|
public function locatorIsCalledWhenInvoked(): void
|
|
|
|
{
|
2022-10-23 19:15:57 +03:00
|
|
|
$this->locator->expects($this->once())->method('locateUnlocatedVisits')->with($this->listener);
|
2022-09-18 19:44:01 +03:00
|
|
|
($this->listener)(new GeoLiteDbCreated());
|
|
|
|
}
|
|
|
|
|
2023-02-09 22:42:18 +03:00
|
|
|
#[Test]
|
2022-09-18 19:44:01 +03:00
|
|
|
public function visitToLocationHelperIsCalledToGeolocateVisits(): void
|
|
|
|
{
|
|
|
|
$visit = Visit::forBasePath(Visitor::emptyInstance());
|
|
|
|
$location = Location::emptyInstance();
|
|
|
|
|
2022-10-23 19:15:57 +03:00
|
|
|
$this->visitToLocation->expects($this->once())->method('resolveVisitLocation')->with($visit)->willReturn(
|
|
|
|
$location,
|
|
|
|
);
|
2022-09-18 19:44:01 +03:00
|
|
|
|
|
|
|
$result = $this->listener->geolocateVisit($visit);
|
|
|
|
|
|
|
|
self::assertSame($location, $result);
|
|
|
|
}
|
|
|
|
}
|