Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To use PHP-DI 6.0 with the Symfony Bridge, with Symfony 3.3, 3.4 et 4+ #19

Merged
merged 8 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you have to do this? Because it looks like a regression in PHP-DI 6 to me 🤔

Copy link
Contributor Author

@frenchcomp frenchcomp Feb 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for me its a regression in PHP-DI 6, the \DI\get returns a reference and not an helper, and so the entry name will never injected into it. So the name is empty. (In PHP-DI 5 its an helper).

But I use PHP-DI only since few months, (it'is a pretty tool). So my experience with this project is limited and I did not have time to see if that was the expected behavior or not for PHP-DI 6.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you I have created an issue to check this in PHP-DI itself. It should not block this PR though.


$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