-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
185 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace KnotsPHP\PublicIP\Exceptions; | ||
|
||
class NoProviderSpecified extends Exception {} |
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use KnotsPHP\PublicIP\Finders\PublicIP; | ||
use KnotsPHP\PublicIP\Finders\PublicIPv4; | ||
use KnotsPHP\PublicIP\Finders\PublicIPv6; | ||
|
||
it('returns an ip address', function () { | ||
$ip = PublicIP::get(); | ||
|
||
$filtered = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6); | ||
|
||
expect($filtered)->toBeScalar(); | ||
}); | ||
|
||
it('returns an ipv4 address', function () { | ||
$ip = PublicIPv4::get(); | ||
|
||
$filtered = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); | ||
|
||
expect($filtered)->toBeString(); | ||
}); | ||
|
||
it('returns an ipv6 address', function () { | ||
$ip = PublicIPv6::get(); | ||
|
||
$filtered = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); | ||
|
||
expect($filtered)->toBeString(); | ||
})->skip( | ||
conditionOrMessage: fn () => getenv('CI') === 'true', | ||
message: 'This test is skipped because the CI environment does not have an IPv6 address.' | ||
); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use KnotsPHP\PublicIP\Exceptions\NoProviderSpecified; | ||
use KnotsPHP\PublicIP\Fetchers\CurlFetcher; | ||
|
||
it('can fetch an ip address', function () { | ||
$ip = (new CurlFetcher) | ||
->all() | ||
->fetch(); | ||
|
||
$filtered = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6); | ||
|
||
expect($filtered)->toBeString(); | ||
}) | ||
->skip( | ||
conditionOrMessage: ! CurlFetcher::isSupported(), | ||
message: 'curl is not installed on this system.' | ||
); | ||
|
||
it('throws an exception if no providers are set', function () { | ||
(new CurlFetcher) | ||
->fetch(); | ||
}) | ||
->throws(NoProviderSpecified::class) | ||
->skip( | ||
conditionOrMessage: ! CurlFetcher::isSupported(), | ||
message: 'curl is not installed on this system.' | ||
); |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use KnotsPHP\PublicIP\Exceptions\NoProviderSpecified; | ||
use KnotsPHP\PublicIP\Fetchers\DigFetcher; | ||
|
||
it('can fetch an ip address', function () { | ||
$ip = (new DigFetcher) | ||
->all() | ||
->fetch(); | ||
|
||
$filtered = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6); | ||
|
||
expect($filtered)->toBeString(); | ||
}) | ||
->skip( | ||
conditionOrMessage: ! DigFetcher::isSupported(), | ||
message: 'curl is not installed on this system.' | ||
); | ||
|
||
it('throws an exception if no providers are set', function () { | ||
(new DigFetcher) | ||
->fetch(); | ||
}) | ||
->throws(NoProviderSpecified::class) | ||
->skip( | ||
conditionOrMessage: ! DigFetcher::isSupported(), | ||
message: 'curl is not installed on this system.' | ||
); |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use KnotsPHP\PublicIP\Exceptions\NoProviderSpecified; | ||
use KnotsPHP\PublicIP\Fetchers\FileGetContentsFetcher; | ||
|
||
it('can fetch an ip address', function () { | ||
$ip = (new FileGetContentsFetcher) | ||
->all() | ||
->fetch(); | ||
|
||
$filtered = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6); | ||
|
||
expect($filtered)->toBeString(); | ||
}); | ||
|
||
it('throws an exception if no providers are set', function () { | ||
(new FileGetContentsFetcher) | ||
->fetch(); | ||
})->throws(NoProviderSpecified::class); |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use KnotsPHP\PublicIP\Enums\DnsProvider; | ||
use KnotsPHP\PublicIP\Fetchers\DigFetcher; | ||
|
||
test('every dns provider', function (DnsProvider $dnsProvider) { | ||
|
||
$ip = (new DigFetcher) | ||
->addProvider($dnsProvider) | ||
->fetch(); | ||
|
||
expect($ip)->not->toBeNull(); | ||
|
||
}) | ||
->with(DnsProvider::cases()) | ||
// ->skip('this test is not important for now') | ||
->skip( | ||
conditionOrMessage: ! DigFetcher::isSupported(), | ||
message: 'dig is not installed on this system.' | ||
); |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use KnotsPHP\PublicIP\Enums\HttpProvider; | ||
use KnotsPHP\PublicIP\Fetchers\CurlFetcher; | ||
|
||
test('every http provider', function (HttpProvider $httpProvider) { | ||
|
||
$ip = (new CurlFetcher) | ||
->addProvider($httpProvider) | ||
->fetch(); | ||
|
||
expect($ip)->not->toBeNull(); | ||
|
||
}) | ||
->with(HttpProvider::cases()) | ||
->skip( | ||
conditionOrMessage: ! CurlFetcher::isSupported(), | ||
message: 'curl is not installed on this system.' | ||
); |