From 8d08ce69fa2ffed595c6834e1d751788a25d72f3 Mon Sep 17 00:00:00 2001 From: Jan Klat Date: Mon, 4 Dec 2017 23:20:11 +0100 Subject: [PATCH 1/2] add SF3.3+ DI changes support --- .travis.yml | 2 ++ .../Compiler/AutowiringCompilerPass.php | 6 ++++- .../AutowiringCompilerPassPropertyTest.php | 7 +++++- .../Compiler/AutowiringCompilerPassTest.php | 25 ++++++++++++++++--- .../ClassMapBuildCompilerPassTest.php | 18 ++++++++++--- Tests/SkrzAutowiringBundleTest.php | 9 +++++-- composer.json | 9 ++++--- 7 files changed, 61 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8ff4cd7..8b61e1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 + - 7.2 - hhvm cache: diff --git a/DependencyInjection/Compiler/AutowiringCompilerPass.php b/DependencyInjection/Compiler/AutowiringCompilerPass.php index 0f1630b..a73cac8 100644 --- a/DependencyInjection/Compiler/AutowiringCompilerPass.php +++ b/DependencyInjection/Compiler/AutowiringCompilerPass.php @@ -86,7 +86,11 @@ public function process(ContainerBuilder $container) ); // add files to cache - $container->addClassResource($reflectionClass); + if (method_exists($container, 'addObjectResource')) { + $container->addObjectResource($reflectionClass); + } elseif (method_exists($container, 'addClassResource')) { + $container->addClassResource($reflectionClass); + } } catch (AutowiringException $exception) { throw new AutowiringException( diff --git a/Tests/DependencyInjection/Compiler/AutowiringCompilerPassPropertyTest.php b/Tests/DependencyInjection/Compiler/AutowiringCompilerPassPropertyTest.php index c1938f3..42ecba5 100644 --- a/Tests/DependencyInjection/Compiler/AutowiringCompilerPassPropertyTest.php +++ b/Tests/DependencyInjection/Compiler/AutowiringCompilerPassPropertyTest.php @@ -9,6 +9,7 @@ use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\ClassMapBuildCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\HttpKernel\Kernel; class AutowiringCompilerPassPropertyTest extends PHPUnit_Framework_TestCase { @@ -46,7 +47,11 @@ public function testAutowireProperty() $reference = $autowiredServiceDefinition->getProperties()["property"]; $this->assertInstanceOf("Symfony\\Component\\DependencyInjection\\Reference", $reference); - $this->assertSame("someservice", (string) $reference); + if (Kernel::VERSION_ID >= 30300) { + $this->assertSame("someService", (string)$reference); + } else { + $this->assertSame("someservice", (string)$reference); + } } } diff --git a/Tests/DependencyInjection/Compiler/AutowiringCompilerPassTest.php b/Tests/DependencyInjection/Compiler/AutowiringCompilerPassTest.php index 2e7c274..dac99bb 100644 --- a/Tests/DependencyInjection/Compiler/AutowiringCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/AutowiringCompilerPassTest.php @@ -10,6 +10,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\HttpKernel\Kernel; class AutowiringCompilerPassTest extends PHPUnit_Framework_TestCase { @@ -61,7 +62,11 @@ public function testAutowireConstructor() /** @var Reference $reference */ $reference = $arguments[0]; $this->assertInstanceOf("Symfony\\Component\\DependencyInjection\\Reference", $reference); - $this->assertSame("someservice", (string) $reference); + if (Kernel::VERSION_ID >= 30300) { + $this->assertSame("someService", (string)$reference); + } else { + $this->assertSame("someservice", (string)$reference); + } } public function testAutowireConstructorWithInterface() @@ -85,7 +90,11 @@ public function testAutowireConstructorWithInterface() /** @var Reference $reference */ $reference = $arguments[0]; $this->assertInstanceOf("Symfony\\Component\\DependencyInjection\\Reference", $reference); - $this->assertSame("someservice", (string) $reference); + if (Kernel::VERSION_ID >= 30300) { + $this->assertSame("someService", (string)$reference); + } else { + $this->assertSame("someservice", (string)$reference); + } } public function testAutowireConstructorWithInterfaceOptionally() @@ -128,10 +137,18 @@ public function testAutowireConstructorWithInterfaceOptionally() /** @var Reference $reference */ $reference = $arguments[0]; $this->assertInstanceOf("Symfony\\Component\\DependencyInjection\\Reference", $reference); - $this->assertSame("someservice", (string) $reference); + if (Kernel::VERSION_ID >= 30300) { + $this->assertSame("someService", (string)$reference); + } else { + $this->assertSame("someservice", (string)$reference); + } $reference = $arguments[1]; $this->assertInstanceOf("Symfony\\Component\\DependencyInjection\\Reference", $reference); - $this->assertSame("someservice2", (string) $reference); + if (Kernel::VERSION_ID >= 30300) { + $this->assertSame("someService2", (string)$reference); + } else { + $this->assertSame("someservice2", (string)$reference); + } } } diff --git a/Tests/DependencyInjection/Compiler/ClassMapBuildCompilerPassTest.php b/Tests/DependencyInjection/Compiler/ClassMapBuildCompilerPassTest.php index 5b39bd2..206c14c 100644 --- a/Tests/DependencyInjection/Compiler/ClassMapBuildCompilerPassTest.php +++ b/Tests/DependencyInjection/Compiler/ClassMapBuildCompilerPassTest.php @@ -3,10 +3,13 @@ use PHPUnit_Framework_Assert; use PHPUnit_Framework_TestCase; +use Psr\Container\ContainerInterface as PsrContainerInterface; use Skrz\Bundle\AutowiringBundle\DependencyInjection\ClassMultiMap; use Skrz\Bundle\AutowiringBundle\DependencyInjection\Compiler\ClassMapBuildCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\HttpKernel\Kernel; class ClassMapBuildCompilerPassTest extends PHPUnit_Framework_TestCase { @@ -30,8 +33,9 @@ public function testProcessEmpty() { $containerBuilder = new ContainerBuilder; $this->classMapBuildCompilerPass->process($containerBuilder); + $container = $this->getClassMapBuildClasses(); - $this->assertSame([], $this->getClassMapBuildClasses()); + $this->assertSame([], $container); } public function testProcess() @@ -39,10 +43,11 @@ public function testProcess() $containerBuilder = new ContainerBuilder; $containerBuilder->setDefinition("someService", new Definition(self::SOME_CLASS_NAME)); $this->classMapBuildCompilerPass->process($containerBuilder); + $serviceName = Kernel::VERSION_ID >= 30300 ? "someService" : "someservice"; $this->assertSame([ - "Skrz\\Bundle\\AutowiringBundle\\Tests\\DependencyInjection\\ClassMultipleMapSource\\SomeInterface" => ["someservice"], - self::SOME_CLASS_NAME => ["someservice"] + "Skrz\\Bundle\\AutowiringBundle\\Tests\\DependencyInjection\\ClassMultipleMapSource\\SomeInterface" => [$serviceName], + self::SOME_CLASS_NAME => [$serviceName] ], $this->getClassMapBuildClasses()); } @@ -80,7 +85,12 @@ public function testSkipAbstract() */ private function getClassMapBuildClasses() { - return PHPUnit_Framework_Assert::getObjectAttribute($this->classMultiMap, "classes"); + $classes = PHPUnit_Framework_Assert::getObjectAttribute($this->classMultiMap, "classes"); + //since SF3.3 container aliases are added in constructor + unset($classes[PsrContainerInterface::class]); + unset($classes[ContainerInterface::class]); + + return $classes; } } diff --git a/Tests/SkrzAutowiringBundleTest.php b/Tests/SkrzAutowiringBundleTest.php index 3e9a7ec..453a3a1 100644 --- a/Tests/SkrzAutowiringBundleTest.php +++ b/Tests/SkrzAutowiringBundleTest.php @@ -4,6 +4,7 @@ use PHPUnit_Framework_TestCase; use Skrz\Bundle\AutowiringBundle\SkrzAutowiringBundle; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Kernel; class SkrzAutowiringBundleTest extends PHPUnit_Framework_TestCase { @@ -31,8 +32,12 @@ public function testBuild() $passConfig = $containerBuilder->getCompiler()->getPassConfig(); $beforeOptimizationPasses = $passConfig->getBeforeOptimizationPasses(); - $this->assertInstanceOf("Skrz\\Bundle\\AutowiringBundle\\DependencyInjection\\Compiler\\ClassMapBuildCompilerPass", $beforeOptimizationPasses[0]); - $this->assertInstanceOf("Skrz\\Bundle\\AutowiringBundle\\DependencyInjection\\Compiler\\AutoscanCompilerPass", $beforeOptimizationPasses[1]); + $baseIndex = 0; + if (Kernel::VERSION_ID >= 30300) { + $baseIndex = 3; + } + $this->assertInstanceOf("Skrz\\Bundle\\AutowiringBundle\\DependencyInjection\\Compiler\\ClassMapBuildCompilerPass", $beforeOptimizationPasses[0 + $baseIndex]); + $this->assertInstanceOf("Skrz\\Bundle\\AutowiringBundle\\DependencyInjection\\Compiler\\AutoscanCompilerPass", $beforeOptimizationPasses[1 + $baseIndex]); $afterRemovingPasses = $passConfig->getAfterRemovingPasses(); $this->assertInstanceOf("Skrz\\Bundle\\AutowiringBundle\\DependencyInjection\\Compiler\\ClassMapBuildCompilerPass", $afterRemovingPasses[0]); diff --git a/composer.json b/composer.json index d5a9dfa..dd71739 100644 --- a/composer.json +++ b/composer.json @@ -11,13 +11,16 @@ "require": { "php": ">=5.4", "doctrine/annotations": "~1.2", - "symfony/config": "~2.7|~3.0", - "symfony/dependency-injection": "~2.7|~3.0", - "symfony/http-kernel": "~2.7|~3.0" + "symfony/config": "~2.7|~3.0|~4.0", + "symfony/dependency-injection": "~2.7|~3.0|~4.0", + "symfony/http-kernel": "~2.7|~3.0|~4.0" }, "autoload": { "psr-4": { "Skrz\\Bundle\\AutowiringBundle\\": "" } + }, + "require-dev": { + "phpunit/phpunit": "~4.6" } } From db570846f21f84495b6a23c0e7c55478b1514d52 Mon Sep 17 00:00:00 2001 From: Jan Klat Date: Mon, 4 Dec 2017 23:28:08 +0100 Subject: [PATCH 2/2] drop 5.4 and hhvm support --- .travis.yml | 2 -- composer.json | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8b61e1e..d60c69b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,11 @@ language: php php: - - 5.4 - 5.5 - 5.6 - 7.0 - 7.1 - 7.2 - - hhvm cache: directories: diff --git a/composer.json b/composer.json index dd71739..1e61951 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": ">=5.4", + "php": ">=5.5.9", "doctrine/annotations": "~1.2", "symfony/config": "~2.7|~3.0|~4.0", "symfony/dependency-injection": "~2.7|~3.0|~4.0",