Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #22 from pamil/symfony4
Browse files Browse the repository at this point in the history
Add support for Symfony 4
  • Loading branch information
pamil authored Feb 13, 2018
2 parents 67ec9bc + a3dfd2e commit 97c376c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ language: php

php:
- 7.1
- nightly
- 7.2

matrix:
allow_failures:
- php: nightly
fast_finish: true
env:
- SYMFONY_VERSION=3.3.*
- SYMFONY_VERSION=3.4.*
- SYMFONY_VERSION=4.0.*

cache:
directories:
- vendor
- ~/.composer/cache/files

before_install:
- phpenv config-rm xdebug.ini || true

install:
- composer update --prefer-dist
- composer require symfony/dependency-injection:${SYMFONY_VERSION} --no-update --no-scripts --prefer-dist
- composer require --dev symfony/http-kernel:${SYMFONY_VERSION} --no-update --no-scripts --prefer-dist
- composer update --prefer-dist $PREFER_LOWEST

script:
- composer validate --strict
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
"php": "^7.1",

"behat/behat": "^3.1",
"symfony/dependency-injection": "^2.8|^3.0"
"symfony/dependency-injection": "^3.3|^4.0"
},
"require-dev": {
"friends-of-behat/test-context": "^1.0",
"phpspec/phpspec": "^4.0@alpha",
"symfony/http-kernel": "^2.8|^3.0",
"phpunit/phpunit": "^5.7.13|^6.0"
"phpspec/phpspec": "^4.0",
"symfony/http-kernel": "^3.3|^4.0",
"phpunit/phpunit": "^6.0"
},
"suggest": {
"symfony/http-kernel": "^2.8|^3.0"
"symfony/http-kernel": "^3.3|^4.0"
},
"autoload": {
"psr-4": { "FriendsOfBehat\\CrossContainerExtension\\": "src/" }
Expand Down
4 changes: 2 additions & 2 deletions spec/ContainerBasedContainerAccessorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ function it_gets_a_service(Container $container): void

function it_gets_parameters_from_frozen_container(Container $container): void
{
$container->isFrozen()->willReturn(true);
$container->isCompiled()->willReturn(true);
$container->getParameterBag()->willReturn(new ParameterBag(['name' => 'value']));

$this->getParameters()->shouldReturn(['name' => 'value']);
}

function it_gets_parameters_from_not_frozen_container(Container $container): void
{
$container->isFrozen()->willReturn(false);
$container->isCompiled()->willReturn(false);
$container->getParameterBag()->willReturn(new ParameterBag(['name' => 'value']));

$this->getParameters()->shouldReturn(['name' => 'value']);
Expand Down
4 changes: 2 additions & 2 deletions spec/KernelBasedContainerAccessorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function it_gets_parameters_from_frozen_container(KernelInterface $kernel, Conta
{
$kernel->getContainer()->willReturn($container);

$container->isFrozen()->willReturn(true);
$container->isCompiled()->willReturn(true);
$container->getParameterBag()->willReturn(new ParameterBag(['name' => 'value']));

$this->getParameters()->shouldReturn(['name' => 'value']);
Expand All @@ -63,7 +63,7 @@ function it_gets_parameters_from_not_frozen_container(KernelInterface $kernel, C
{
$kernel->getContainer()->willReturn($container);

$container->isFrozen()->willReturn(false);
$container->isCompiled()->willReturn(false);
$container->getParameterBag()->willReturn(new ParameterBag(['name' => 'value']));

$this->getParameters()->shouldReturn(['name' => 'value']);
Expand Down
2 changes: 1 addition & 1 deletion src/ContainerBasedContainerAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getParameters(): array
{
$parameterBag = $this->container->getParameterBag();

if (!$this->container->isFrozen()) {
if (!$this->container->isCompiled()) {
$parameterBag = clone $parameterBag;
$parameterBag->resolve();
}
Expand Down
44 changes: 27 additions & 17 deletions tests/CrossContainerProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ final class CrossContainerProcessorTest extends TestCase
public function it_resolves_cross_container_references_in_service_argument(): void
{
$externalContainer = new ContainerBuilder();
$externalContainer->setDefinition('array_object', new Definition(\ArrayObject::class, [['foo' => 'bar']]));
$externalContainer->setDefinition('array_object', (new Definition(\ArrayObject::class, [['foo' => 'bar']]))->setPublic(true));

$baseContainer = new ContainerBuilder();
$baseContainer->setDefinition('array_object', new Definition(\ArrayObject::class, [
$baseContainer->setDefinition('array_object', (new Definition(\ArrayObject::class, [
new Reference('__external__.array_object'),
]));
]))->setPublic(true));

$this->buildContainerWithDependencies($baseContainer, ['external' => $externalContainer]);

Expand All @@ -48,12 +48,12 @@ public function it_resolves_cross_container_references_in_service_argument(): vo
public function it_resolves_cross_container_references_in_service_argument_array(): void
{
$externalContainer = new ContainerBuilder();
$externalContainer->setDefinition('std_class', new Definition(\stdClass::class));
$externalContainer->setDefinition('std_class', (new Definition(\stdClass::class))->setPublic(true));

$baseContainer = new ContainerBuilder();
$baseContainer->setDefinition('array_object', new Definition(\ArrayObject::class, [
$baseContainer->setDefinition('array_object', (new Definition(\ArrayObject::class, [
['std' => ['class' => new Reference('__external__.std_class')]],
]));
]))->setPublic(true));

$this->buildContainerWithDependencies($baseContainer, ['external' => $externalContainer]);

Expand All @@ -67,14 +67,14 @@ public function it_resolves_cross_container_references_in_service_argument_array
public function it_resolves_cross_container_references_in_service_argument_anonymous_definition(): void
{
$externalContainer = new ContainerBuilder();
$externalContainer->setDefinition('std_class', new Definition(\stdClass::class));
$externalContainer->setDefinition('std_class', (new Definition(\stdClass::class))->setPublic(true));

$baseContainer = new ContainerBuilder();
$baseContainer->setDefinition('array_object', new Definition(\ArrayObject::class, [
$baseContainer->setDefinition('array_object', (new Definition(\ArrayObject::class, [
new Definition(\ArrayObject::class, [
['std_class' => new Reference('__external__.std_class')],
]),
]));
]))->setPublic(true));

$this->buildContainerWithDependencies($baseContainer, ['external' => $externalContainer]);

Expand All @@ -88,11 +88,14 @@ public function it_resolves_cross_container_references_in_service_argument_anony
public function it_resolves_cross_container_references_in_service_factory(): void
{
$externalContainer = new ContainerBuilder();
$externalContainer->setDefinition('array_object_factory', new Definition(\ArrayObject::class, [['old' => 'old']]));
$externalContainer->setDefinition('array_object_factory', (new Definition(\ArrayObject::class, [['old' => 'old']]))->setPublic(true));

$baseContainer = new ContainerBuilder();
$baseContainer->setDefinition('array_object',
(new Definition(\ArrayObject::class, [['new' => 'new']]))->setFactory([new Reference('__external__.array_object_factory'), 'exchangeArray'])
$baseContainer->setDefinition(
'array_object',
(new Definition(\ArrayObject::class, [['new' => 'new']]))
->setFactory([new Reference('__external__.array_object_factory'), 'exchangeArray'])
->setPublic(true)
);

$this->buildContainerWithDependencies($baseContainer, ['external' => $externalContainer]);
Expand Down Expand Up @@ -142,9 +145,11 @@ public function it_resolves_cross_container_parameters_in_service_definition_arr
$externalContainer->setParameter('parameter', '42');

$baseContainer = new ContainerBuilder();
$baseContainer->setDefinition('array_object', new Definition(\ArrayObject::class, [
['parameter' => '%__external__.parameter%'],
]));
$baseContainer->setDefinition(
'array_object',
(new Definition(\ArrayObject::class, [['parameter' => '%__external__.parameter%']]))
->setPublic(true)
);

$this->buildContainerWithDependencies($baseContainer, ['external' => $externalContainer]);

Expand Down Expand Up @@ -190,10 +195,15 @@ public function it_resolves_cross_container_escaped_parameters_symfony_kernel():
public function it_resolves_cross_container_references_in_method_calls(): void
{
$externalContainer = new ContainerBuilder();
$externalContainer->setDefinition('array_object', new Definition(\ArrayObject::class, [['foo' => 'bar']]));
$externalContainer->setDefinition('array_object', (new Definition(\ArrayObject::class, [['foo' => 'bar']]))->setPublic(true));

$baseContainer = new ContainerBuilder();
$baseContainer->setDefinition('array_object', (new Definition(\ArrayObject::class, [[]]))->addMethodCall('exchangeArray', [new Reference('__external__.array_object')]));
$baseContainer->setDefinition(
'array_object',
(new Definition(\ArrayObject::class, [[]]))
->addMethodCall('exchangeArray', [new Reference('__external__.array_object')])
->setPublic(true)
);

$this->buildContainerWithDependencies($baseContainer, ['external' => $externalContainer]);

Expand Down

0 comments on commit 97c376c

Please sign in to comment.