From 53c2f3bf26cbe61c11ed6e8ba991f253daaf2ae2 Mon Sep 17 00:00:00 2001 From: Filis Futsarov Date: Fri, 21 Mar 2025 20:10:19 +0100 Subject: [PATCH] php8.4 support among other improvements --- .gitattributes | 15 ++++++------ .github/workflows/main.yaml | 47 +++++++++++++++++-------------------- .gitignore | 3 +++ .php-cs-fixer.php | 11 +++++++++ .phpstan.neon | 8 +++++++ CHANGELOG.md | 5 ++++ LICENSE | 2 +- composer.json | 29 +++++++++++++---------- phpcs.xml | 16 +++++++++++++ phpunit.xml | 33 ++++++++++++++++++++++++++ tests/GeolocationTest.php | 25 +++++++++++++------- 11 files changed, 140 insertions(+), 54 deletions(-) create mode 100644 .php-cs-fixer.php create mode 100644 .phpstan.neon create mode 100644 phpcs.xml create mode 100644 phpunit.xml diff --git a/.gitattributes b/.gitattributes index 2d48476..b67c7ca 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,10 @@ * text=auto eol=lf -/tests export-ignore -.editorconfig export-ignore -.gitattributes export-ignore -.gitignore export-ignore -.travis.yml export-ignore -phpunit.xml export-ignore -phpcs.xml export-ignore +/tests export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.php-cs-fixer.php export-ignore +phpcs.xml.dist export-ignore +phpunit.xml.dist export-ignore +.phpstan.neon export-ignore diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 327717c..5d14a59 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,10 +1,10 @@ name: "testing" on: - push: - branches: [ master ] - pull_request: - branches: [ master ] + push: + branches: [ master ] + pull_request: + branches: [ master ] jobs: qa: @@ -13,19 +13,19 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Validate composer.json and composer.lock run: composer validate - name: Cache Composer packages id: composer-cache - uses: actions/cache@v2 + uses: actions/cache@v4 with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' @@ -40,19 +40,19 @@ jobs: strategy: matrix: - php: - - 7.2 - - 7.3 - - 7.4 - composer-args: [ "" ] - include: - - php: 8.0 - composer-args: --ignore-platform-reqs - fail-fast: false + php: + - 7.2 + - 7.3 + - 7.4 + - 8.0 + - 8.1 + - 8.2 + - 8.3 + - 8.4 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -60,17 +60,14 @@ jobs: php-version: ${{ matrix.php }} - name: Cache PHP dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: vendor key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer- - name: Install dependencies - run: composer install --prefer-dist --no-progress ${{ matrix.composer-args }} + run: composer install --prefer-dist --no-progress - name: Tests run: composer test - - - name: Tests coverage - run: composer coverage diff --git a/.gitignore b/.gitignore index d0ec629..6ee8bf3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ composer.lock .php_cs.cache coverage .phpunit.result.cache +.idea +kit +*.cache diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..c061a01 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,11 @@ +setFinder( + PhpCsFixer\Finder::create() + ->files() + ->name('*.php') + ->in(__DIR__.'/src') + ->in(__DIR__.'/tests') + ); diff --git a/.phpstan.neon b/.phpstan.neon new file mode 100644 index 0000000..f5ff233 --- /dev/null +++ b/.phpstan.neon @@ -0,0 +1,8 @@ +parameters: + #treatPhpDocTypesAsCertain: false + reportUnmatchedIgnoredErrors: false + inferPrivatePropertyTypeFromConstructor: true + level: 8 + paths: + - src + - tests \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e96dc45..4da496e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [3.1.0] - 2025-03-21 +### Added +- Support for PHP 8.4 + ## [3.0.0] - 2020-12-04 ### Added - Support for PHP 8 @@ -60,6 +64,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## 0.1.0 - 2016-10-10 First version +[3.1.0]: https://github.com/middlewares/geolocation/compare/v3.0.0...v3.1.0 [3.0.0]: https://github.com/middlewares/geolocation/compare/v2.0.0...v3.0.0 [2.0.0]: https://github.com/middlewares/geolocation/compare/v1.0.0...v2.0.0 [1.0.0]: https://github.com/middlewares/geolocation/compare/v0.5.0...v1.0.0 diff --git a/LICENSE b/LICENSE index d46d39c..306ec99 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018 +Copyright (c) 2018-2025 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index d2a830c..2e604f2 100644 --- a/composer.json +++ b/composer.json @@ -19,20 +19,20 @@ }, "require": { "php": "^7.2 || ^8.0", - "willdurand/geocoder": "^4.0", - "php-http/message": "^1.6", - "psr/http-server-middleware": "^1.0" + "willdurand/geocoder": "^4", + "php-http/message": "^1", + "psr/http-server-middleware": "^1" }, "require-dev": { - "phpunit/phpunit": "^8|^9", - "friendsofphp/php-cs-fixer": "^2.0", - "squizlabs/php_codesniffer": "^3.0", - "middlewares/utils": "^2.1", - "eloquent/phony-phpunit": "^6.0|^7.0", - "php-http/guzzle6-adapter": "^1.1", - "geocoder-php/free-geoip-provider": "^4.1", - "phpstan/phpstan": "^0.12", - "laminas/laminas-diactoros": "^2.3" + "phpunit/phpunit": "^8 || ^9", + "friendsofphp/php-cs-fixer": "^3", + "squizlabs/php_codesniffer": "^3", + "middlewares/utils": "^2 || ^3 || ^4", + "php-http/guzzle7-adapter": "^1", + "geocoder-php/free-geoip-provider": "^4", + "phpstan/phpstan": "^1 || ^2", + "laminas/laminas-diactoros": "^2 || ^3", + "oscarotero/php-cs-fixer-config": "^2" }, "autoload": { "psr-4": { @@ -51,5 +51,10 @@ "test": "phpunit", "coverage": "phpunit --coverage-text", "coverage-html": "phpunit --coverage-html=coverage" + }, + "config": { + "allow-plugins": { + "php-http/discovery": false + } } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..7814331 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,16 @@ + + + Middlewares coding standard + + + + + + + + + + + src + tests + diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..003bf67 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,33 @@ + + + + + tests + + + + + + ./src + + ./tests + ./vendor + + + + diff --git a/tests/GeolocationTest.php b/tests/GeolocationTest.php index 0a2eca1..16c3db0 100644 --- a/tests/GeolocationTest.php +++ b/tests/GeolocationTest.php @@ -3,11 +3,11 @@ namespace Middlewares\Tests; -use Eloquent\Phony\Phpunit\Phony; +use Geocoder\Collection; use Geocoder\Model\Address; use Geocoder\Model\AddressCollection; use Geocoder\Provider\FreeGeoIp\FreeGeoIp; -use Http\Adapter\Guzzle6\Client; +use Http\Adapter\Guzzle7\Client; use Middlewares\Geolocation; use Middlewares\Utils\Dispatcher; use Middlewares\Utils\Factory; @@ -15,17 +15,24 @@ class GeolocationTest extends TestCase { + /** + * @return Geolocation + */ private static function getMiddleware() { - $container = Phony::partialMock(Geolocation::class, [new FreeGeoIp(new Client())]); - $container->getAddress->with('123.9.34.23')->returns(new AddressCollection([ - Address::createFromArray(['country' => 'China']), - ])); + return new class(new FreeGeoIp(new Client())) extends Geolocation { + protected function getAddress(string $ip): Collection + { + assert($ip, '123.9.34.23'); - return $container->get(); + return new AddressCollection([ + Address::createFromArray(['country' => 'China']), + ]); + } + }; } - public function testGeolocation() + public function testGeolocation(): void { $response = Dispatcher::run( [ @@ -40,7 +47,7 @@ function ($request) { $this->assertEquals('China', (string) $response->getBody()); } - public function testAttribute() + public function testAttribute(): void { $geocoder = new FreeGeoIp(new Client(), 'http://freegeoip.net/json/%s');