From fdd8efc12d4a6ff8aae3bfb39faa5aeb0ae7f6ec Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 22 Mar 2020 11:12:30 +0100 Subject: [PATCH] Added test covering case in which the original address is provided when locating visits --- .../EventDispatcher/LocateShortUrlVisitTest.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php index 5f40bb7b..c8f6f388 100644 --- a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php +++ b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php @@ -130,13 +130,16 @@ class LocateShortUrlVisitTest extends TestCase yield 'localhost' => [new Visit($shortUrl, new Visitor('', '', IpAddress::LOCALHOST))]; } - /** @test */ - public function locatableVisitsResolveToLocation(): void + /** + * @test + * @dataProvider provideIpAddresses + */ + public function locatableVisitsResolveToLocation(string $anonymizedIpAddress, ?string $originalIpAddress): void { - $ipAddr = '1.2.3.0'; + $ipAddr = $originalIpAddress ?? $anonymizedIpAddress; $visit = new Visit(new ShortUrl(''), new Visitor('', '', $ipAddr)); $location = new Location('', '', '', '', 0.0, 0.0, ''); - $event = new ShortUrlVisited('123'); + $event = new ShortUrlVisited('123', $originalIpAddress); $findVisit = $this->em->find(Visit::class, '123')->willReturn($visit); $flush = $this->em->flush()->will(function (): void { @@ -155,6 +158,12 @@ class LocateShortUrlVisitTest extends TestCase $dispatch->shouldHaveBeenCalledOnce(); } + public function provideIpAddresses(): iterable + { + yield 'no original IP address' => ['1.2.3.0', null]; + yield 'original IP address' => ['1.2.3.0', '1.2.3.4']; + } + /** @test */ public function errorWhenUpdatingGeoLiteWithExistingCopyLogsWarning(): void {