Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support GeoIP2-php 3.0.0 #93

Merged
merged 14 commits into from
Nov 19, 2024
32 changes: 30 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,79 @@ jobs:
include:
- php: '7.2'
symfony: '2.8.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_4.neon
- php: '7.2'
symfony: '3.0.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_4.neon
- php: '7.2'
symfony: '3.1.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_4.neon
- php: '7.2'
symfony: '3.2.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_4.neon
- php: '7.2'
symfony: '3.3.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_4.neon
- php: '7.2'
symfony: '3.4.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_4.neon
- php: '7.2'
symfony: '4.0.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_4.neon
- php: '7.2'
symfony: '4.1.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_4.neon
- php: '7.2'
symfony: '4.2.*'
geoip2: '~2.0'
phpstan: .phpstan/default.neon
- php: '7.2'
symfony: '4.3.*'
geoip2: '~2.0'
phpstan: .phpstan/default.neon
- php: '7.2'
symfony: '4.4.*'
geoip2: '~2.0'
phpstan: .phpstan/default.neon
- php: '7.2'
symfony: '5.0.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_5.neon
- php: '7.2'
symfony: '5.1.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_5.neon
- php: '7.2'
symfony: '5.2.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_5.neon
- php: '8.0'
symfony: '5.2.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_5.neon
- php: '8.1'
symfony: '6.4.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_6.neon
- php: '8.2'
symfony: '7.0.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_6.neon
- php: '8.3'
symfony: '7.0.*'
geoip2: '~2.0'
phpstan: .phpstan/symfony_6.neon
- php: '8.3'
symfony: '7.0.*'
geoip2: '~3.0'
phpstan: .phpstan/symfony_6.neon
steps:
- name: Checkout
Expand All @@ -82,6 +107,9 @@ jobs:
- name: Install Symfony
run: composer require symfony/symfony:"${{ matrix.symfony }}" --no-update

- name: Install GeoIP2-php
run: composer require geoip2/geoip2:"${{ matrix.geoip2 }}" --no-update

- name: 'Install Composer dependencies (highest)'
uses: 'ramsey/composer-install@v1'
with:
Expand All @@ -91,7 +119,7 @@ jobs:
run: vendor/bin/phpunit --coverage-clover build/coverage-clover.xml

- name: Send coverage results to Scrutinizer CI
if: matrix.php != '8.0' && matrix.php != '8.1' && matrix.php != '8.2'
if: matrix.php != '8.0' && matrix.php != '8.1' && matrix.php != '8.2' && matrix.php != '8.3'
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/coverage-clover.xml
Expand All @@ -101,7 +129,7 @@ jobs:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: 'PHP ${{ matrix.php }} + ${{ matrix.symfony }}'
if: matrix.php != '8.0' && matrix.php != '8.1' && matrix.php != '8.2'
if: matrix.php != '8.0' && matrix.php != '8.1' && matrix.php != '8.2' && matrix.php != '8.3'
run: |
composer global require php-coveralls/php-coveralls
php-coveralls -x build/coverage-clover.xml -o build/coveralls-upload.json -v
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ext-phar": "*",
"ext-zlib": "*",
"php": ">=7.2.0",
"geoip2/geoip2": "~2.0",
"geoip2/geoip2": "~2.0|~3.0",
"symfony/http-kernel": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0",
"symfony/dependency-injection": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0",
"symfony/expression-language": "~2.8|~3.0|~4.0|~5.0|~6.0|~7.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/ReaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(array $databases, string $reader_class = Reader::cla
*
* @return Reader
*/
public function create(string $database, array $locales = null): Reader
public function create(string $database, ?array $locales = null): Reader
{
if (!array_key_exists($database, $this->databases)) {
$databases = implode('", "', array_keys($this->databases));
Expand Down
43 changes: 21 additions & 22 deletions tests/Command/DownloadDatabaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ public function testInvalidURLArgument(): void
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('URL of downloaded GeoIP2 database should be a string, got ["https:\/\/example.com\/GeoIP2.tar.gz"] instead.');

$url = ['https://example.com/GeoIP2.tar.gz'];
$target = '/tmp/GeoIP2.mmdb';

$this->input
->expects($this->at(4))
->expects($this->exactly(2))
->method('getArgument')
->with('url')
->willReturn(['https://example.com/GeoIP2.tar.gz']);
->withConsecutive(['url'], ['target'])
->willReturnOnConsecutiveCalls($url, $target);

$this->command->run($this->input, $this->output);
}
Expand All @@ -92,11 +95,14 @@ public function testNoTargetArgument(): void
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Target download path should be a string, got null instead.');

$url = 'https://example.com/GeoIP2.tar.gz';
$target = null;

$this->input
->expects($this->at(4))
->expects($this->exactly(2))
->method('getArgument')
->with('url')
->willReturn('https://example.com/GeoIP2.tar.gz');
->withConsecutive(['url'], ['target'])
->willReturnOnConsecutiveCalls($url, $target);

$this->command->run($this->input, $this->output);
}
Expand All @@ -106,16 +112,14 @@ public function testInvalidTargetArgument(): void
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Target download path should be a string, got ["\/tmp\/GeoIP2.mmdb"] instead.');

$url = 'https://example.com/GeoIP2.tar.gz';
$target = ['/tmp/GeoIP2.mmdb'];

$this->input
->expects($this->at(4))
->method('getArgument')
->with('url')
->willReturn('https://example.com/GeoIP2.tar.gz');
$this->input
->expects($this->at(5))
->expects($this->exactly(2))
->method('getArgument')
->with('target')
->willReturn(['/tmp/GeoIP2.mmdb']);
->withConsecutive(['url'], ['target'])
->willReturnOnConsecutiveCalls($url, $target);

$this->command->run($this->input, $this->output);
}
Expand All @@ -126,15 +130,10 @@ public function testDownload(): void
$target = '/tmp/GeoIP2.mmdb';

$this->input
->expects($this->at(4))
->method('getArgument')
->with('url')
->willReturn($url);
$this->input
->expects($this->at(5))
->expects($this->exactly(2))
->method('getArgument')
->with('target')
->willReturn($target);
->withConsecutive(['url'], ['target'])
->willReturnOnConsecutiveCalls($url, $target);

$this->downloader
->expects($this->once())
Expand Down
29 changes: 14 additions & 15 deletions tests/Command/UpdateDatabaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testInvalidDatabasesArgument(): void
$this->expectExceptionMessage('Updated databases should be a array, got "" instead.');

$this->input
->expects($this->at(4))
->expects($this->once())
->method('getArgument')
->with('databases')
->willReturn('');
Expand All @@ -89,7 +89,7 @@ public function testUndefinedDatabase(): void
$this->expectExceptionMessage('Undefined "default" database.');

$this->input
->expects($this->at(4))
->expects($this->once())
->method('getArgument')
->with('databases')
->willReturn(['default']);
Expand All @@ -104,7 +104,7 @@ public function testUndefinedDatabase2(): void
$this->expectExceptionMessage('Undefined "foo" database.');

$this->input
->expects($this->at(4))
->expects($this->once())
->method('getArgument')
->with('databases')
->willReturn(['foo']);
Expand All @@ -121,7 +121,7 @@ public function testNoDatabaseURL(): void
$this->expectExceptionMessage('Invalid "default" database config.');

$this->input
->expects($this->at(4))
->expects($this->once())
->method('getArgument')
->with('databases')
->willReturn(['default']);
Expand All @@ -138,7 +138,7 @@ public function testNoDatabasePath(): void
$this->expectExceptionMessage('Invalid "default" database config.');

$this->input
->expects($this->at(4))
->expects($this->once())
->method('getArgument')
->with('databases')
->willReturn(['default']);
Expand All @@ -157,7 +157,7 @@ public function testInvalidDatabaseURL(): void
$this->expectExceptionMessage('Invalid "default" database config.');

$this->input
->expects($this->at(4))
->expects($this->once())
->method('getArgument')
->with('databases')
->willReturn(['default']);
Expand All @@ -176,7 +176,7 @@ public function testInvalidDatabasePath(): void
$this->expectExceptionMessage('Invalid "default" database config.');

$this->input
->expects($this->at(4))
->expects($this->once())
->method('getArgument')
->with('databases')
->willReturn(['default']);
Expand All @@ -193,7 +193,7 @@ public function testInvalidDatabasePath(): void
public function testDownloadOneDatabases(): void
{
$this->input
->expects($this->at(4))
->expects($this->once())
->method('getArgument')
->with('databases')
->willReturn(['default']);
Expand All @@ -215,7 +215,7 @@ public function testDownloadOneDatabases(): void
public function testDownloadSeveralDatabases(): void
{
$this->input
->expects($this->at(4))
->expects($this->once())
->method('getArgument')
->with('databases')
->willReturn(['second', 'first']);
Expand All @@ -232,13 +232,12 @@ public function testDownloadSeveralDatabases(): void
];

$this->downloader
->expects($this->at(0))
->method('download')
->with($databases['second']['url'], $databases['second']['path']);
$this->downloader
->expects($this->at(1))
->expects($this->exactly(2))
->method('download')
->with($databases['first']['url'], $databases['first']['path']);
->withConsecutive(
[$databases['second']['url'], $databases['second']['path']],
[$databases['first']['url'], $databases['first']['path']]
);

$command = new UpdateDatabaseCommand($this->downloader, $databases);
$command->run($this->input, $this->output);
Expand Down
Loading
Loading