-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Use pest and remove Laravel 9
- Loading branch information
1 parent
eaeddee
commit 171687c
Showing
11 changed files
with
330 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
build | ||
composer.lock | ||
vendor | ||
.php_cs.cache | ||
coverage | ||
.phpunit.result.cache | ||
/.idea | ||
/.vscode | ||
.phpunit.cache | ||
.phpunit.result.cache | ||
.php-cs-fixer.cache | ||
.php_cs.cache | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,105 @@ | ||
<?php | ||
|
||
namespace PulkitJalan\GeoIP\Tests\Drivers; | ||
|
||
use Illuminate\Support\Arr; | ||
use PulkitJalan\GeoIP\GeoIP; | ||
use PulkitJalan\GeoIP\Tests\AbstractTestCase; | ||
use PulkitJalan\GeoIP\Exceptions\GeoIPException; | ||
|
||
class IPApiDriverTest extends AbstractTestCase | ||
{ | ||
public function test_ip_api() | ||
{ | ||
$config = [ | ||
'driver' => 'ip-api', | ||
]; | ||
|
||
$geoip = new GeoIP($config); | ||
$geoip = $geoip->setIp($this->validIp); | ||
|
||
$this->assertEquals($geoip->getCountry(), 'United Kingdom'); | ||
|
||
$geoip = $geoip->setIp($this->invalidIp); | ||
|
||
$this->assertEquals('fail', Arr::get($geoip->getRaw(), 'status')); | ||
|
||
$this->assertEquals([ | ||
'city' => null, | ||
'country' => null, | ||
'countryCode' => null, | ||
'latitude' => null, | ||
'longitude' => null, | ||
'region' => null, | ||
'regionCode' => null, | ||
'timezone' => null, | ||
'postalCode' => null, | ||
], $geoip->get()); | ||
|
||
$this->assertEquals('', $geoip->getCountry()); | ||
} | ||
|
||
public function test_get_multiple_ipaddress() | ||
{ | ||
$config = [ | ||
'driver' => 'ip-api', | ||
]; | ||
|
||
$geoip = new GeoIP($config); | ||
$geoip->setIp($this->multipleIps); | ||
$ip = $geoip->getIp(); | ||
|
||
$this->assertEquals($this->validIp, $ip); | ||
$this->assertTrue(! filter_var($ip, FILTER_VALIDATE_IP) === false); | ||
} | ||
|
||
public function test_get_random_ipaddress() | ||
{ | ||
$config = [ | ||
'driver' => 'ip-api', | ||
'random' => true, | ||
]; | ||
|
||
$geoip = new GeoIP($config); | ||
$ip = $geoip->getIp(); | ||
|
||
$this->assertNotEquals($this->invalidIp, $ip); | ||
$this->assertTrue(! filter_var($ip, FILTER_VALIDATE_IP) === false); | ||
} | ||
|
||
public function test_get_non_random_ipaddress() | ||
{ | ||
$config = [ | ||
'driver' => 'ip-api', | ||
'random' => false, | ||
]; | ||
|
||
$geoip = new GeoIP($config); | ||
$ip = $geoip->getIp(); | ||
|
||
$this->assertEquals($this->invalidIp, $ip); | ||
$this->assertTrue(! filter_var($ip, FILTER_VALIDATE_IP) === false); | ||
} | ||
|
||
public function test_ip_api_pro_exception() | ||
{ | ||
$config = [ | ||
'driver' => 'ip-api', | ||
'ip-api' => [ | ||
'key' => 'test', | ||
], | ||
]; | ||
|
||
$this->expectException(GeoIPException::class); | ||
|
||
$geoip = new GeoIP($config); | ||
$geoip = $geoip->setIp($this->validIp); | ||
|
||
$geoip->get(); | ||
} | ||
|
||
public function test_ip_api_pro_exception_getRaw() | ||
{ | ||
$config = [ | ||
'driver' => 'ip-api', | ||
'ip-api' => [ | ||
'key' => 'test', | ||
], | ||
]; | ||
|
||
$this->expectException(GeoIPException::class); | ||
|
||
$geoip = new GeoIP($config); | ||
$geoip = $geoip->setIp($this->validIp); | ||
|
||
$geoip->getRaw(); | ||
} | ||
} | ||
test('ip api', function () { | ||
$config = [ | ||
'driver' => 'ip-api', | ||
]; | ||
|
||
$geoip = new GeoIP($config); | ||
$geoip = $geoip->setIp($this->validIp); | ||
|
||
expect('United Kingdom')->toEqual($geoip->getCountry()); | ||
|
||
$geoip = $geoip->setIp($this->invalidIp); | ||
|
||
expect(Arr::get($geoip->getRaw(), 'status'))->toEqual('fail'); | ||
|
||
expect($geoip->get())->toEqual([ | ||
'city' => null, | ||
'country' => null, | ||
'countryCode' => null, | ||
'latitude' => null, | ||
'longitude' => null, | ||
'region' => null, | ||
'regionCode' => null, | ||
'timezone' => null, | ||
'postalCode' => null, | ||
]); | ||
|
||
expect($geoip->getCountry())->toEqual(''); | ||
}); | ||
|
||
test('get multiple ipaddress', function () { | ||
$config = [ | ||
'driver' => 'ip-api', | ||
]; | ||
|
||
$geoip = new GeoIP($config); | ||
$geoip->setIp($this->multipleIps); | ||
$ip = $geoip->getIp(); | ||
|
||
expect($ip)->toEqual($this->validIp); | ||
expect(! filter_var($ip, FILTER_VALIDATE_IP) === false)->toBeTrue(); | ||
}); | ||
|
||
test('get random ipaddress', function () { | ||
$config = [ | ||
'driver' => 'ip-api', | ||
'random' => true, | ||
]; | ||
|
||
$geoip = new GeoIP($config); | ||
$ip = $geoip->getIp(); | ||
|
||
$this->assertNotEquals($this->invalidIp, $ip); | ||
expect(! filter_var($ip, FILTER_VALIDATE_IP) === false)->toBeTrue(); | ||
}); | ||
|
||
test('get non random ipaddress', function () { | ||
$config = [ | ||
'driver' => 'ip-api', | ||
'random' => false, | ||
]; | ||
|
||
$geoip = new GeoIP($config); | ||
$ip = $geoip->getIp(); | ||
|
||
expect($ip)->toEqual($this->invalidIp); | ||
expect(! filter_var($ip, FILTER_VALIDATE_IP) === false)->toBeTrue(); | ||
}); | ||
|
||
test('ip api pro exception', function () { | ||
$config = [ | ||
'driver' => 'ip-api', | ||
'ip-api' => [ | ||
'key' => 'test', | ||
], | ||
]; | ||
|
||
$this->expectException(GeoIPException::class); | ||
|
||
$geoip = new GeoIP($config); | ||
$geoip = $geoip->setIp($this->validIp); | ||
|
||
$geoip->get(); | ||
}); | ||
|
||
test('ip api pro exception get raw', function () { | ||
$config = [ | ||
'driver' => 'ip-api', | ||
'ip-api' => [ | ||
'key' => 'test', | ||
], | ||
]; | ||
|
||
$this->expectException(GeoIPException::class); | ||
|
||
$geoip = new GeoIP($config); | ||
$geoip = $geoip->setIp($this->validIp); | ||
|
||
$geoip->getRaw(); | ||
}); |
Oops, something went wrong.