diff --git a/.github/workflows/bc.yml b/.github/workflows/bc.yml index 9127600..00041a9 100644 --- a/.github/workflows/bc.yml +++ b/.github/workflows/bc.yml @@ -1,8 +1,28 @@ on: - - pull_request - - push + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + - 'psalm.xml' + push: + branches: ['master'] + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + - 'psalm.xml' name: backwards compatibility + jobs: roave_bc_check: uses: yiisoft/actions/.github/workflows/bc.yml@master @@ -10,4 +30,4 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.0'] + ['8.1'] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ed9a60b..05e7b40 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,7 @@ on: - 'psalm.xml' push: + branches: ['master'] paths-ignore: - 'docs/**' - 'README.md' @@ -24,8 +25,10 @@ name: build jobs: phpunit: uses: yiisoft/actions/.github/workflows/phpunit.yml@master + secrets: + codecovToken: ${{ secrets.CODECOV_TOKEN }} with: os: >- ['ubuntu-latest', 'windows-latest'] php: >- - ['8.0', '8.1', '8.2'] + ['8.1', '8.2', '8.3'] diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 6cf3cef..a857bce 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -11,6 +11,7 @@ on: - 'psalm.xml' push: + branches: ['master'] paths-ignore: - 'docs/**' - 'README.md' @@ -30,4 +31,4 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.0', '8.1', '8.2'] + ['8.1', '8.2', '8.3'] diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index c1aca98..a6873e2 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -9,6 +9,7 @@ on: - 'psalm.xml' push: + branches: ['master'] paths-ignore: - 'docs/**' - 'README.md' @@ -26,6 +27,6 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.1'] + ['8.3'] secrets: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index adacd73..457772a 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -1,5 +1,5 @@ on: - pull_request: + pull_request_target: paths-ignore: - 'docs/**' - 'README.md' @@ -14,8 +14,11 @@ name: rector jobs: rector: uses: yiisoft/actions/.github/workflows/rector.yml@master + secrets: + token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} with: + repository: ${{ github.event.pull_request.head.repo.full_name }} os: >- ['ubuntu-latest'] php: >- - ['8.0'] + ['8.3'] diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index b7d3200..e33eca8 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -10,6 +10,7 @@ on: - 'phpunit.xml.dist' push: + branches: ['master'] paths-ignore: - 'docs/**' - 'README.md' @@ -28,4 +29,4 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.0', '8.1', '8.2', '8.3'] + ['8.1', '8.2', '8.3'] diff --git a/.gitignore b/.gitignore index 18a33d4..e7e07ca 100644 --- a/.gitignore +++ b/.gitignore @@ -23,12 +23,10 @@ composer.phar # Mac DS_Store Files .DS_Store -# phpunit itself is not needed -phpunit.phar -# local phpunit config +# PhpUnit +/phpunit.phar /phpunit.xml -# phpunit cache -.phpunit.result.cache +/.phpunit.cache # Phan analysis.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index e090bef..51f9d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2.1.1 under development - Enh #65: Minor refactoring of `CallableFactory` and `ListenerCollectionFactory` (@vjik) +- Enh #76: Raise minimum PHP version to `^8.1` and refactor code (@vjik) ## 2.1.0 November 04, 2023 diff --git a/README.md b/README.md index 1511817..b09bf83 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ All you need is to use any [PSR-11](https://www.php-fig.org/psr/psr-11/) compati ## Requirements -- PHP 8.0 or higher. +- PHP 8.1 or higher. ## Installation diff --git a/composer.json b/composer.json index fecf4f7..96d9d77 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "psr/container": "^1.0|^2.0", "yiisoft/event-dispatcher": "^1.0", "yiisoft/friendly-exception": "^1.0", @@ -35,11 +35,11 @@ }, "require-dev": { "maglnet/composer-require-checker": "^4.4", - "phpunit/phpunit": "^9.5", - "rector/rector": "^1.0.0", + "phpunit/phpunit": "^10.5", + "rector/rector": "^1.2", "roave/infection-static-analysis-plugin": "^1.16", "spatie/phpunit-watcher": "^1.23", - "vimeo/psalm": "^4.30|^5.21", + "vimeo/psalm": "^5.26", "yiisoft/config": "^1.3", "yiisoft/di": "^1.2", "yiisoft/test-support": "^3.0" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c3bda44..82324d1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,18 @@ - - + colors="true" + displayDetailsOnPhpunitDeprecations="true" +> @@ -21,9 +23,9 @@ - + - ./src + ./src - + diff --git a/rector.php b/rector.php index f471311..e7a0c09 100644 --- a/rector.php +++ b/rector.php @@ -6,6 +6,7 @@ use Rector\Config\RectorConfig; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Php80\Rector\Ternary\GetDebugTypeRector; +use Rector\Php81\Rector\Array_\FirstClassCallableRector; use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $rectorConfig): void { @@ -19,11 +20,14 @@ // define sets of rules $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_80, + LevelSetList::UP_TO_PHP_81, ]); $rectorConfig->skip([ ClosureToArrowFunctionRector::class, GetDebugTypeRector::class, + FirstClassCallableRector::class => [ + __DIR__ . '/tests/CallableFactoryTest.php', + ], ]); }; diff --git a/src/CallableFactory.php b/src/CallableFactory.php index f985dd5..2b32840 100644 --- a/src/CallableFactory.php +++ b/src/CallableFactory.php @@ -19,7 +19,7 @@ final class CallableFactory { public function __construct( - private ContainerInterface $container + private readonly ContainerInterface $container ) { } diff --git a/src/ListenerCollectionFactory.php b/src/ListenerCollectionFactory.php index be57e8a..d5db22e 100644 --- a/src/ListenerCollectionFactory.php +++ b/src/ListenerCollectionFactory.php @@ -12,8 +12,8 @@ final class ListenerCollectionFactory { public function __construct( - private Injector $injector, - private CallableFactory $callableFactory, + private readonly Injector $injector, + private readonly CallableFactory $callableFactory, ) { } diff --git a/src/ListenerConfigurationChecker.php b/src/ListenerConfigurationChecker.php index 70c79e9..b2a996f 100644 --- a/src/ListenerConfigurationChecker.php +++ b/src/ListenerConfigurationChecker.php @@ -20,7 +20,7 @@ final class ListenerConfigurationChecker { public function __construct( - private CallableFactory $callableFactory, + private readonly CallableFactory $callableFactory, ) { } diff --git a/tests/CallableFactoryTest.php b/tests/CallableFactoryTest.php index 62e38ab..d2ae768 100644 --- a/tests/CallableFactoryTest.php +++ b/tests/CallableFactoryTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\Yii\Event\Tests; use Closure; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use stdClass; @@ -18,7 +19,7 @@ class CallableFactoryTest extends TestCase { - public function dataArray(): array + public static function dataArray(): array { return [ 'base' => [[Event::class, 'register']], @@ -27,9 +28,7 @@ public function dataArray(): array ]; } - /** - * @dataProvider dataArray - */ + #[DataProvider('dataArray')] public function testArray($definition): void { self::assertIsArray( @@ -37,7 +36,7 @@ public function testArray($definition): void ); } - public function dataInvokableObject(): array + public static function dataInvokableObject(): array { return [ 'base' => [new HandlerInvokable()], @@ -45,9 +44,7 @@ public function dataInvokableObject(): array ]; } - /** - * @dataProvider dataInvokableObject - */ + #[DataProvider('dataInvokableObject')] public function testInvokableObject($definition): void { self::assertInstanceOf( @@ -56,7 +53,7 @@ public function testInvokableObject($definition): void ); } - public function dataClosure(): array + public static function dataClosure(): array { return [ 'closure' => [ @@ -67,9 +64,7 @@ static function () { ]; } - /** - * @dataProvider dataClosure - */ + #[DataProvider('dataClosure')] public function testClosure($definition): void { self::assertInstanceOf( @@ -78,7 +73,7 @@ public function testClosure($definition): void ); } - public function dataException(): array + public static function dataException(): array { return [ 'non-existent container definition' => [['test', 'register']], @@ -94,9 +89,7 @@ public function dataException(): array ]; } - /** - * @dataProvider dataException - */ + #[DataProvider('dataException')] public function testException($definition): void { $this->expectException(InvalidListenerConfigurationException::class); diff --git a/tests/EventConfiguratorTest.php b/tests/EventConfiguratorTest.php index 047269a..e53bcbe 100644 --- a/tests/EventConfiguratorTest.php +++ b/tests/EventConfiguratorTest.php @@ -98,7 +98,7 @@ private function getEventsConfig(): array Event::class => [ ['eventAlias', 'register'], [Event::class, 'register'], - [Handler::class, 'handleStatic'], + Handler::handleStatic(...), [new Event(), 'register'], static function (Event $event) { $event->register(new stdClass()); diff --git a/tests/ListenerConfigurationCheckerTest.php b/tests/ListenerConfigurationCheckerTest.php index 2f8ed47..6bca093 100644 --- a/tests/ListenerConfigurationCheckerTest.php +++ b/tests/ListenerConfigurationCheckerTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Yii\Event\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use stdClass; @@ -21,7 +22,7 @@ class ListenerConfigurationCheckerTest extends TestCase { - public function badCallableProvider(): array + public static function badCallableProvider(): array { return [ 'non-existent container definition' => [ @@ -75,9 +76,7 @@ public function badCallableProvider(): array ]; } - /** - * @dataProvider badCallableProvider - */ + #[DataProvider('badCallableProvider')] public function testBadCallable($callable, string $message): void { $this->expectException(InvalidListenerConfigurationException::class); @@ -87,11 +86,11 @@ public function testBadCallable($callable, string $message): void $this->createChecker()->check([Event::class => [$callable]]); } - public function goodCallableProvider(): array + public static function goodCallableProvider(): array { return [ 'array callable' => [[Event::class, 'register']], - 'array callable static' => [[Handler::class, 'handleStatic']], + 'array callable static' => [Handler::handleStatic(...)], 'array callable with object' => [[new Event(), 'register']], 'invokable object' => [new HandlerInvokable()], 'invokable object to instantiate' => [HandlerInvokable::class], @@ -103,11 +102,7 @@ static function () { ]; } - /** - * @dataProvider goodCallableProvider - * - * @param $callable - */ + #[DataProvider('goodCallableProvider')] public function testGoodCallable($callable): void { $checker = $this->createChecker();