Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
* 3.0:
  use stable 1.0.x Composer versions
  Fix typo in VarDumper README
  [DI] Fix AutowirePass fatal error with classes that have non-existing parents
  [DependencyInjection] Tests for AutowirePass with missing parent class
  [WebProfilerBunde] Give an absolute url in case the request occured from another domain

Conflicts:
	src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
	src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
  • Loading branch information
nicolas-grekas committed Apr 25, 2016
2 parents 84b48de + fc50ad9 commit b44abe3
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -56,7 +56,7 @@ before_install:
- if [[ ! $skip && $PHP != hhvm ]]; then echo extension = ldap.so >> $INI_FILE; fi
- if [[ ! $skip && $PHP != hhvm ]]; then echo extension = redis.so >> $INI_FILE; fi;
- if [[ ! $skip && $PHP != hhvm ]]; then phpenv config-rm xdebug.ini; fi
- if [[ ! $skip ]]; then composer self-update; fi
- if [[ ! $skip ]]; then composer self-update --stable; fi
- if [[ ! $skip ]]; then cp .composer/* ~/.composer/; composer global install; fi
- if [[ ! $skip ]]; then ./phpunit install; fi
- if [[ ! $skip && $deps ]]; then composer global remove hirak/prestissimo; fi
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -45,7 +45,7 @@ install:
- IF %PHP%==1 echo extension=php_pdo_sqlite.dll >> php.ini-max
- IF %PHP%==1 echo extension=php_curl.dll >> php.ini-max
- IF %PHP%==1 echo curl.cainfo=c:\php\cacert.pem >> php.ini-max
- appveyor DownloadFile https://getcomposer.org/composer.phar
- IF %PHP%==1 appveyor DownloadFile https://getcomposer.org/download/1.0.2/composer.phar
- copy /Y php.ini-max php.ini
- cd c:\projects\symfony
- mkdir %APPDATA%\Composer
Expand Down
Expand Up @@ -65,7 +65,7 @@ public function onKernelResponse(FilterResponseEvent $event)
try {
$response->headers->set(
'X-Debug-Token-Link',
$this->urlGenerator->generate('_profiler', array('token' => $response->headers->get('X-Debug-Token')))
$this->urlGenerator->generate('_profiler', array('token' => $response->headers->get('X-Debug-Token')), UrlGeneratorInterface::ABSOLUTE_URL)
);
} catch (\Exception $e) {
$response->headers->set('X-Debug-Error', get_class($e).': '.$e->getMessage());
Expand Down
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class WebDebugToolbarListenerTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -195,16 +196,16 @@ public function testXDebugUrlHeader()
$urlGenerator
->expects($this->once())
->method('generate')
->with('_profiler', array('token' => 'xxxxxxxx'))
->will($this->returnValue('/_profiler/xxxxxxxx'))
->with('_profiler', array('token' => 'xxxxxxxx'), UrlGeneratorInterface::ABSOLUTE_URL)
->will($this->returnValue('http://mydomain.com/_profiler/xxxxxxxx'))
;

$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);

$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, 'bottom', $urlGenerator);
$listener->onKernelResponse($event);

$this->assertEquals('/_profiler/xxxxxxxx', $response->headers->get('X-Debug-Token-Link'));
$this->assertEquals('http://mydomain.com/_profiler/xxxxxxxx', $response->headers->get('X-Debug-Token-Link'));
}

public function testThrowingUrlGenerator()
Expand Down
Expand Up @@ -35,19 +35,32 @@ class AutowirePass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
$this->container = $container;
foreach ($container->getDefinitions() as $id => $definition) {
if ($definition->isAutowired()) {
$this->completeDefinition($id, $definition);
$throwingAutoloader = function ($class) { throw new \ReflectionException(sprintf('Class %s does not exist', $class)); };
spl_autoload_register($throwingAutoloader);

try {
$this->container = $container;
foreach ($container->getDefinitions() as $id => $definition) {
if ($definition->isAutowired()) {
$this->completeDefinition($id, $definition);
}
}
} catch (\Error $e) {
} catch (\Exception $e) {
}

spl_autoload_unregister($throwingAutoloader);

// Free memory and remove circular reference to container
$this->container = null;
$this->reflectionClasses = array();
$this->definedTypes = array();
$this->types = null;
$this->ambiguousServiceTypes = array();

if (isset($e)) {
throw $e;
}
}

/**
Expand Down Expand Up @@ -139,11 +152,11 @@ private function completeDefinition($id, Definition $definition)
}
}
}
} catch (\ReflectionException $reflectionException) {
} catch (\ReflectionException $e) {
// Typehint against a non-existing class

if (!$parameter->isDefaultValueAvailable()) {
throw new RuntimeException(sprintf('Cannot autowire argument %s for %s because the type-hinted class does not exist (%s).', $index + 1, $definition->getClass(), $reflectionException->getMessage()), 0, $reflectionException);
throw new RuntimeException(sprintf('Cannot autowire argument %s for %s because the type-hinted class does not exist (%s).', $index + 1, $definition->getClass(), $e->getMessage()), 0, $e);
}

$value = $parameter->getDefaultValue();
Expand Down Expand Up @@ -295,7 +308,7 @@ private function getReflectionClass($id, Definition $definition)

try {
$reflector = new \ReflectionClass($class);
} catch (\ReflectionException $reflectionException) {
} catch (\ReflectionException $e) {
$reflector = false;
}

Expand Down
Expand Up @@ -284,6 +284,21 @@ public function testClassNotFoundThrowsException()
$pass->process($container);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Cannot autowire argument 2 for Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument because the type-hinted class does not exist (Class Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass does not exist).
*/
public function testParentClassNotFoundThrowsException()
{
$container = new ContainerBuilder();

$aDefinition = $container->register('a', __NAMESPACE__.'\BadParentTypeHintedArgument');
$aDefinition->setAutowired(true);

$pass = new AutowirePass();
$pass->process($container);
}

public function testDontUseAbstractServices()
{
$container = new ContainerBuilder();
Expand Down Expand Up @@ -446,6 +461,21 @@ public function getCreateResourceTests()
['ClassChangedConstructorArgs', false],
);
}

public function testIgnoreServiceWithClassNotExisting()
{
$container = new ContainerBuilder();

$container->register('class_not_exist', __NAMESPACE__.'\OptionalServiceClass');

$barDefinition = $container->register('bar', __NAMESPACE__.'\Bar');
$barDefinition->setAutowired(true);

$pass = new AutowirePass();
$pass->process($container);

$this->assertTrue($container->hasDefinition('bar'));
}
}

class Foo
Expand Down Expand Up @@ -558,6 +588,12 @@ public function __construct(Dunglas $k, NotARealClass $r)
{
}
}
class BadParentTypeHintedArgument
{
public function __construct(Dunglas $k, OptionalServiceClass $r)
{
}
}
class NotGuessableArgument
{
public function __construct(Foo $k)
Expand Down
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Tests\Compiler;

use Symfony\Bug\NotExistClass;

class OptionalServiceClass extends NotExistClass
{
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/README.md
Expand Up @@ -2,7 +2,7 @@ VarDumper Component
===================

The VarDumper component provides mechanisms for walking through any arbitrary
PHP variable. Built on top, it provides a better `dump()`` function that you
PHP variable. Built on top, it provides a better `dump()` function that you
can use instead of `var_dump`.

Resources
Expand Down

0 comments on commit b44abe3

Please sign in to comment.