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

Remove deprecated warning on DebugClassLoader #22

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.phar
vendor/*
.idea/*
/phpunit.xml
var/cache/*
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

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

before_script:
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
}
},
"require": {
"php": "~7.0",
"php": "~7.2",
"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"
"symfony/dependency-injection": "~3.4||~4.4||~5.1",
"symfony/http-kernel": "~3.4||~4.4||~5.1",
"symfony/proxy-manager-bridge": "~3.4||~4.4||~5.1",
"symfony/config": "~3.4||~4.4||~5.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"symfony/filesystem": "^3.0",
"symfony/yaml": "^3.0",
"symfony/debug": "^3.0"
"phpunit/phpunit": "~8.0||~9.0",
"symfony/filesystem": "~3.4||~4.4||~5.1",
"symfony/yaml": "~3.4||~4.4||~5.1",
"symfony/error-handler": "~3.4||~4.4||~5.1"
}
}
31 changes: 21 additions & 10 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
namespace DI\Bridge\Symfony;

use Psr\Container\ContainerInterface;
use Symfony\Component\Debug\DebugClassLoader;
use Symfony\Component\Debug\DebugClassLoader as LegacyDebugClassLoader;
use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\ErrorHandler\DebugClassLoader;

/**
* Customization of Symfony's kernel to setup PHP-DI.
Expand Down Expand Up @@ -78,25 +79,35 @@ protected function initializeContainer()
private function removeInvalidReferenceBehaviorPass(ContainerBuilder $container)
{
$passConfig = $container->getCompilerPassConfig();
$compilationPasses = $passConfig->getRemovingPasses();

foreach ($compilationPasses as $i => $pass) {
if ($pass instanceof CheckExceptionOnInvalidReferenceBehaviorPass) {
unset($compilationPasses[$i]);
break;
$compilationPassRemover = static function (array $compilationPasses): array {
foreach ($compilationPasses as $i => $pass) {
if ($pass instanceof CheckExceptionOnInvalidReferenceBehaviorPass) {
unset($compilationPasses[$i]);
break;
}
}
}

$passConfig->setRemovingPasses($compilationPasses);
return $compilationPasses;
};

$passConfig->setRemovingPasses($compilationPassRemover($passConfig->getRemovingPasses()));
$passConfig->setAfterRemovingPasses($compilationPassRemover($passConfig->getAfterRemovingPasses()));
}

private function disableDebugClassLoader()
{
if (!class_exists(DebugClassLoader::class)) {
if (class_exists(DebugClassLoader::class)) {
DebugClassLoader::disable();

return;
}

if (!class_exists(LegacyDebugClassLoader::class)) {
return;
}

DebugClassLoader::disable();
LegacyDebugClassLoader::disable();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/FunctionalTest/AbstractFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
namespace DI\Bridge\Symfony\Test\FunctionalTest;

use DI\Bridge\Symfony\Test\FunctionalTest\Fixtures\AppKernel;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;

abstract class AbstractFunctionalTest extends \PHPUnit_Framework_TestCase
abstract class AbstractFunctionalTest extends TestCase
{
protected function createKernel($configFile = 'empty.yml')
{
Expand Down
4 changes: 2 additions & 2 deletions tests/FunctionalTest/ContainerAwareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @coversNothing
*/
class ContainerAwareInterfaceTest extends AbstractFunctionalTest
class ContainerAwareTest extends AbstractFunctionalTest
{
/**
* @link https://github.com/PHP-DI/Symfony-Bridge/issues/2
Expand All @@ -27,6 +27,6 @@ public function testContainerAware()
/** @var ContainerAwareController $class */
$class = $container->get(ContainerAwareController::class);

$this->assertSame($container, $class->container);
$this::assertSame($container, $class->container);
Copy link
Member

Choose a reason for hiding this comment

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

These code-style changes are unrelated to the PR, could you revert them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Assert method are static.

}
}
10 changes: 5 additions & 5 deletions tests/FunctionalTest/ContainerInteractionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ContainerInteractionTest extends AbstractFunctionalTest
/**
* @test Get a Symfony entry from PHP-DI's container
*/
public function phpdi_should_get_entries_from_symfony()
public function phpdiShouldGetEntriesFromSymfony()
Copy link
Member

@mnapoli mnapoli Jul 18, 2020

Choose a reason for hiding this comment

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

Could you restore the original name? (including in the other tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

{
$kernel = $this->createKernel('class2.yml');

Expand All @@ -42,7 +42,7 @@ public function phpdi_should_get_entries_from_symfony()

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

$this->assertTrue($class1 instanceof Class1);
$this::assertTrue($class1 instanceof Class1);
}

/**
Expand All @@ -54,13 +54,13 @@ public function symfonyGetInPHPDI()

$class1 = $kernel->getContainer()->get('class1');

$this->assertTrue($class1 instanceof Class1);
$this::assertTrue($class1 instanceof Class1);
}

/**
* @test Alias a Symfony entry from PHP-DI's container
*/
public function phpdi_aliases_can_reference_symfony_entries()
public function phpdiAliasesCanReferenceSymfonyEntries()
{
$kernel = $this->createKernel('class2.yml');

Expand All @@ -75,6 +75,6 @@ public function phpdi_aliases_can_reference_symfony_entries()

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

$this->assertTrue($class2 instanceof Class2);
$this::assertTrue($class2 instanceof Class2);
}
}
2 changes: 1 addition & 1 deletion tests/FunctionalTest/Fixtures/config/class1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ services:
class1:
class: DI\Bridge\Symfony\Test\FunctionalTest\Fixtures\Class1
public: true
arguments: [ '@DI\\Bridge\\Symfony\\Test\\FunctionalTest\\Fixtures\\Class2' ]
arguments: [ '@DI\Bridge\Symfony\Test\FunctionalTest\Fixtures\Class2' ]
21 changes: 6 additions & 15 deletions tests/FunctionalTest/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,26 @@
*/
class KernelTest extends AbstractFunctionalTest
{
/**
* @test
*/
public function kernel_should_boot()
public function testKernelShouldBoot()
{
$kernel = $this->createKernel();

$this->assertInstanceOf(SymfonyContainerBridge::class, $kernel->getContainer());
$this::assertInstanceOf(SymfonyContainerBridge::class, $kernel->getContainer());
}

/**
* @test
*/
public function phpdi_should_resolve_classes()
public function testPhpdiShouldResolveClasses()
{
$kernel = $this->createKernel();

$object = $kernel->getContainer()->get(Class1::class);
$this->assertInstanceOf(Class1::class, $object);
$this::assertInstanceOf(Class1::class, $object);
}

/**
* @test
*/
public function symfony_should_resolve_classes()
public function testSymfonyShouldResolveClasses()
{
$kernel = $this->createKernel('class2.yml');

$object = $kernel->getContainer()->get('class2');
$this->assertInstanceOf(Class2::class, $object);
$this::assertInstanceOf(Class2::class, $object);
}
}
25 changes: 13 additions & 12 deletions tests/UnitTest/SymfonyContainerBridgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,41 @@

use DI\Bridge\Symfony\SymfonyContainerBridge;
use DI\ContainerBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface as SfContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

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

$fallback = $this->getMockForAbstractClass(ContainerInterface::class);
$fallback->expects($this->once())
$fallback->expects(self::once())
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idem Once method are static.

->method('has')
->with('foo')
->will($this->returnValue(false));
->will(self::returnValue(false));

$wrapper->setFallbackContainer($fallback);

$this->assertFalse($wrapper->has('foo'));
$this::assertFalse($wrapper->has('foo'));
}

public function testGetFallback()
{
$wrapper = new SymfonyContainerBridge();

$fallback = $this->getMockForAbstractClass(ContainerInterface::class);
$fallback->expects($this->once())
$fallback->expects(self::once())
->method('get')
->with('foo')
->will($this->returnValue('bar'));
->will(self::returnValue('bar'));

$wrapper->setFallbackContainer($fallback);

$this->assertEquals('bar', $wrapper->get('foo'));
$this::assertEquals('bar', $wrapper->get('foo'));
}

public function testGetNotFoundReturnNull()
Expand All @@ -52,18 +54,17 @@ public function testGetNotFoundReturnNull()

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

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

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testGetNotFoundException()
{
$this->expectException(ServiceNotFoundException::class);

$wrapper = new SymfonyContainerBridge();

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

$this->assertNull($wrapper->get('foo'));
$this::assertNull($wrapper->get('foo'));
}
}