reader = $this->prophesize(Reader::class); $this->resolver = new GeoLite2LocationResolver($this->reader->reveal()); } /** * @test * @dataProvider provideReaderExceptions */ public function exceptionIsThrownIfReaderThrowsException(string $e, string $message) { $ipAddress = '1.2.3.4'; $cityMethod = $this->reader->city($ipAddress)->willThrow($e); $this->expectException(WrongIpException::class); $this->expectExceptionMessage($message); $this->expectExceptionCode(0); $cityMethod->shouldBeCalledOnce(); $this->resolver->resolveIpLocation($ipAddress); } public function provideReaderExceptions(): array { return [ [AddressNotFoundException::class, 'Provided IP "1.2.3.4" is invalid'], [InvalidDatabaseException::class, 'Provided GeoLite2 db file is invalid'], ]; } /** @test */ public function resolvedCityIsProperlyMapped(): void { $ipAddress = '1.2.3.4'; $city = new City([]); $cityMethod = $this->reader->city($ipAddress)->willReturn($city); $result = $this->resolver->resolveIpLocation($ipAddress); $this->assertEquals(Location::emptyInstance(), $result); $cityMethod->shouldHaveBeenCalledOnce(); } }