From d07104b8d914dfc9d116606dbe9b249491939aeb Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Oct 2022 07:34:38 +0200 Subject: [PATCH] Migrated LocateUnlocatedVisitsTest to use PHPUnit mocks --- .../LocateUnlocatedVisitsTest.php | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/module/Core/test/EventDispatcher/LocateUnlocatedVisitsTest.php b/module/Core/test/EventDispatcher/LocateUnlocatedVisitsTest.php index 5eb97592..b3063374 100644 --- a/module/Core/test/EventDispatcher/LocateUnlocatedVisitsTest.php +++ b/module/Core/test/EventDispatcher/LocateUnlocatedVisitsTest.php @@ -4,9 +4,8 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Core\EventDispatcher; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\EventDispatcher\Event\GeoLiteDbCreated; use Shlinkio\Shlink\Core\EventDispatcher\LocateUnlocatedVisits; use Shlinkio\Shlink\Core\Visit\Entity\Visit; @@ -17,25 +16,23 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location; class LocateUnlocatedVisitsTest extends TestCase { - use ProphecyTrait; - private LocateUnlocatedVisits $listener; - private ObjectProphecy $locator; - private ObjectProphecy $visitToLocation; + private MockObject $locator; + private MockObject $visitToLocation; protected function setUp(): void { - $this->locator = $this->prophesize(VisitLocatorInterface::class); - $this->visitToLocation = $this->prophesize(VisitToLocationHelperInterface::class); + $this->locator = $this->createMock(VisitLocatorInterface::class); + $this->visitToLocation = $this->createMock(VisitToLocationHelperInterface::class); - $this->listener = new LocateUnlocatedVisits($this->locator->reveal(), $this->visitToLocation->reveal()); + $this->listener = new LocateUnlocatedVisits($this->locator, $this->visitToLocation); } /** @test */ public function locatorIsCalledWhenInvoked(): void { + $this->locator->expects($this->once())->method('locateUnlocatedVisits')->with($this->equalTo($this->listener)); ($this->listener)(new GeoLiteDbCreated()); - $this->locator->locateUnlocatedVisits($this->listener)->shouldHaveBeenCalledOnce(); } /** @test */ @@ -44,11 +41,12 @@ class LocateUnlocatedVisitsTest extends TestCase $visit = Visit::forBasePath(Visitor::emptyInstance()); $location = Location::emptyInstance(); - $resolve = $this->visitToLocation->resolveVisitLocation($visit)->willReturn($location); + $this->visitToLocation->expects($this->once())->method('resolveVisitLocation')->with( + $this->equalTo($visit), + )->willReturn($location); $result = $this->listener->geolocateVisit($visit); self::assertSame($location, $result); - $resolve->shouldHaveBeenCalledOnce(); } }