diff --git a/src/ipinfolaravel.php b/src/ipinfolaravel.php index 4490f19..e5ee902 100644 --- a/src/ipinfolaravel.php +++ b/src/ipinfolaravel.php @@ -23,16 +23,28 @@ class ipinfolaravel /** * Return true to skip IPinfo lookup, otherwise return false. - * @var function + * @var callable|null */ public $filter = null; /** - * Provides ip. + * IP Handler interface instance. * @var ipinfo\ipinfolaravel\iphandler\IPHandlerInterface */ public $ip_selector = null; + /** + * IPinfo client object. + * @var IPinfoClient + */ + public $ipinfo = null; + + /** + * Boolean flag to handle exceptions. + * @var bool + */ + public $no_except = false; + const CACHE_MAXSIZE = 4096; const CACHE_TTL = 60 * 24; @@ -50,7 +62,7 @@ public function handle($request, Closure $next) $details = null; } else { try { - $details = $this->ipinfo->getDetails($this->ip_selector->getIP($request)); + $details = $this->ipinfo->getDetails($this->ip_selector->getIP($request)); } catch (\Exception $e) { $details = null; @@ -58,7 +70,7 @@ public function handle($request, Closure $next) // middleware unfortunately, so we catch it for them. but for // backwards-compatibility, we throw the exception again unless // they've told us not to. - if ($this->no_except != true) { + if (!$this->no_except) { throw $e; } } diff --git a/tests/IpinfolaravelTest.php b/tests/IpinfolaravelTest.php index 8e647cc..1da415a 100644 --- a/tests/IpinfolaravelTest.php +++ b/tests/IpinfolaravelTest.php @@ -92,12 +92,14 @@ public function test_handle_skips_lookup_when_filter_returns_true() public function test_handle_throws_if_client_throws_and_no_except_false() { - $this->expectException(\Exception::class); + $expected = new \RuntimeException('Boom! That went wrong.'); + + $this->expectExceptionObject($expected); $client = $this->createMock(IPinfoClient::class); $client ->method("getDetails") - ->willThrowException(new \Exception("fail")); + ->willThrowException($expected); $selector = $this->createMock(IPHandlerInterface::class); $selector->method("getIP")->willReturn("1.2.3.4");