ipLocationResolver = $this->prophesize(IpLocationResolverInterface::class); $this->helper = new VisitToLocationHelper($this->ipLocationResolver->reveal()); } /** * @test * @dataProvider provideNonLocatableVisits */ public function throwsExpectedErrorForNonLocatableVisit( Visit $visit, IpCannotBeLocatedException $expectedException, ): void { $this->expectExceptionObject($expectedException); $this->ipLocationResolver->resolveIpLocation(Argument::cetera())->shouldNotBeCalled(); $this->helper->resolveVisitLocation($visit); } public function provideNonLocatableVisits(): iterable { yield [Visit::forBasePath(Visitor::emptyInstance()), IpCannotBeLocatedException::forEmptyAddress()]; yield [ Visit::forBasePath(new Visitor('foo', 'bar', IpAddress::LOCALHOST, '')), IpCannotBeLocatedException::forLocalhost(), ]; } /** @test */ public function throwsGenericErrorWhenResolvingIpFails(): void { $e = new WrongIpException(''); $this->expectExceptionObject(IpCannotBeLocatedException::forError($e)); $this->ipLocationResolver->resolveIpLocation(Argument::cetera())->willThrow($e) ->shouldBeCalledOnce(); $this->helper->resolveVisitLocation(Visit::forBasePath(new Visitor('foo', 'bar', '1.2.3.4', ''))); } }