Skip to content

Commit

Permalink
feat!: Use pest and remove Laravel 9
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkitjalan committed Mar 28, 2024
1 parent eaeddee commit 171687c
Show file tree
Hide file tree
Showing 11 changed files with 330 additions and 374 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.0, 8.1, 8.2]
laravel: [9.*, 10.*]
php: [8.1, 8.2, 8.3]
laravel: [10.*, 11.*]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- laravel: 10.*
php: 8.0

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand Down
5 changes: 3 additions & 2 deletions .gitignore
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
26 changes: 18 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
}
],
"require": {
"php": ">=8.0",
"illuminate/support": "^9|^10.0|^11.0",
"illuminate/console": "^9|^10.0|^11.0",
"guzzlehttp/guzzle": "^7.2|^7.3",
"geoip2/geoip2": "^2.13"
"php": "^8.1",
"illuminate/support": "^9.0|^10.0|^11.0",
"guzzlehttp/guzzle": "^7.5|^7.8",
"symfony/console": "^5.3|^6.0",
"geoip2/geoip2": "^3"
},
"require-dev": {
"phpunit/phpunit": "^9.5.24",
"mockery/mockery": "^1.5"
"mockery/mockery": "^1.6",
"pestphp/pest": "^2",
"pestphp/pest-plugin-drift": "v2.6.0",
"phpunit/phpunit": "^10"
},
"autoload": {
"psr-4": {
Expand All @@ -45,12 +47,20 @@
"aliases": {
"GeoIP": "PulkitJalan\\GeoIP\\Facades\\GeoIP"
}
},
"pest": {
"plugins": [
"Pest\\Drift\\Plugin"
]
}
},
"scripts": {
"test": "vendor/bin/phpunit"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
22 changes: 12 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<file>src/GeoIPServiceProvider.php</file>
<directory suffix=".php">src/config/</directory>
<directory suffix=".php">src/Facades/</directory>
<directory suffix=".php">src/Console/</directory>
</exclude>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
Expand All @@ -25,4 +16,15 @@
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<file>src/GeoIPServiceProvider.php</file>
<directory suffix=".php">src/config/</directory>
<directory suffix=".php">src/Facades/</directory>
<directory suffix=".php">src/Console/</directory>
</exclude>
</source>
</phpunit>
210 changes: 99 additions & 111 deletions tests/Drivers/IPApiDriverTest.php
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();
});
Loading

0 comments on commit 171687c

Please sign in to comment.