From 4d582063f94589376ef43b216bf9b3ca1dd527bf Mon Sep 17 00:00:00 2001 From: Martijn Gastkemper Date: Thu, 23 Jan 2025 09:36:06 +0100 Subject: [PATCH] Upgrade PHPUnit PHPUnit 9.5 reports deprecations when running on PHP 8.4 --- .github/workflows/phpunit.yml | 26 +++++++++++++++----------- .gitignore | 2 ++ composer.json | 4 ++-- phpstan-baseline.neon | 10 +++++----- phpunit-8.xml | 18 ++++++++++++++++++ phpunit.xml | 12 ++++++------ tests/ContainsTest.php | 2 +- tests/IsAssocTest.php | 2 +- tests/PropTest.php | 3 +-- tests/RenameKeysTest.php | 2 +- 10 files changed, 52 insertions(+), 29 deletions(-) create mode 100644 phpunit-8.xml diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 0917e49..ffee4c5 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -13,6 +13,16 @@ jobs: matrix: php: [7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, nightly] stability: [--prefer-lowest, --prefer-stable] + include: + - php: 7.2 + phpunit: ^8 + phpunit-config: phpunit-8.xml + - php: 7.3 + phpunit: ^9 + - php: 7.4 + phpunit: ^9 + - php: 8.0 + phpunit: ^9 steps: - uses: actions/checkout@v4 @@ -33,15 +43,9 @@ jobs: key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - - name: Install PHPUnit 7 - id: phpunit-7 - if: ${{ matrix.php == '7.2' }} - run: composer require phpunit/phpunit:^7 --no-interaction --no-update + - name: Install PHPUnit ${{ matrix.phpunit || '^10.5' }} and the other dependencies + run: | + composer require --dev phpunit/phpunit:${{ matrix.phpunit || '^10.5' }} --no-interaction --no-update + composer update ${{ matrix.stability }} --prefer-dist --no-interaction - - name: Install PHPUnit 9 - if: ${{ steps.phpunit-7.outcome == 'skipped' }} - run: composer require phpunit/phpunit:^9.5 --no-interaction --no-update - - - run: composer update ${{ matrix.stability }} --prefer-dist --no-interaction - - - run: ./vendor/bin/phpunit + - run: ./vendor/bin/phpunit --configuration ${{ matrix.phpunit-config || 'phpunit.xml' }} diff --git a/.gitignore b/.gitignore index e0c6366..3cb9ac5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /vendor/ .DS_Store +.phpunit.result.cache +.phpunit.cache composer.lock diff --git a/composer.json b/composer.json index 4535bcb..3827192 100644 --- a/composer.json +++ b/composer.json @@ -3,9 +3,9 @@ "description": "Utility library embracing functional programming paradigms.", "type": "library", "require-dev": { - "phpunit/phpunit": "^7.0 | ^9.5", "squizlabs/php_codesniffer": "^3.5", - "phpstan/phpstan": "^1.10" + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.5" }, "license": "BSD-3-Clause", "authors": [ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 560bf57..013be82 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -526,27 +526,27 @@ parameters: path: tests/PropTest.php - - message: "#^Method class@anonymous/tests/PropTest\\.php\\:79\\:\\:__get\\(\\) has no return type specified\\.$#" + message: "#^Method class@anonymous/tests/PropTest\\.php\\:78\\:\\:__get\\(\\) has no return type specified\\.$#" count: 1 path: tests/PropTest.php - - message: "#^Method class@anonymous/tests/PropTest\\.php\\:79\\:\\:__get\\(\\) has parameter \\$prop with no type specified\\.$#" + message: "#^Method class@anonymous/tests/PropTest\\.php\\:78\\:\\:__get\\(\\) has parameter \\$prop with no type specified\\.$#" count: 1 path: tests/PropTest.php - - message: "#^Method class@anonymous/tests/PropTest\\.php\\:79\\:\\:__isset\\(\\) has parameter \\$prop with no type specified\\.$#" + message: "#^Method class@anonymous/tests/PropTest\\.php\\:78\\:\\:__isset\\(\\) has parameter \\$prop with no type specified\\.$#" count: 1 path: tests/PropTest.php - - message: "#^Property class@anonymous/tests/PropTest\\.php\\:79\\:\\:\\$_data has no type specified\\.$#" + message: "#^Property class@anonymous/tests/PropTest\\.php\\:78\\:\\:\\$_data has no type specified\\.$#" count: 1 path: tests/PropTest.php - - message: "#^Property class@anonymous/tests/PropTest\\.php\\:91\\:\\:\\$_data has no type specified\\.$#" + message: "#^Property class@anonymous/tests/PropTest\\.php\\:90\\:\\:\\$_data has no type specified\\.$#" count: 1 path: tests/PropTest.php diff --git a/phpunit-8.xml b/phpunit-8.xml new file mode 100644 index 0000000..4e0647c --- /dev/null +++ b/phpunit-8.xml @@ -0,0 +1,18 @@ + + + + + library/Garp/Functional + + + + + tests/ + + + + + + + + diff --git a/phpunit.xml b/phpunit.xml index 4e0647c..85c5d0c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,10 +1,5 @@ - - - - library/Garp/Functional - - + tests/ @@ -15,4 +10,9 @@ + + + library/Garp/Functional + + diff --git a/tests/ContainsTest.php b/tests/ContainsTest.php index 0bc69df..b838cd5 100644 --- a/tests/ContainsTest.php +++ b/tests/ContainsTest.php @@ -67,7 +67,7 @@ public function test_should_be_curried(): void { $this->assertTrue($containsHello(array('hello', 'world'))); } - public function invalidCollections(): array { + public static function invalidCollections(): array { return array( array(100), array(new stdClass()), diff --git a/tests/IsAssocTest.php b/tests/IsAssocTest.php index 4a13f16..78bd22e 100644 --- a/tests/IsAssocTest.php +++ b/tests/IsAssocTest.php @@ -19,7 +19,7 @@ public function test_should_recognize_associative_arrays($input, bool $result) { $this->assertSame($result, f\is_assoc($input)); } - public function arrayProvider(): array { + public static function arrayProvider(): array { return [ [ [1, 2, 3], diff --git a/tests/PropTest.php b/tests/PropTest.php index 04ddb4a..ba659bf 100644 --- a/tests/PropTest.php +++ b/tests/PropTest.php @@ -2,7 +2,6 @@ use Garp\Functional\Tests\Helpers\MockSpiceTraverser; use PHPUnit\Framework\TestCase; use Garp\Functional as f; -use Carbon\Carbon; /** * @package Garp\Functional @@ -75,7 +74,7 @@ public function test_should_read_magic_prop($result, $prop, $obj) { ); } - public function magicDataProvider(): array { + public static function magicDataProvider(): array { $obj = new class { protected $_data = [ 'bar' => '12345' diff --git a/tests/RenameKeysTest.php b/tests/RenameKeysTest.php index 323da18..d67ab9b 100644 --- a/tests/RenameKeysTest.php +++ b/tests/RenameKeysTest.php @@ -106,7 +106,7 @@ public function test_should_throw_on_invalid_arguments($arg): void { f\rename_keys($arg, []); } - public function invalidArgumentProvider(): array { + public static function invalidArgumentProvider(): array { return array( array(new stdClass), array(true),