shlink/module/Core/test/EventDispatcher/LocateUnlocatedVisitsTest.php
2022-10-24 19:59:03 +02:00

53 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\EventDispatcher;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\EventDispatcher\Event\GeoLiteDbCreated;
use Shlinkio\Shlink\Core\EventDispatcher\LocateUnlocatedVisits;
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocatorInterface;
use Shlinkio\Shlink\Core\Visit\Geolocation\VisitToLocationHelperInterface;
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
class LocateUnlocatedVisitsTest extends TestCase
{
private LocateUnlocatedVisits $listener;
private MockObject & VisitLocatorInterface $locator;
private MockObject & VisitToLocationHelperInterface $visitToLocation;
protected function setUp(): void
{
$this->locator = $this->createMock(VisitLocatorInterface::class);
$this->visitToLocation = $this->createMock(VisitToLocationHelperInterface::class);
$this->listener = new LocateUnlocatedVisits($this->locator, $this->visitToLocation);
}
/** @test */
public function locatorIsCalledWhenInvoked(): void
{
$this->locator->expects($this->once())->method('locateUnlocatedVisits')->with($this->listener);
($this->listener)(new GeoLiteDbCreated());
}
/** @test */
public function visitToLocationHelperIsCalledToGeolocateVisits(): void
{
$visit = Visit::forBasePath(Visitor::emptyInstance());
$location = Location::emptyInstance();
$this->visitToLocation->expects($this->once())->method('resolveVisitLocation')->with($visit)->willReturn(
$location,
);
$result = $this->listener->geolocateVisit($visit);
self::assertSame($location, $result);
}
}