Skip to content

Commit

Permalink
Merge pull request #19 from frenchcomp/master
Browse files Browse the repository at this point in the history
To use PHP-DI 6.0 with the Symfony Bridge, with Symfony 3.3, 3.4 et 4+
  • Loading branch information
mnapoli authored Mar 5, 2018
2 parents 043c7eb + a4965bc commit d536a47
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ composer.lock
composer.phar
vendor/*
.idea/*
/phpunit.xml
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
language: php

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

matrix:
include:
- php: 5.5
- php: 7.0
env: dependencies=lowest

before_script:
- composer install -n
- if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest --prefer-stable -n; fi;

script:
- vendor/bin/phpunit
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
}
},
"require": {
"php": "~5.5|~7.0",
"php-di/php-di": "^5.0",
"symfony/dependency-injection": "^3.0",
"symfony/http-kernel": "^3.0",
"symfony/proxy-manager-bridge": "^3.0",
"symfony/config": "^3.0"
"php": "~7.0",
"php-di/php-di": "~6.0",
"symfony/dependency-injection": "~3.3||~4.0",
"symfony/http-kernel": "~3.3||~4.0",
"symfony/proxy-manager-bridge": "~3.3||~4.0",
"symfony/config": "~3.3||~4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace DI\Bridge\Symfony;

use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\Debug\DebugClassLoader;
use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -92,7 +92,7 @@ private function removeInvalidReferenceBehaviorPass(ContainerBuilder $container)

private function disableDebugClassLoader()
{
if (!class_exists('Symfony\Component\Debug\DebugClassLoader')) {
if (!class_exists(DebugClassLoader::class)) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/SymfonyContainerBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace DI\Bridge\Symfony;

use DI\NotFoundException;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Container as SymfonyContainer;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
Expand Down Expand Up @@ -87,7 +87,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
return $entry;
} catch (NotFoundException $e) {
if ($invalidBehavior === self::EXCEPTION_ON_INVALID_REFERENCE) {
throw new ServiceNotFoundException($id);
throw new ServiceNotFoundException($id, null, $e);
}
}

Expand Down
6 changes: 4 additions & 2 deletions tests/FunctionalTest/ContainerInteractionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function phpdi_should_get_entries_from_symfony()

$phpdiContainer->set(
'foo',
\DI\object(Class1::class)
\DI\create(Class1::class)
->constructor(\DI\get('class2'))
);

Expand Down Expand Up @@ -69,7 +69,9 @@ public function phpdi_aliases_can_reference_symfony_entries()
/** @var Container $phpdiContainer */
$phpdiContainer = $container->getFallbackContainer();

$phpdiContainer->set('foo', \DI\get('class2'));
$ref = \DI\get('class2');
$ref->setName('foo');
$phpdiContainer->set('foo', $ref);

$class2 = $container->get('foo');

Expand Down
1 change: 1 addition & 0 deletions tests/FunctionalTest/Fixtures/config/class1.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
services:
class1:
class: DI\Bridge\Symfony\Test\FunctionalTest\Fixtures\Class1
public: true
arguments: [ '@DI\\Bridge\\Symfony\\Test\\FunctionalTest\\Fixtures\\Class2' ]
1 change: 1 addition & 0 deletions tests/FunctionalTest/Fixtures/config/class2.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
services:
class2:
class: DI\Bridge\Symfony\Test\FunctionalTest\Fixtures\Class2
public: true
9 changes: 5 additions & 4 deletions tests/UnitTest/SymfonyContainerBridgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@

use DI\Bridge\Symfony\SymfonyContainerBridge;
use DI\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface as SfContainerInterface;

class SymfonyContainerBridgeTest extends \PHPUnit_Framework_TestCase
{
public function testHasFallback()
{
$wrapper = new SymfonyContainerBridge();

$fallback = $this->getMockForAbstractClass('Interop\Container\ContainerInterface');
$fallback = $this->getMockForAbstractClass(ContainerInterface::class);
$fallback->expects($this->once())
->method('has')
->with('foo')
Expand All @@ -34,7 +35,7 @@ public function testGetFallback()
{
$wrapper = new SymfonyContainerBridge();

$fallback = $this->getMockForAbstractClass('Interop\Container\ContainerInterface');
$fallback = $this->getMockForAbstractClass(ContainerInterface::class);
$fallback->expects($this->once())
->method('get')
->with('foo')
Expand All @@ -51,7 +52,7 @@ public function testGetNotFoundReturnNull()

$wrapper->setFallbackContainer(ContainerBuilder::buildDevContainer());

$this->assertNull($wrapper->get('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE));
$this->assertNull($wrapper->get('foo', SfContainerInterface::NULL_ON_INVALID_REFERENCE));
}

/**
Expand Down

0 comments on commit d536a47

Please sign in to comment.