Skip to content

Commit

Permalink
Merge pull request #9 from klatys/sf3.3-plus
Browse files Browse the repository at this point in the history
Sf3.3 plus
  • Loading branch information
mzstic authored Dec 5, 2017
2 parents 44c30b8 + db57084 commit 90cc4f7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
- 7.1
- 7.2

cache:
directories:
Expand Down
6 changes: 5 additions & 1 deletion DependencyInjection/Compiler/AutowiringCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}

}
25 changes: 21 additions & 4 deletions Tests/DependencyInjection/Compiler/AutowiringCompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,19 +33,21 @@ public function testProcessEmpty()
{
$containerBuilder = new ContainerBuilder;
$this->classMapBuildCompilerPass->process($containerBuilder);
$container = $this->getClassMapBuildClasses();

$this->assertSame([], $this->getClassMapBuildClasses());
$this->assertSame([], $container);
}

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());
}

Expand Down Expand Up @@ -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;
}

}
9 changes: 7 additions & 2 deletions Tests/SkrzAutowiringBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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]);
Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
}
],
"require": {
"php": ">=5.4",
"php": ">=5.5.9",
"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"
}
}

0 comments on commit 90cc4f7

Please sign in to comment.