diff --git a/.github/workflows/styles.yml b/.github/workflows/styles.yml index 88795fb..d4f3e60 100644 --- a/.github/workflows/styles.yml +++ b/.github/workflows/styles.yml @@ -12,10 +12,10 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.3' + php-version: '8.5' extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv tools: php-cs-fixer, cs2pr - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: composer install --prefer-dist - run: ./vendor/bin/php-cs-fixer fix --dry-run --format=checkstyle | cs2pr @@ -26,25 +26,12 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.3' + php-version: '8.5' extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: composer install --prefer-dist - run: ./vendor/bin/phpmd ./ text ./phpmd.xml --suffixes php,inc,test --exclude vendor,bin,tests - phpcpd: - name: phpcpd - runs-on: ubuntu-latest - steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv - - uses: actions/checkout@v2 - - run: composer install --prefer-dist - - run: ./vendor/bin/phpcpd ./ --suffix .php --suffix .inc --suffix .test --exclude vendor --exclude bin --exclude tests - phpstan: name: phpstan runs-on: ubuntu-latest @@ -52,10 +39,10 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.3' + php-version: '8.5' extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv tools: phpstan, cs2pr - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: composer install --prefer-dist - run: ./vendor/bin/phpstan analyse ./src ./tests --error-format=checkstyle | cs2pr @@ -66,9 +53,9 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.3' + php-version: '8.5' extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: composer install --prefer-dist - run: ./vendor/bin/psalm --output-format=github @@ -80,6 +67,6 @@ jobs: uses: shivammathur/setup-php@v2 with: tools: composer:v2 - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: composer install --prefer-dist - uses: symfonycorp/security-checker-action@v3 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 546204c..213fe70 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] + php-versions: ['8.3', '8.4', '8.5'] steps: - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 02859bb..f1346fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- add tests coverage for PHP 8.5 +- upgrade vimeo/psalm (4.30.0 = => 6.15.1) + +### Removed +- removed support PHP 8.0 +- removed support PHP 8.1 +- removed support PHP 8.2 +- remove phpcpd as abandoned +- remove unused php-mock/php-mock-phpunit + +### Security +- upgrade phpstan/phpstan (0.12.100 => 2.1.39) +- upgrade phpunit/php-code-coverage (9.2.32 => 12.5.3) +- upgrade phpunit/phpunit (9.6.34 => 12.5.14) + +### Changed +- remove deprecated usage of ReflectionProperty::setAccessible since PHP8.1 ## [1.0.2] - 2025-06-03 ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 61ff265..94b38ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,6 +13,22 @@ Pull requests for bugs are more than welcome - please explain the bug you're try ## Developing +## 🧪 Running tests + +Run the test suite without code coverage (no Xdebug required): + +```bash +./vendor/bin/phpunit --no-coverage +``` + +Run the test suite with code coverage (requires [Xdebug](https://xdebug.org/) or [PCOV](https://github.com/krakjoe/pcov)): + +```bash +XDEBUG_MODE=coverage ./vendor/bin/phpunit +``` + +> **Note:** Running `./vendor/bin/phpunit` without `--no-coverage` and without a coverage driver will fail with _"No code coverage driver available"_. Use `--no-coverage` for day-to-day local development. + ## 🚔 Check Symfony 4 coding standards & best practices You need to run composer before using [FriendsOfPHP/PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer). @@ -37,7 +53,7 @@ It can modernize your code (like converting the pow function to the ** operator ./vendor/bin/phpstan analyse ./ --error-format=checkstyle ``` -### Improve global code quality using PHPCPD (Code duplication) & PHPMD (PHP Mess Detector) +### Improve global code quality using PHPMD (PHP Mess Detector) Detect overcomplicated expressions & Unused parameters, methods, properties @@ -45,12 +61,6 @@ Detect overcomplicated expressions & Unused parameters, methods, properties ./vendor/bin/phpmd ./ text ./phpmd.xml --suffixes php,inc,test --exclude vendor,bin,tests ``` -Copy/Paste Detector - -```bash -./vendor/bin/phpcpd ./ --names=*.php,*.inc,*.test --names-exclude=*.md --ansi --exclude=vendor --exclude=bin --exclude=tests -``` - ### Checks compatibility with PHP interpreter versions ```bash diff --git a/README.md b/README.md index 63c6e8c..4358818 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Convert World Coordinates to Swiss Coordinates - and vice versa [![Build](https://github.com/antistatique/swisstopo/actions/workflows/tests.yml/badge.svg)](https://github.com/antistatique/swisstopo/actions/workflows/tests.yml) [![Packagist](https://img.shields.io/packagist/dt/antistatique/swisstopo.svg?maxAge=2592000)](https://packagist.org/packages/antistatique/swisstopo) [![License](https://poser.pugx.org/antistatique/swisstopo/license)](https://packagist.org/packages/antistatique/swisstopo) -[![PHP Versions Supported](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg)](https://packagist.org/packages/antistatique/swisstopo) +[![PHP Versions Supported](https://img.shields.io/badge/php-%3E%3D%208.3-8892BF.svg)](https://packagist.org/packages/antistatique/swisstopo) Super-simple PHP library to transpose GPS (WGS84) coordinates to/from the Swiss military and civilian coordinate systems CH1903/LV03 (MN03) or CH1995/LV95 (MN95). diff --git a/bin/post-commit b/bin/post-commit index 295c0b5..3d58d06 100644 --- a/bin/post-commit +++ b/bin/post-commit @@ -4,9 +4,6 @@ echo "\n🚔 \033[0;32mRunning Code Sniffer Symfony for /public ...\033[0m" echo "\n💩 \033[0;32mRunning PHP Mess Detector ...\033[0m" ./vendor/bin/phpmd ./ text ./phpmd.xml --suffixes php,inc,test --exclude vendor,bin,tests -echo "\n🛂 \033[0;32mRunning PHP Copy/Paste Detector ...\033[0m" -./vendor/bin/phpcpd ./ --names=*.php,*.inc,*.test --names-exclude=*.md --ansi --exclude=vendor --exclude=bin --exclude=tests - echo "\n🍫 \033[0;32mRunning PhpCodeFixer ...\033[0m" ./vendor/bin/phpcf --target 7.3 --file-extensions php,inc,test ./ diff --git a/composer.json b/composer.json index e2b3578..064745b 100644 --- a/composer.json +++ b/composer.json @@ -3,18 +3,16 @@ "description": "Convert GPS (WGS84) to Swiss (LV03 and LV95) coordinates (and vice versa)", "license": "MIT", "require": { - "php": ">=8.0" + "php": ">=8.3" }, "require-dev": { - "phpunit/phpunit": "^9.0.0", - "phpunit/php-code-coverage": "^9.2.0", + "phpunit/phpunit": "^12", + "phpunit/php-code-coverage": "^12", "friendsofphp/php-cs-fixer": "^3.21", "phpmd/phpmd": "^2.8", - "sebastian/phpcpd": "^6.0", "php-coveralls/php-coveralls": "^2.1", - "php-mock/php-mock-phpunit": "^2.4", - "vimeo/psalm": "^4.29", - "phpstan/phpstan-deprecation-rules": "^0.12.2" + "vimeo/psalm": "^6.0", + "phpstan/phpstan-deprecation-rules": "^2.0" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index 8a564d7..ec8f57a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ parameters: # Ignore tests - excludes_analyse: + excludePaths: - *Test.php - *TestBase.php # PHPStan Level 1 diff --git a/phpunit.xml b/phpunit.xml index 42e3057..8c54f75 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,23 +1,28 @@ - - + + + + ./tests/ + ./tests/Traits/ + + + src + + - - - ./tests/ - - - - - - - - diff --git a/psalm.xml b/psalm.xml index d1c0af3..035b5bf 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,28 +1,18 @@ - + xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" +> - + - - - - - - - - - - - diff --git a/src/SwisstopoConverter.php b/src/SwisstopoConverter.php index 1952ef5..8ca34eb 100644 --- a/src/SwisstopoConverter.php +++ b/src/SwisstopoConverter.php @@ -1,9 +1,13 @@ > * The collection of input and expected converted value */ - public function decimalDegreesToSexagesimalProvider() + public static function decimalDegreesToSexagesimalProvider(): iterable { - return [ - [12.76389, 12.4550004], - ]; + yield [12.76389, 12.4550004]; } - /** - * @covers ::degToSec - * - * @dataProvider decimalDegreesToSecondsOfArcProvider - * - * @throws \ReflectionException - */ + #[DataProvider('decimalDegreesToSecondsOfArcProvider')] public function testDegToSec($degrees, $expected): void { $swiss_converter = new SwisstopoConverter(); @@ -57,17 +51,15 @@ public function testDegToSec($degrees, $expected): void /** * Collection of Decimal Degrees notation converted to Seconds of Arc. * - * @return array + * @return iterable> * The collection of input and expected converted value */ - public function decimalDegreesToSecondsOfArcProvider() + public static function decimalDegreesToSecondsOfArcProvider(): iterable { - return [ - [1, 3600], - [1.24, 5040], - [360, 1.296e+6], - [-12, -43200], - ['1.24', 5040], - ]; + yield [1, 3600]; + yield [1.24, 5040]; + yield [360, 1.296e+6]; + yield [-12, -43200]; + yield ['1.24', 5040]; } } diff --git a/tests/SwisstopoConverterWGSToMN03Tests.php b/tests/SwisstopoConverterWGSToMN03Tests.php index 94ffc26..49e2f86 100644 --- a/tests/SwisstopoConverterWGSToMN03Tests.php +++ b/tests/SwisstopoConverterWGSToMN03Tests.php @@ -1,21 +1,29 @@ assertEqualsWithDelta(6.8486736590762, $coordinates['long'], 0.0001); } - /** - * @covers ::fromWGSToMN03 - */ public function testFromWGSToMN03(): void { $swiss_converter = new SwisstopoConverter(); @@ -37,11 +42,6 @@ public function testFromWGSToMN03(): void ], $coordinates); } - /** - * @covers ::fromMN03ToWGSLatitude - * - * @throws \ReflectionException - */ public function testFromMN03ToWGSLatitude(): void { $swiss_converter = new SwisstopoConverter(); @@ -49,11 +49,6 @@ public function testFromMN03ToWGSLatitude(): void $this->assertEqualsWithDelta(46.462057617639, $latitude, 0.0001); } - /** - * @covers ::fromMN03ToWGSLongitude - * - * @throws \ReflectionException - */ public function testFromMN03ToWGSLongitude(): void { $swiss_converter = new SwisstopoConverter(); @@ -61,11 +56,6 @@ public function testFromMN03ToWGSLongitude(): void $this->assertEqualsWithDelta(6.8486736590762, $longitude, 0.0001); } - /** - * @covers ::fromWGSToMN03x - * - * @throws \ReflectionException - */ public function testFromWGSToMN03x(): void { $swiss_converter = new SwisstopoConverter(); @@ -73,11 +63,6 @@ public function testFromWGSToMN03x(): void $this->assertEquals(145807.4339423232, $x); } - /** - * @covers ::fromWGSToMN03y - * - * @throws \ReflectionException - */ public function testFromWGSToMN03y(): void { $swiss_converter = new SwisstopoConverter(); diff --git a/tests/SwisstopoConverterWGSToMN95Tests.php b/tests/SwisstopoConverterWGSToMN95Tests.php index d24bb17..90489a4 100644 --- a/tests/SwisstopoConverterWGSToMN95Tests.php +++ b/tests/SwisstopoConverterWGSToMN95Tests.php @@ -1,21 +1,29 @@ assertEqualsWithDelta(6.8534397262208, $coordinates['long'], 0.0001); } - /** - * @covers ::fromWGSToMN95 - */ public function testFromWGSToMN95(): void { $swiss_converter = new SwisstopoConverter(); @@ -37,11 +42,6 @@ public function testFromWGSToMN95(): void ], $coordinates); } - /** - * @covers ::fromWGSToMN95East - * - * @throws \ReflectionException - */ public function testFromWGSToMN95East(): void { $swiss_converter = new SwisstopoConverter(); @@ -50,11 +50,6 @@ public function testFromWGSToMN95East(): void $this->assertEquals(2555047, round($east)); } - /** - * @covers ::fromWGSToMN95North - * - * @throws \ReflectionException - */ public function testFomWGSToMN95North(): void { $swiss_converter = new SwisstopoConverter(); @@ -63,11 +58,6 @@ public function testFomWGSToMN95North(): void $this->assertEquals(1145923, round($north)); } - /** - * @covers ::fromMN95ToWGSLatitude - * - * @throws \ReflectionException - */ public function testFromMN95ToWGSLatitude(): void { $swiss_converter = new SwisstopoConverter(); @@ -75,11 +65,6 @@ public function testFromMN95ToWGSLatitude(): void $this->assertEqualsWithDelta(46.463125794982, $latitude, 0.0001); } - /** - * @covers ::fromMN95ToWGSLongitude - * - * @throws \ReflectionException - */ public function testFromMN95ToWGSLongitude(): void { $swiss_converter = new SwisstopoConverter(); diff --git a/tests/Traits/InvokeMethodTrait.php b/tests/Traits/InvokeMethodTrait.php index 4661e87..7e3ab38 100644 --- a/tests/Traits/InvokeMethodTrait.php +++ b/tests/Traits/InvokeMethodTrait.php @@ -1,5 +1,7 @@ $parameters * * @throws \ReflectionException */ - protected function invokeMethod(&$object, $method_name, array $parameters = [], array $protected_properties = []) + protected function invokeMethod(object $object, string $methodName, array $parameters = []): mixed { - $reflection = new \ReflectionClass(\get_class($object)); - - foreach ($protected_properties as $property => $value) { - $property = $reflection->getProperty($property); - $property->setAccessible(true); - $property->setValue($object, $value); - } - - $method = $reflection->getMethod($method_name); - $method->setAccessible(true); + $method = new \ReflectionMethod($object, $methodName); return $method->invokeArgs($object, $parameters); }