From e51c62b786788e80707ba9ed5dfc2ffdec3b6742 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Fri, 13 Sep 2024 13:11:19 +0300
Subject: [PATCH 1/3] Fix readme badges (#373)
---
README.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index cdcaa046..5b188c53 100644
--- a/README.md
+++ b/README.md
@@ -6,9 +6,9 @@
-[![Latest Stable Version](https://poser.pugx.org/yiisoft/di/v/stable.png)](https://packagist.org/packages/yiisoft/di)
-[![Total Downloads](https://poser.pugx.org/yiisoft/di/downloads.png)](https://packagist.org/packages/yiisoft/di)
-[![Build status](https://github.com/yiisoft/di/workflows/build/badge.svg)](https://github.com/yiisoft/di/actions?query=workflow%3Abuild)
+[![Latest Stable Version](https://poser.pugx.org/yiisoft/di/v)](https://packagist.org/packages/yiisoft/di)
+[![Total Downloads](https://poser.pugx.org/yiisoft/di/downloads)](https://packagist.org/packages/yiisoft/di)
+[![Build status](https://github.com/yiisoft/di/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/di/actions/workflows/build.yml)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/di/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/di/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/di/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/di/?branch=master)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdi%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/di/master)
From e78378a357063c5153542c5a66c4adc594d5b3a8 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Fri, 13 Sep 2024 13:36:04 +0300
Subject: [PATCH 2/3] Remove scrutinizer (#374)
---
.gitattributes | 1 -
.scrutinizer.yml | 35 -----------------------------------
README.md | 3 +--
3 files changed, 1 insertion(+), 38 deletions(-)
delete mode 100644 .scrutinizer.yml
diff --git a/.gitattributes b/.gitattributes
index 5583f369..9f9e9af9 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -26,7 +26,6 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
-/.scrutinizer.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/docs export-ignore
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
deleted file mode 100644
index 61fb502d..00000000
--- a/.scrutinizer.yml
+++ /dev/null
@@ -1,35 +0,0 @@
-checks:
- php: true
-
-filter:
- paths:
- - src/
-
-build:
- image: default-bionic
-
- environment:
- php:
- version: 8.0.18
- ini:
- xdebug.mode: coverage
-
- nodes:
- analysis:
- tests:
- override:
- - php-scrutinizer-run
-
- phpunit:
- dependencies:
- override:
- - composer self-update
- - composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
-
- tests:
- override:
- - command: ./vendor/bin/phpunit --coverage-clover ./coverage.xml
- on_node: 1
- coverage:
- file: coverage.xml
- format: php-clover
diff --git a/README.md b/README.md
index 5b188c53..76e958c4 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,7 @@
[![Latest Stable Version](https://poser.pugx.org/yiisoft/di/v)](https://packagist.org/packages/yiisoft/di)
[![Total Downloads](https://poser.pugx.org/yiisoft/di/downloads)](https://packagist.org/packages/yiisoft/di)
[![Build status](https://github.com/yiisoft/di/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/di/actions/workflows/build.yml)
-[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/di/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/di/?branch=master)
-[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/di/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/di/?branch=master)
+[![Code coverage](https://codecov.io/gh/yiisoft/di/graph/badge.svg?token=P8W1UTwgQt)](https://codecov.io/gh/yiisoft/di)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdi%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/di/master)
[![static analysis](https://github.com/yiisoft/di/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/di/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yiisoft/di/coverage.svg)](https://shepherd.dev/github/yiisoft/di)
From 1ab3bedfbbcb53931d69eccac0c15ec2ceea4ad2 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev
Date: Fri, 13 Sep 2024 14:21:25 +0300
Subject: [PATCH 3/3] Raise minimum PHP version to `^8.1` and refactor code
(#375)
---
.github/workflows/bc.yml | 25 +++++++--
.github/workflows/bechmark.yml | 2 +-
.github/workflows/build.yml | 5 +-
.../workflows/composer-require-checker.yml | 3 +-
.github/workflows/mutation.yml | 3 +-
.github/workflows/rector.yml | 5 +-
.github/workflows/static.yml | 3 +-
.gitignore | 8 ++-
CHANGELOG.md | 3 +-
README.md | 2 +-
composer.json | 6 +--
phpunit.xml.dist | 25 +++++----
psalm.xml | 1 +
rector.php | 6 ++-
src/Container.php | 16 +-----
src/ExtensibleService.php | 7 +--
src/Helpers/DefinitionParser.php | 5 --
src/NotFoundException.php | 2 +-
src/StateResetter.php | 3 +-
tests/Support/Car.php | 6 ++-
tests/Support/ConstructorTestClass.php | 2 +-
tests/Support/EngineFactory.php | 2 +-
tests/Support/EngineStorage.php | 2 +-
tests/Support/Garage.php | 2 +-
tests/Support/GearBox.php | 2 +-
tests/Support/OptionalConcreteDependency.php | 2 +-
tests/Support/SportCar.php | 6 ++-
tests/Support/TreeItem.php | 2 +-
...nConstructorFirstTypeInParamResolvable.php | 2 +-
...ionTypeInConstructorParamNotResolvable.php | 2 +-
...ConstructorSecondTypeInParamResolvable.php | 2 +-
tests/Support/VariadicConstructor.php | 9 ++--
.../CompositePsrContainerOverLeagueTest.php | 2 +-
.../CompositePsrContainerOverYiisoftTest.php | 2 +-
... => CompositePsrContainerTestAbstract.php} | 6 +--
tests/Unit/ContainerTest.php | 53 ++++++-------------
tests/Unit/LeaguePsrContainerTest.php | 2 +-
...rTest.php => PsrContainerTestAbstract.php} | 2 +-
tests/Unit/Reference/TagReferenceTest.php | 4 --
tests/Unit/YiisoftPsrContainerTest.php | 2 +-
40 files changed, 117 insertions(+), 127 deletions(-)
rename tests/Unit/{AbstractCompositePsrContainerTest.php => CompositePsrContainerTestAbstract.php} (96%)
rename tests/Unit/{AbstractPsrContainerTest.php => PsrContainerTestAbstract.php} (97%)
diff --git a/.github/workflows/bc.yml b/.github/workflows/bc.yml
index ba3e9ef1..00041a9f 100644
--- a/.github/workflows/bc.yml
+++ b/.github/workflows/bc.yml
@@ -1,6 +1,25 @@
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
@@ -11,4 +30,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
- ['8.0']
+ ['8.1']
diff --git a/.github/workflows/bechmark.yml b/.github/workflows/bechmark.yml
index 4caa5d88..f5341be7 100644
--- a/.github/workflows/bechmark.yml
+++ b/.github/workflows/bechmark.yml
@@ -28,5 +28,5 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
- ['8.0', '8.1']
+ ['8.1']
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 8506ea11..05e7b401 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.1', '8.2', '8.3']
diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml
index 6cb40992..a857bce6 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.3']
diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml
index c1aca98c..a6873e2e 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 b5a56491..457772af 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'
@@ -17,7 +17,8 @@ jobs:
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 96b26790..e33eca86 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.1', '8.2', '8.3']
diff --git a/.gitignore b/.gitignore
index fc599ffa..6dd15181 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
# Static analysis
analysis.txt
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fe0220d3..90988b47 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,10 +1,11 @@
# Yii Dependency Injection Change Log
-## 1.2.2 under development
+## 1.3.0 under development
- Enh #353: Add shortcut for tag reference #333 (@xepozz)
- Enh #356: Improve usage `NotFoundException` for cases with definitions (@vjik)
- Enh #364: Minor refactoring to improve performance of container (@samdark)
+- Enh #375: Raise minimum PHP version to `^8.1` and refactor code (@vjik)
## 1.2.1 December 23, 2022
diff --git a/README.md b/README.md
index 76e958c4..e4b54db2 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ and configure classes resolving dependencies.
## Requirements
-- PHP 8.0 or higher.
+- PHP 8.1 or higher.
- `Multibyte String` PHP extension.
## Installation
diff --git a/composer.json b/composer.json
index f3698848..5d7a32c8 100644
--- a/composer.json
+++ b/composer.json
@@ -32,7 +32,7 @@
}
],
"require": {
- "php": "^8.0",
+ "php": "^8.1",
"ext-mbstring": "*",
"psr/container": "^1.1|^2.0",
"yiisoft/definitions": "^3.0"
@@ -41,11 +41,11 @@
"league/container": "^4.2",
"maglnet/composer-require-checker": "^4.2",
"phpbench/phpbench": "^1.2.0",
- "phpunit/phpunit": "^9.5",
+ "phpunit/phpunit": "^10.5",
"rector/rector": "^1.2",
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23",
- "vimeo/psalm": "^4.30|^5.7",
+ "vimeo/psalm": "^5.26",
"yiisoft/injector": "^1.0",
"yiisoft/test-support": "^3.0"
},
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 316e34ba..d0c9dfab 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,15 +1,18 @@
-
+ colors="true"
+ displayDetailsOnPhpunitDeprecations="true"
+>
@@ -20,9 +23,9 @@
-
+
+
diff --git a/psalm.xml b/psalm.xml
index 5ce79f0e..7d4b7337 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -14,6 +14,7 @@
+
diff --git a/rector.php b/rector.php
index f55daaed..3f22397e 100644
--- a/rector.php
+++ b/rector.php
@@ -5,6 +5,7 @@
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
+use Rector\Php81\Rector\Array_\FirstClassCallableRector;
use Rector\Set\ValueObject\LevelSetList;
return static function (RectorConfig $rectorConfig): void {
@@ -18,10 +19,13 @@
// define sets of rules
$rectorConfig->sets([
- LevelSetList::UP_TO_PHP_80,
+ LevelSetList::UP_TO_PHP_81,
]);
$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
+ FirstClassCallableRector::class => [
+ __DIR__ . '/tests/Unit/Helpers/DefinitionParserTest.php',
+ ],
]);
};
diff --git a/src/Container.php b/src/Container.php
index 38a14cb8..f8cb2864 100644
--- a/src/Container.php
+++ b/src/Container.php
@@ -40,7 +40,7 @@ final class Container implements ContainerInterface
/**
* @var DefinitionStorage Storage of object definitions.
*/
- private DefinitionStorage $definitions;
+ private readonly DefinitionStorage $definitions;
/**
* @var array Used to collect IDs of objects instantiated during build
@@ -51,7 +51,7 @@ final class Container implements ContainerInterface
/**
* @var bool $validate If definitions should be validated.
*/
- private bool $validate;
+ private readonly bool $validate;
private array $instances = [];
@@ -207,7 +207,6 @@ public function get(string $id)
*/
private function addDefinition(string $id, mixed $definition): void
{
- /** @var mixed $definition */
[$definition, $meta] = DefinitionParser::parse($definition);
if ($this->validate) {
$this->validateDefinition($definition, $id);
@@ -237,7 +236,6 @@ private function addDefinition(string $id, mixed $definition): void
*/
private function addDefinitions(array $config): void
{
- /** @var mixed $definition */
foreach ($config as $id => $definition) {
if ($this->validate && !is_string($id)) {
throw new InvalidConfigException(
@@ -296,10 +294,7 @@ private function setDelegates(array $delegates): void
private function validateDefinition(mixed $definition, ?string $id = null): void
{
if (is_array($definition) && isset($definition[DefinitionParser::IS_PREPARED_ARRAY_DEFINITION_DATA])) {
- /** @var mixed $class */
$class = $definition['class'];
-
- /** @var mixed $constructorArguments */
$constructorArguments = $definition['__construct()'];
/**
@@ -331,7 +326,6 @@ private function validateDefinition(mixed $definition, ?string $id = null): void
*/
private function validateMeta(array $meta): void
{
- /** @var mixed $value */
foreach ($meta as $key => $value) {
if (!in_array($key, self::ALLOWED_META, true)) {
throw new InvalidConfigException(
@@ -413,7 +407,6 @@ private function setTags(array $tags): void
)
);
}
- /** @var mixed $service */
foreach ($services as $service) {
if (!is_string($service)) {
throw new InvalidConfigException(
@@ -505,7 +498,6 @@ private function build(string $id)
$definition = DefinitionNormalizer::normalize($this->definitions->get($id), $id);
- /** @var mixed $object */
$object = $definition->resolve($this->get(ContainerInterface::class));
} finally {
unset($this->building[$id]);
@@ -520,7 +512,6 @@ private function getTaggedServices(string $tagAlias): array
$services = [];
if (isset($this->tags[$tag])) {
foreach ($this->tags[$tag] as $service) {
- /** @var mixed */
$services[] = $this->get($service);
}
}
@@ -535,7 +526,6 @@ private function getTaggedServices(string $tagAlias): array
private function addProviders(array $providers): void
{
$extensions = [];
- /** @var mixed $provider */
foreach ($providers as $provider) {
$providerInstance = $this->buildProvider($provider);
$extensions[] = $providerInstance->getExtensions();
@@ -543,7 +533,6 @@ private function addProviders(array $providers): void
}
foreach ($extensions as $providerExtensions) {
- /** @var mixed $extension */
foreach ($providerExtensions as $id => $extension) {
if (!is_string($id)) {
throw new InvalidConfigException(
@@ -568,7 +557,6 @@ private function addProviders(array $providers): void
);
}
- /** @var mixed $definition */
$definition = $this->definitions->get($id);
if (!$definition instanceof ExtensibleService) {
$definition = new ExtensibleService($definition, $id);
diff --git a/src/ExtensibleService.php b/src/ExtensibleService.php
index 208f1873..bb04aeab 100644
--- a/src/ExtensibleService.php
+++ b/src/ExtensibleService.php
@@ -29,8 +29,8 @@ final class ExtensibleService implements DefinitionInterface
* @param mixed $definition Definition to allow registering extensions for.
*/
public function __construct(
- private mixed $definition,
- private string $id
+ private readonly mixed $definition,
+ private readonly string $id
) {
}
@@ -54,18 +54,15 @@ public function addExtension(callable $closure): void
public function resolve(ContainerInterface $container): mixed
{
- /** @var mixed $service */
$service = DefinitionNormalizer::normalize($this->definition, $this->id)
->resolve($container);
foreach ($this->extensions as $extension) {
- /** @var mixed $result */
$result = $extension($container->get(ContainerInterface::class), $service);
if ($result === null) {
continue;
}
- /** @var mixed $service */
$service = $result;
}
diff --git a/src/Helpers/DefinitionParser.php b/src/Helpers/DefinitionParser.php
index 81cf18be..c6495286 100644
--- a/src/Helpers/DefinitionParser.php
+++ b/src/Helpers/DefinitionParser.php
@@ -64,7 +64,6 @@ public static function parse(mixed $definition): array
// Dedicated definition
if (isset($definition[self::DEFINITION_META])) {
- /** @var mixed $newDefinition */
$newDefinition = $definition[self::DEFINITION_META];
unset($definition[self::DEFINITION_META]);
@@ -81,19 +80,16 @@ public static function parse(mixed $definition): array
$class = null;
$constructorArguments = [];
$methodsAndProperties = [];
- /** @var mixed $value */
foreach ($definition as $key => $value) {
if (is_string($key)) {
// Class
if ($key === ArrayDefinition::CLASS_NAME) {
- /** @var mixed $class */
$class = $value;
continue;
}
// Constructor arguments
if ($key === ArrayDefinition::CONSTRUCTOR) {
- /** @var mixed $constructorArguments */
$constructorArguments = $value;
continue;
}
@@ -109,7 +105,6 @@ public static function parse(mixed $definition): array
}
}
- /** @var mixed */
$meta[$key] = $value;
}
return [
diff --git a/src/NotFoundException.php b/src/NotFoundException.php
index 2616ce71..a765a362 100644
--- a/src/NotFoundException.php
+++ b/src/NotFoundException.php
@@ -18,7 +18,7 @@ final class NotFoundException extends Exception implements NotFoundExceptionInte
* @param string[] $buildStack Stack of IDs of services requested definition or class that was not found.
*/
public function __construct(
- private string $id,
+ private readonly string $id,
private array $buildStack = [],
?Throwable $previous = null,
) {
diff --git a/src/StateResetter.php b/src/StateResetter.php
index 624baf29..d8290e96 100644
--- a/src/StateResetter.php
+++ b/src/StateResetter.php
@@ -27,7 +27,7 @@ final class StateResetter
* @param ContainerInterface $container Container to reset.
*/
public function __construct(
- private ContainerInterface $container
+ private readonly ContainerInterface $container
) {
}
@@ -74,7 +74,6 @@ public function setResetters(array $resetters): void
);
}
- /** @var mixed $instance */
$instance = $this->container->get($serviceId);
if (!is_object($instance)) {
throw new InvalidArgumentException(
diff --git a/tests/Support/Car.php b/tests/Support/Car.php
index 03b9e3f8..ebe8aa48 100644
--- a/tests/Support/Car.php
+++ b/tests/Support/Car.php
@@ -11,8 +11,10 @@ class Car
{
public ColorInterface $color;
- public function __construct(private EngineInterface $engine, private array $moreEngines = [])
- {
+ public function __construct(
+ private readonly EngineInterface $engine,
+ private readonly array $moreEngines = [],
+ ) {
}
public function setColor(ColorInterface $color): self
diff --git a/tests/Support/ConstructorTestClass.php b/tests/Support/ConstructorTestClass.php
index c11da94f..39b52011 100644
--- a/tests/Support/ConstructorTestClass.php
+++ b/tests/Support/ConstructorTestClass.php
@@ -11,7 +11,7 @@
*/
class ConstructorTestClass
{
- private array $allParameters;
+ private readonly array $allParameters;
/**
* ConstructorTestClass constructor.
diff --git a/tests/Support/EngineFactory.php b/tests/Support/EngineFactory.php
index ff71e8ac..bf774e39 100644
--- a/tests/Support/EngineFactory.php
+++ b/tests/Support/EngineFactory.php
@@ -12,7 +12,7 @@
*/
class EngineFactory
{
- public function __construct(private ContainerInterface $container)
+ public function __construct(private readonly ContainerInterface $container)
{
}
diff --git a/tests/Support/EngineStorage.php b/tests/Support/EngineStorage.php
index 08bdccd9..df33846b 100644
--- a/tests/Support/EngineStorage.php
+++ b/tests/Support/EngineStorage.php
@@ -6,7 +6,7 @@
final class EngineStorage
{
- private array $engines;
+ private readonly array $engines;
public function __construct(EngineInterface ...$engines)
{
diff --git a/tests/Support/Garage.php b/tests/Support/Garage.php
index 7d23cf87..94047cfe 100644
--- a/tests/Support/Garage.php
+++ b/tests/Support/Garage.php
@@ -9,7 +9,7 @@
*/
final class Garage
{
- public function __construct(private SportCar $car)
+ public function __construct(private readonly SportCar $car)
{
}
diff --git a/tests/Support/GearBox.php b/tests/Support/GearBox.php
index ee6fd068..32cd4a96 100644
--- a/tests/Support/GearBox.php
+++ b/tests/Support/GearBox.php
@@ -9,7 +9,7 @@
*/
class GearBox
{
- public function __construct(private int $maxGear = 5)
+ public function __construct(private readonly int $maxGear = 5)
{
}
}
diff --git a/tests/Support/OptionalConcreteDependency.php b/tests/Support/OptionalConcreteDependency.php
index 10d4d8a6..ca0c4db3 100644
--- a/tests/Support/OptionalConcreteDependency.php
+++ b/tests/Support/OptionalConcreteDependency.php
@@ -6,7 +6,7 @@
class OptionalConcreteDependency
{
- public function __construct(private ?Car $car = null)
+ public function __construct(private readonly ?Car $car = null)
{
}
diff --git a/tests/Support/SportCar.php b/tests/Support/SportCar.php
index f2472054..2d865d42 100644
--- a/tests/Support/SportCar.php
+++ b/tests/Support/SportCar.php
@@ -11,8 +11,10 @@ class SportCar
{
public ColorInterface $color;
- public function __construct(private EngineInterface $engine, private int $maxSpeed)
- {
+ public function __construct(
+ private readonly EngineInterface $engine,
+ private readonly int $maxSpeed,
+ ) {
}
public function setColor(ColorInterface $color): self
diff --git a/tests/Support/TreeItem.php b/tests/Support/TreeItem.php
index ccf53f9b..4ad33784 100644
--- a/tests/Support/TreeItem.php
+++ b/tests/Support/TreeItem.php
@@ -9,7 +9,7 @@
*/
class TreeItem
{
- public function __construct(private self $treeItem)
+ public function __construct(private readonly self $treeItem)
{
}
}
diff --git a/tests/Support/UnionTypeInConstructorFirstTypeInParamResolvable.php b/tests/Support/UnionTypeInConstructorFirstTypeInParamResolvable.php
index 73db39e1..5456bbf0 100644
--- a/tests/Support/UnionTypeInConstructorFirstTypeInParamResolvable.php
+++ b/tests/Support/UnionTypeInConstructorFirstTypeInParamResolvable.php
@@ -6,7 +6,7 @@
final class UnionTypeInConstructorFirstTypeInParamResolvable
{
- public function __construct(private EngineMarkOne|EngineInterface $engine)
+ public function __construct(private readonly EngineMarkOne|EngineInterface $engine)
{
}
}
diff --git a/tests/Support/UnionTypeInConstructorParamNotResolvable.php b/tests/Support/UnionTypeInConstructorParamNotResolvable.php
index 59284018..792d781c 100644
--- a/tests/Support/UnionTypeInConstructorParamNotResolvable.php
+++ b/tests/Support/UnionTypeInConstructorParamNotResolvable.php
@@ -6,7 +6,7 @@
final class UnionTypeInConstructorParamNotResolvable
{
- public function __construct(private EngineInterface|ColorInterface $param)
+ public function __construct(private readonly EngineInterface|ColorInterface $param)
{
}
}
diff --git a/tests/Support/UnionTypeInConstructorSecondTypeInParamResolvable.php b/tests/Support/UnionTypeInConstructorSecondTypeInParamResolvable.php
index e802ee17..08bbe040 100644
--- a/tests/Support/UnionTypeInConstructorSecondTypeInParamResolvable.php
+++ b/tests/Support/UnionTypeInConstructorSecondTypeInParamResolvable.php
@@ -6,7 +6,7 @@
final class UnionTypeInConstructorSecondTypeInParamResolvable
{
- public function __construct(private EngineInterface|EngineMarkOne $engine)
+ public function __construct(private readonly EngineInterface|EngineMarkOne $engine)
{
}
}
diff --git a/tests/Support/VariadicConstructor.php b/tests/Support/VariadicConstructor.php
index a41e7a79..f782fe85 100644
--- a/tests/Support/VariadicConstructor.php
+++ b/tests/Support/VariadicConstructor.php
@@ -6,10 +6,13 @@
final class VariadicConstructor
{
- private array $parameters;
+ private readonly array $parameters;
- public function __construct(private $first, private EngineInterface $engine, ...$parameters)
- {
+ public function __construct(
+ private $first,
+ private readonly EngineInterface $engine,
+ ...$parameters
+ ) {
$this->parameters = $parameters;
}
diff --git a/tests/Unit/CompositePsrContainerOverLeagueTest.php b/tests/Unit/CompositePsrContainerOverLeagueTest.php
index e4968cb4..dcce5464 100644
--- a/tests/Unit/CompositePsrContainerOverLeagueTest.php
+++ b/tests/Unit/CompositePsrContainerOverLeagueTest.php
@@ -12,7 +12,7 @@
/**
* Test the CompositeContainer over League Container.
*/
-final class CompositePsrContainerOverLeagueTest extends AbstractCompositePsrContainerTest
+final class CompositePsrContainerOverLeagueTest extends CompositePsrContainerTestAbstract
{
public function createContainer(iterable $definitions = []): ContainerInterface
{
diff --git a/tests/Unit/CompositePsrContainerOverYiisoftTest.php b/tests/Unit/CompositePsrContainerOverYiisoftTest.php
index 771a18ed..568aa243 100644
--- a/tests/Unit/CompositePsrContainerOverYiisoftTest.php
+++ b/tests/Unit/CompositePsrContainerOverYiisoftTest.php
@@ -16,7 +16,7 @@
/**
* Test the CompositeContainer over Yiisoft Container.
*/
-final class CompositePsrContainerOverYiisoftTest extends AbstractCompositePsrContainerTest
+final class CompositePsrContainerOverYiisoftTest extends CompositePsrContainerTestAbstract
{
public function createContainer(iterable $definitions = []): ContainerInterface
{
diff --git a/tests/Unit/AbstractCompositePsrContainerTest.php b/tests/Unit/CompositePsrContainerTestAbstract.php
similarity index 96%
rename from tests/Unit/AbstractCompositePsrContainerTest.php
rename to tests/Unit/CompositePsrContainerTestAbstract.php
index 6a306340..d72e1f2d 100644
--- a/tests/Unit/AbstractCompositePsrContainerTest.php
+++ b/tests/Unit/CompositePsrContainerTestAbstract.php
@@ -19,7 +19,7 @@
* General tests for PSR-11 composite container.
* To be extended for specific containers.
*/
-abstract class AbstractCompositePsrContainerTest extends AbstractPsrContainerTest
+abstract class CompositePsrContainerTestAbstract extends PsrContainerTestAbstract
{
public function createCompositeContainer(ContainerInterface $attachedContainer): ContainerInterface
{
@@ -154,10 +154,6 @@ public function testDelegateLookup(): void
public function testDelegateLookupUnionTypes(): void
{
- if (PHP_VERSION_ID < 80000) {
- $this->markTestSkipped('Union types are not supported before PHP 8');
- }
-
$compositeContainer = new CompositeContainer();
$firstContainer = new Container(ContainerConfig::create());
diff --git a/tests/Unit/ContainerTest.php b/tests/Unit/ContainerTest.php
index d75202be..e8020664 100644
--- a/tests/Unit/ContainerTest.php
+++ b/tests/Unit/ContainerTest.php
@@ -5,6 +5,7 @@
namespace Yiisoft\Di\Tests\Unit;
use ArrayIterator;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
@@ -130,7 +131,7 @@ public function testOptionalCircularClassDependency(): void
$this->assertNull($a->b->a);
}
- public function dataHas(): array
+ public static function dataHas(): array
{
return [
[false, 'non_existing'],
@@ -144,9 +145,7 @@ public function dataHas(): array
];
}
- /**
- * @dataProvider dataHas
- */
+ #[DataProvider('dataHas')]
public function testHas(bool $expected, $id): void
{
$config = ContainerConfig::create()
@@ -158,7 +157,7 @@ public function testHas(bool $expected, $id): void
$this->assertSame($expected, $container->has($id));
}
- public function dataUnionTypes(): array
+ public static function dataUnionTypes(): array
{
return [
[UnionTypeInConstructorSecondTypeInParamResolvable::class],
@@ -166,15 +165,9 @@ public function dataUnionTypes(): array
];
}
- /**
- * @dataProvider dataUnionTypes
- */
+ #[DataProvider('dataUnionTypes')]
public function testUnionTypes(string $class): void
{
- if (PHP_VERSION_ID < 80000) {
- $this->markTestSkipped('Union types are not supported before PHP 8');
- }
-
$container = new Container(ContainerConfig::create());
$this->assertTrue($container->has($class));
@@ -191,7 +184,7 @@ public function testClassExistsButIsNotResolvable(): void
$this->assertFalse($container->has(ColorInterface::class));
}
- public function dataClassExistButIsNotResolvableWithUnionTypes(): array
+ public static function dataClassExistButIsNotResolvableWithUnionTypes(): array
{
return [
[UnionTypeInConstructorParamNotResolvable::class],
@@ -199,15 +192,9 @@ public function dataClassExistButIsNotResolvableWithUnionTypes(): array
];
}
- /**
- * @dataProvider dataClassExistButIsNotResolvableWithUnionTypes
- */
+ #[DataProvider('dataClassExistButIsNotResolvableWithUnionTypes')]
public function testClassExistButIsNotResolvableWithUnionTypes(string $class): void
{
- if (PHP_VERSION_ID < 80000) {
- $this->markTestSkipped('Union types are not supported before PHP 8');
- }
-
$container = new Container(ContainerConfig::create());
$this->assertFalse($container->has($class));
@@ -693,7 +680,7 @@ public function testCallableWithInjector(): void
$config = ContainerConfig::create()
->withDefinitions([
EngineInterface::class => EngineMarkOne::class,
- 'car' => fn (CarFactory $factory, Injector $injector) => $injector->invoke([$factory, 'create']),
+ 'car' => fn (CarFactory $factory, Injector $injector) => $injector->invoke($factory->create(...)),
]);
$container = new Container($config);
@@ -760,7 +747,7 @@ public function testArrayStaticCall(): void
$config = ContainerConfig::create()
->withDefinitions([
EngineInterface::class => EngineMarkOne::class,
- 'car' => [CarFactory::class, 'create'],
+ 'car' => CarFactory::create(...),
]);
$container = new Container($config);
@@ -1146,7 +1133,7 @@ public function testTagsAsArrayInConstructor(): void
$this->assertSame(EngineMarkTwo::class, $engines[1]::class);
}
- public function dataResetter(): array
+ public static function dataResetter(): array
{
return [
'strict-mode' => [true],
@@ -1154,9 +1141,7 @@ public function dataResetter(): array
];
}
- /**
- * @dataProvider dataResetter
- */
+ #[DataProvider('dataResetter')]
public function testResetter(bool $strictMode): void
{
$config = ContainerConfig::create()
@@ -1353,7 +1338,7 @@ static function (ContainerInterface $container) {
);
}
- public function dataResetterInProviderDefinitions(): array
+ public static function dataResetterInProviderDefinitions(): array
{
return [
'strict-mode' => [true],
@@ -1361,9 +1346,7 @@ public function dataResetterInProviderDefinitions(): array
];
}
- /**
- * @dataProvider dataResetterInProviderDefinitions
- */
+ #[DataProvider('dataResetterInProviderDefinitions')]
public function testResetterInProviderDefinitions(bool $strictMode): void
{
$config = ContainerConfig::create()
@@ -1944,7 +1927,7 @@ public function testNonArrayArguments(): void
$container = new Container($config);
}
- public function dataInvalidTags(): array
+ public static function dataInvalidTags(): array
{
return [
[
@@ -1962,9 +1945,7 @@ public function dataInvalidTags(): array
];
}
- /**
- * @dataProvider dataInvalidTags
- */
+ #[DataProvider('dataInvalidTags')]
public function testInvalidTags(string $message, array $tags): void
{
$config = ContainerConfig::create()
@@ -1983,9 +1964,7 @@ public static function dataNotFoundExceptionMessageWithDefinitions(): array
];
}
- /**
- * @dataProvider dataNotFoundExceptionMessageWithDefinitions
- */
+ #[DataProvider('dataNotFoundExceptionMessageWithDefinitions')]
public function testNotFoundExceptionMessageWithDefinitions(array $definitions): void
{
$config = ContainerConfig::create()->withDefinitions($definitions);
diff --git a/tests/Unit/LeaguePsrContainerTest.php b/tests/Unit/LeaguePsrContainerTest.php
index c3a2242f..beb539fb 100644
--- a/tests/Unit/LeaguePsrContainerTest.php
+++ b/tests/Unit/LeaguePsrContainerTest.php
@@ -10,7 +10,7 @@
/**
* Test the League PSR-11 Container.
*/
-final class LeaguePsrContainerTest extends AbstractPsrContainerTest
+final class LeaguePsrContainerTest extends PsrContainerTestAbstract
{
public function createContainer(array $definitions = []): ContainerInterface
{
diff --git a/tests/Unit/AbstractPsrContainerTest.php b/tests/Unit/PsrContainerTestAbstract.php
similarity index 97%
rename from tests/Unit/AbstractPsrContainerTest.php
rename to tests/Unit/PsrContainerTestAbstract.php
index d411a43b..5cbde8b3 100644
--- a/tests/Unit/AbstractPsrContainerTest.php
+++ b/tests/Unit/PsrContainerTestAbstract.php
@@ -17,7 +17,7 @@
* General tests for PSR-11 container.
* To be extended for specific containers.
*/
-abstract class AbstractPsrContainerTest extends TestCase
+abstract class PsrContainerTestAbstract extends TestCase
{
abstract public function createContainer(array $definitions = []): ContainerInterface;
diff --git a/tests/Unit/Reference/TagReferenceTest.php b/tests/Unit/Reference/TagReferenceTest.php
index 9abfe046..f1237da4 100644
--- a/tests/Unit/Reference/TagReferenceTest.php
+++ b/tests/Unit/Reference/TagReferenceTest.php
@@ -23,10 +23,6 @@ public function testConstructor(): void
$reflection = new \ReflectionClass(TagReference::class);
$reflectionMethod = $reflection->getConstructor();
$this->assertTrue($reflectionMethod->isPrivate());
- if (PHP_VERSION_ID < 81000) {
- $reflectionMethod->setAccessible(true);
- }
-
$reflectionMethod->invoke($reflection->newInstanceWithoutConstructor());
}
diff --git a/tests/Unit/YiisoftPsrContainerTest.php b/tests/Unit/YiisoftPsrContainerTest.php
index b7959e97..1e58e76d 100644
--- a/tests/Unit/YiisoftPsrContainerTest.php
+++ b/tests/Unit/YiisoftPsrContainerTest.php
@@ -12,7 +12,7 @@
/**
* Test the Yiisoft PSR-11 Container.
*/
-final class YiisoftPsrContainerTest extends AbstractPsrContainerTest
+final class YiisoftPsrContainerTest extends PsrContainerTestAbstract
{
public function createContainer(iterable $definitions = []): ContainerInterface
{