diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d12150199..2423187dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,10 +16,10 @@ jobs: timeout-minutes: 15 strategy: matrix: - php: [ '7.2', '7.3', '7.4', '8.0' ] + php: [ '7.4', '8.0', '8.1' ] dependency-version: [ '' ] include: - - php: '7.2' + - php: '7.4' dependency-version: '--prefer-lowest' steps: - name: Checkout @@ -28,7 +28,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - tools: composer:v1 + tools: composer:v2 coverage: none - name: Cache Composer dependencies uses: actions/cache@v2 @@ -37,10 +37,10 @@ jobs: key: php-${{ matrix.php }}-composer-locked-${{ hashFiles('composer.lock') }} restore-keys: php-${{ matrix.php }}-composer-locked- - name: Install PHP dependencies - if: matrix.php != '8.0' + if: matrix.php != '8.1' run: composer update ${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress --no-suggest - - name: 'Install PHP dependencies on PHP 8 (TODO: remove that)' - if: matrix.php == '8.0' + - name: 'Install PHP dependencies on PHP 8.1 (TODO: remove that)' + if: matrix.php == '8.1' run: | # Install Composer 2 composer self-update --snapshot diff --git a/change-log.md b/change-log.md index 94fe4e66d..572f284ea 100644 --- a/change-log.md +++ b/change-log.md @@ -1,5 +1,9 @@ # Change log +## 6.1.0 + +- [#791](https://github.com/PHP-DI/PHP-DI/issues/791) Support PHP 8.1, remove support for PHP 7.2 + ## 6.0.2 - Fix potential regression introduced when fixing [#582](https://github.com/PHP-DI/PHP-DI/issues/582) diff --git a/composer.json b/composer.json index 0874f2d80..16b5f265e 100644 --- a/composer.json +++ b/composer.json @@ -25,17 +25,17 @@ "phpstan": "phpstan analyse -l 5 -c phpstan.neon src" }, "require": { - "php": ">=7.2.0", + "php": ">=7.4.0", "psr/container": "^1.0", "php-di/invoker": "^2.0", "php-di/phpdoc-reader": "^2.0.1", - "opis/closure": "^3.5.5" + "laravel/serializable-closure": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^8.5|^9.0", + "phpunit/phpunit": "^9.5", "mnapoli/phpunit-easymock": "^1.2", - "doctrine/annotations": "~1.2", - "ocramius/proxy-manager": "^2.0.2", + "doctrine/annotations": "~1.10", + "ocramius/proxy-manager": "^2.11.2", "friendsofphp/php-cs-fixer": "^2.4", "phpstan/phpstan": "^0.12" }, diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index 8abc32d69..ca5d49467 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -21,7 +21,7 @@ use function dirname; use function file_put_contents; use InvalidArgumentException; -use Opis\Closure\SerializableClosure; +use Laravel\SerializableClosure\Support\ReflectionClosure; use function rename; use function sprintf; use function tempnam; @@ -401,8 +401,7 @@ private function isCompilable($value) */ private function compileClosure(\Closure $closure) : string { - $wrapper = new SerializableClosure($closure); - $reflector = $wrapper->getReflector(); + $reflector = new ReflectionClosure($closure); if ($reflector->getUseVariables()) { throw new InvalidDefinition('Cannot compile closures which import variables using the `use` keyword'); diff --git a/src/Definition/Resolver/ArrayResolver.php b/src/Definition/Resolver/ArrayResolver.php index 72d5ed4c0..30a715b70 100644 --- a/src/Definition/Resolver/ArrayResolver.php +++ b/src/Definition/Resolver/ArrayResolver.php @@ -42,7 +42,7 @@ public function resolve(Definition $definition, array $parameters = []) : array $values = $definition->getValues(); // Resolve nested definitions - array_walk_recursive($values, function (&$value, $key) use ($definition) { + array_walk_recursive($values, function (& $value, $key) use ($definition) { if ($value instanceof Definition) { $value = $this->resolveDefinition($value, $definition, $key); } diff --git a/tests/IntegrationTest/ContainerDebugTest.php b/tests/IntegrationTest/ContainerDebugTest.php index a0a183360..eca1f3b02 100644 --- a/tests/IntegrationTest/ContainerDebugTest.php +++ b/tests/IntegrationTest/ContainerDebugTest.php @@ -74,28 +74,28 @@ public function testEntriesDefinitions() }); // Default definitions - $this->assertRegExp('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('DI\Container')); - $this->assertRegExp( + $this->assertMatchesRegularExpression('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('DI\Container')); + $this->assertMatchesRegularExpression( '/^Object \(\n {4}class = #NOT INSTANTIABLE# DI\\\FactoryInterface\n/', $container->debugEntry('DI\FactoryInterface') ); - $this->assertRegExp( + $this->assertMatchesRegularExpression( '/^Object \(\n {4}class = #NOT INSTANTIABLE# Invoker\\\InvokerInterface\n/', $container->debugEntry('Invoker\InvokerInterface') ); - $this->assertRegExp( + $this->assertMatchesRegularExpression( '/^Object \(\n {4}class = #NOT INSTANTIABLE# Psr\\\Container\\\ContainerInterface\n/', $container->debugEntry('Psr\Container\ContainerInterface') ); // Container definitions - $this->assertRegExp('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('create')); - $this->assertRegExp('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('autowire')); + $this->assertMatchesRegularExpression('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('create')); + $this->assertMatchesRegularExpression('/^Object \(\n {4}class = DI\\\Container\n/', $container->debugEntry('autowire')); $this->assertEquals('Factory', $container->debugEntry('factory')); $this->assertEquals('Factory', $container->debugEntry('callback')); $this->assertEquals('Decorate(decorator)', $container->debugEntry('decorator')); $this->assertEquals('get(value)', $container->debugEntry('alias')); - $this->assertRegExp('/^Environment variable \(\n {4}variable = foo\n/', $container->debugEntry('environment')); + $this->assertMatchesRegularExpression('/^Environment variable \(\n {4}variable = foo\n/', $container->debugEntry('environment')); $this->assertEquals("[\n 0 => 'foo',\n 1 => 'bar',\n]", $container->debugEntry('array')); $this->assertEquals('foo', $container->debugEntry('string')); $this->assertEquals('Value (1.5)', $container->debugEntry('float')); diff --git a/tests/IntegrationTest/Definitions/FactoryDefinitionTest.php b/tests/IntegrationTest/Definitions/FactoryDefinitionTest.php index cac73c8dc..6bbe8ce24 100644 --- a/tests/IntegrationTest/Definitions/FactoryDefinitionTest.php +++ b/tests/IntegrationTest/Definitions/FactoryDefinitionTest.php @@ -590,7 +590,7 @@ public function test_closure_with_static_variables_are_supported(ContainerBuilde public function test_multiple_closures_on_the_same_line_cannot_be_compiled() { - $this->markTestSkipped('Opis/closure doesn\'t throw on multiple closures on the same line'); + $this->markTestSkipped('laravel/serializable-closure doesn\'t throw on multiple closures on the same line'); $this->expectException(InvalidDefinition::class); $this->expectExceptionMessage('Cannot compile closures when two closures are defined on the same line'); @@ -614,9 +614,6 @@ public function test_optional_parameters_can_be_omitted(ContainerBuilder $builde self::assertEquals('foo', $container->get('factory')); } - /** - * @requires PHP 7.4 - */ public function test_fn_closures_compilation_is_supported() { $builder = (new ContainerBuilder)->enableCompilation(self::COMPILATION_DIR, self::generateCompiledClassName()); diff --git a/tests/UnitTest/Definition/Source/AnnotationBasedAutowiringTest.php b/tests/UnitTest/Definition/Source/AnnotationBasedAutowiringTest.php index f42fe98a1..3187e91d2 100644 --- a/tests/UnitTest/Definition/Source/AnnotationBasedAutowiringTest.php +++ b/tests/UnitTest/Definition/Source/AnnotationBasedAutowiringTest.php @@ -65,10 +65,6 @@ public function testUnguessableProperty() (new AnnotationBasedAutowiring)->autowire(AnnotationFixture4::class); } - /** - * Typed properties support requires PHP 7.4 - * @requires PHP 7.4 - */ public function testTypedProperty() { $definition = (new AnnotationBasedAutowiring)->autowire(AnnotationFixtureTypedProperties::class); @@ -79,10 +75,6 @@ public function testTypedProperty() $this->assertHasPropertyInjection($definition, 'typedAndNamed', 'name'); } - /** - * Typed properties support requires PHP 7.4 - * @requires PHP 7.4 - */ public function testScalarTypedPropertiesFail() { $this->expectException(\DI\Definition\Exception\InvalidAnnotation::class);