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

Raise minimum PHP version to ^8.1 and refactor code #76

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions .github/workflows/bc.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
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
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
['8.1']
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -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']
3 changes: 2 additions & 1 deletion .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -30,4 +31,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1', '8.2']
['8.1', '8.2', '8.3']
3 changes: 2 additions & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -26,6 +27,6 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.1']
['8.3']
secrets:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
7 changes: 5 additions & 2 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
on:
pull_request:
pull_request_target:
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -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']
3 changes: 2 additions & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'phpunit.xml.dist'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -28,4 +29,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1', '8.2', '8.3']
['8.1', '8.2', '8.3']
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"psr/container": "^1.0|^2.0",
"yiisoft/event-dispatcher": "^1.0",
"yiisoft/friendly-exception": "^1.0",
"yiisoft/injector": "^1.0"
},
"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"
Expand Down
26 changes: 14 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="false"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
executionOrder="random"
failOnRisky="true"
failOnWarning="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
executionOrder="random"
resolveDependencies="true">
colors="true"
displayDetailsOnPhpunitDeprecations="true"
>
<php>
<ini name="error_reporting" value="-1"/>
</php>
Expand All @@ -21,9 +23,9 @@
</testsuite>
</testsuites>

<coverage>
<source>
<include>
<directory>./src</directory>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>
</phpunit>
6 changes: 5 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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',
],
]);
};
2 changes: 1 addition & 1 deletion src/CallableFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
final class CallableFactory
{
public function __construct(
private ContainerInterface $container
private readonly ContainerInterface $container
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/ListenerCollectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
final class ListenerCollectionFactory
{
public function __construct(
private Injector $injector,
private CallableFactory $callableFactory,
private readonly Injector $injector,
private readonly CallableFactory $callableFactory,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/ListenerConfigurationChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
final class ListenerConfigurationChecker
{
public function __construct(
private CallableFactory $callableFactory,
private readonly CallableFactory $callableFactory,
) {
}

Expand Down Expand Up @@ -60,7 +60,7 @@
}
} catch (ContainerExceptionInterface $exception) {
throw new InvalidListenerConfigurationException(
'Could not instantiate event listener or listener class has invalid configuration. Got ' .

Check warning on line 63 in src/ListenerConfigurationChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ throw new InvalidListenerConfigurationException($this->createNotCallableMessage($listener)); } } catch (ContainerExceptionInterface $exception) { - throw new InvalidListenerConfigurationException('Could not instantiate event listener or listener class has invalid configuration. Got ' . $this->listenerDump($listener) . '.', 0, $exception); + throw new InvalidListenerConfigurationException('Could not instantiate event listener or listener class has invalid configuration. Got ' . $this->listenerDump($listener), 0, $exception); } } }
$this->listenerDump($listener) . '.',
0,
$exception
Expand Down Expand Up @@ -106,7 +106,7 @@
}
}

return 'Listener must be a callable. Got ' . $this->listenerDump($definition) . '.';

Check warning on line 109 in src/ListenerConfigurationChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ return sprintf('"%s" method is not defined in "%s" class.', $definition[1], $definition[0]::class); } } - return 'Listener must be a callable. Got ' . $this->listenerDump($definition) . '.'; + return 'Listener must be a callable. Got ' . $this->listenerDump($definition); } /** * @throws ContainerExceptionInterface Error while retrieving the entry from container.
}

/**
Expand Down
25 changes: 9 additions & 16 deletions tests/CallableFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +19,7 @@

class CallableFactoryTest extends TestCase
{
public function dataArray(): array
public static function dataArray(): array
{
return [
'base' => [[Event::class, 'register']],
Expand All @@ -27,27 +28,23 @@ public function dataArray(): array
];
}

/**
* @dataProvider dataArray
*/
#[DataProvider('dataArray')]
public function testArray($definition): void
{
self::assertIsArray(
$this->createFactory()->create($definition),
);
}

public function dataInvokableObject(): array
public static function dataInvokableObject(): array
{
return [
'base' => [new HandlerInvokable()],
'instantiate' => [HandlerInvokable::class],
];
}

/**
* @dataProvider dataInvokableObject
*/
#[DataProvider('dataInvokableObject')]
public function testInvokableObject($definition): void
{
self::assertInstanceOf(
Expand All @@ -56,7 +53,7 @@ public function testInvokableObject($definition): void
);
}

public function dataClosure(): array
public static function dataClosure(): array
{
return [
'closure' => [
Expand All @@ -67,9 +64,7 @@ static function () {
];
}

/**
* @dataProvider dataClosure
*/
#[DataProvider('dataClosure')]
public function testClosure($definition): void
{
self::assertInstanceOf(
Expand All @@ -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']],
Expand All @@ -94,9 +89,7 @@ public function dataException(): array
];
}

/**
* @dataProvider dataException
*/
#[DataProvider('dataException')]
public function testException($definition): void
{
$this->expectException(InvalidListenerConfigurationException::class);
Expand Down
2 changes: 1 addition & 1 deletion tests/EventConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading