client = $this->prophesize(Client::class); $this->ipResolver = new IpLocationResolver($this->client->reveal()); } /** * @test */ public function correctIpReturnsDecodedInfo() { $expected = [ 'foo' => 'bar', 'baz' => 'foo', ]; $response = new Response(); $response->getBody()->write(json_encode($expected)); $response->getBody()->rewind(); $this->client->get('http://freegeoip.net/json/1.2.3.4')->willReturn($response) ->shouldBeCalledTimes(1); $this->assertEquals($expected, $this->ipResolver->resolveIpLocation('1.2.3.4')); } /** * @test * @expectedException \Shlinkio\Shlink\Common\Exception\WrongIpException */ public function guzzleExceptionThrowsShlinkException() { $this->client->get('http://freegeoip.net/json/1.2.3.4')->willThrow(new TransferException()) ->shouldBeCalledTimes(1); $this->ipResolver->resolveIpLocation('1.2.3.4'); } }