Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Facades/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* @method static \Stevebauman\Location\Drivers\Driver[] drivers()
* @method static \Stevebauman\Location\Position|bool get(string $ip = null)
* @method static \Stevebauman\Location\Position|false get(string $ip = null)
* @method static void resolveRequestUsing(callable $callback)
* @method static void setDriver(\Stevebauman\Location\Drivers\Driver $driver)
*/
Expand Down
2 changes: 1 addition & 1 deletion src/LocationFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __call(string $method, array $parameters): mixed
/**
* Get a fake location instance.
*/
public function get(?string $ip = null): Position|bool
public function get(?string $ip = null): Position|false
{
$ip ??= '127.0.0.1';

Expand Down
8 changes: 2 additions & 6 deletions src/LocationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,9 @@ public function setDefaultDriver(): static
/**
* Attempt to retrieve the location of the user.
*/
public function get(?string $ip = null): Position|bool
public function get(?string $ip = null): Position|false
{
if ($location = $this->driver->get($this->request()->setIp($ip))) {
return $location;
}

return false;
return $this->driver->get($this->request()->setIp($ip));
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/LocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
$this->assertInstanceOf(Position::class, Location::get());
});

it('returns false when no driver can resolve a location', function () {
$driver = m::mock(Driver::class)
->makePartial()
->shouldAllowMockingProtectedMethods();

$driver->shouldReceive('process')
->once()
->andReturn(false);

Location::setDriver($driver);

expect(Location::get())->toBeFalse();
});

it('throws an exception when the driver does not exist', function () {
config(['location.driver' => 'Test']);

Expand Down