Skip to content

Commit

Permalink
Merge branch '2.7'
Browse files Browse the repository at this point in the history
* 2.7:
  `ResolveParameterPlaceHoldersPass` unit tests
  Fixing wrong variable name from symfony#13519
  [translation][initialize cache] Remove dead code.
  [DependencyInjection] fixed service resolution for factories
  [HttpKernel] Throw a LogicException when kernel.exception does not led to a Response
  [FrameworkBundle] Added domain column when debugging translations
  [PhpUnitBridge] do not replace but require-dev in symfony/symfony
  [acl][command][SecurityBundle] Fixed user input option mode to be an Array

Conflicts:
	composer.json
  • Loading branch information
fabpot committed Mar 17, 2015
2 parents a4149db + 17ad6fd commit 3ea8943
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 34 deletions.
15 changes: 10 additions & 5 deletions composer.json
Expand Up @@ -45,7 +45,6 @@
"symfony/locale": "self.version",
"symfony/monolog-bridge": "self.version",
"symfony/options-resolver": "self.version",
"symfony/phpunit-bridge": "self.version",
"symfony/process": "2.99.99",
"symfony/property-access": "self.version",
"symfony/proxy-manager-bridge": "self.version",
Expand All @@ -68,6 +67,7 @@
"symfony/yaml": "2.99.99"
},
"require-dev": {
"symfony/phpunit-bridge": "self.version",
"doctrine/data-fixtures": "1.0.*",
"doctrine/dbal": "~2.2",
"doctrine/orm": "~2.2,>=2.2.3",
Expand All @@ -78,16 +78,21 @@
"egulias/email-validator": "~1.2"
},
"autoload": {
"psr-0": { "Symfony\\": "src/" },
"psr-0": {
"Symfony\\Bridge\\Doctrine\\": "src/",
"Symfony\\Bridge\\Monolog\\": "src/",
"Symfony\\Bridge\\ProxyManager\\": "src/",
"Symfony\\Bridge\\Swiftmailer\\": "src/",
"Symfony\\Bridge\\Twig\\": "src/",
"Symfony\\Bundle\\": "src/",
"Symfony\\Component\\": "src/"
},
"classmap": [
"src/Symfony/Component/HttpFoundation/Resources/stubs",
"src/Symfony/Component/Intl/Resources/stubs"
],
"files": [ "src/Symfony/Component/Intl/Resources/stubs/functions.php" ]
},
"autoload-dev": {
"files": [ "src/Symfony/Bridge/PhpUnit/bootstrap.php" ]
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
Expand Down
Expand Up @@ -139,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$table = new Table($output);

// Display header line
$headers = array('State(s)', 'Id', sprintf('Message Preview (%s)', $locale));
$headers = array('State(s)', 'Domain', 'Id', sprintf('Message Preview (%s)', $locale));
foreach ($fallbackCatalogues as $fallbackCatalogue) {
$headers[] = sprintf('Fallback Message Preview (%s)', $fallbackCatalogue->getLocale());
}
Expand Down Expand Up @@ -172,7 +172,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$row = array($this->formatStates($states), $this->formatId($messageId), $this->sanitizeString($value));
$row = array($this->formatStates($states), $domain, $this->formatId($messageId), $this->sanitizeString($value));
foreach ($fallbackCatalogues as $fallbackCatalogue) {
$row[] = $this->sanitizeString($fallbackCatalogue->get($messageId, $domain));
}
Expand Down
Expand Up @@ -78,7 +78,7 @@ protected function configure()
EOF
)
->addArgument('arguments', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'A list of permissions and object identities (class name and ID separated by a column)')
->addOption('user', null, InputOption::VALUE_REQUIRED, 'A list of security identities')
->addOption('user', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A list of security identities')
->addOption('role', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A list of roles')
->addOption('class-scope', null, InputOption::VALUE_NONE, 'Use class-scope entries')
;
Expand Down
Expand Up @@ -37,6 +37,9 @@ public function process(ContainerBuilder $container)
$definition->setClass($parameterBag->resolveValue($definition->getClass()));
$definition->setFile($parameterBag->resolveValue($definition->getFile()));
$definition->setArguments($parameterBag->resolveValue($definition->getArguments()));
if ($definition->getFactoryClass(false)) {
$definition->setFactoryClass($parameterBag->resolveValue($definition->getFactoryClass()));
}

$calls = array();
foreach ($definition->getMethodCalls() as $name => $arguments) {
Expand Down
Expand Up @@ -1338,7 +1338,9 @@ private function dumpValue($value, $interpolate = true)
if (null !== $value->getFactoryClass(false)) {
return sprintf("call_user_func(array(%s, '%s')%s)", $this->dumpValue($value->getFactoryClass(false)), $value->getFactoryMethod(false), count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
} elseif (null !== $value->getFactoryService(false)) {
return sprintf("%s->%s(%s)", $this->getServiceCall($value->getFactoryService(false)), $value->getFactoryMethod(false), implode(', ', $arguments));
$service = $this->dumpValue($value->getFactoryService(false));

return sprintf("%s->%s(%s)", 0 === strpos($service, '$') ? sprintf('$this->get(%s)', $service) : $this->getServiceCall($value->getFactoryService(false)), $value->getFactoryMethod(false), implode(', ', $arguments));
} else {
throw new RuntimeException('Cannot dump definitions which have factory method without factory service or factory class.');
}
Expand Down
@@ -0,0 +1,91 @@
<?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\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class ResolveParameterPlaceHoldersPassTest extends \PHPUnit_Framework_TestCase
{
private $compilerPass;
private $container;
private $fooDefinition;

protected function setUp()
{
$this->compilerPass = new ResolveParameterPlaceHoldersPass();
$this->container = $this->createContainerBuilder();
$this->compilerPass->process($this->container);
$this->fooDefinition = $this->container->getDefinition('foo');
}

public function testClassParametersShouldBeResolved()
{
$this->assertSame('Foo', $this->fooDefinition->getClass());
}

public function testFactoryClassParametersShouldBeResolved()
{
$this->assertSame('FooFactory', $this->fooDefinition->getFactoryClass());
}

public function testArgumentParametersShouldBeResolved()
{
$this->assertSame(array('bar', 'baz'), $this->fooDefinition->getArguments());
}

public function testMethodCallParametersShouldBeResolved()
{
$this->assertSame(array(array('foobar', array('bar', 'baz'))), $this->fooDefinition->getMethodCalls());
}

public function testPropertyParametersShouldBeResolved()
{
$this->assertSame(array('bar' => 'baz'), $this->fooDefinition->getProperties());
}

public function testFileParametersShouldBeResolved()
{
$this->assertSame('foo.php', $this->fooDefinition->getFile());
}

public function testAliasParametersShouldBeResolved()
{
$this->assertSame('foo', $this->container->getAlias('bar')->__toString());
}

private function createContainerBuilder()
{
$containerBuilder = new ContainerBuilder();

$containerBuilder->setParameter('foo.class', 'Foo');
$containerBuilder->setParameter('foo.factory.class', 'FooFactory');
$containerBuilder->setParameter('foo.arg1', 'bar');
$containerBuilder->setParameter('foo.arg2', 'baz');
$containerBuilder->setParameter('foo.method', 'foobar');
$containerBuilder->setParameter('foo.property.name', 'bar');
$containerBuilder->setParameter('foo.property.value', 'baz');
$containerBuilder->setParameter('foo.file', 'foo.php');
$containerBuilder->setParameter('alias.id', 'bar');

$fooDefinition = $containerBuilder->register('foo', '%foo.class%');
$fooDefinition->setFactoryClass('%foo.factory.class%');
$fooDefinition->setArguments(array('%foo.arg1%', '%foo.arg2%'));
$fooDefinition->addMethodCall('%foo.method%', array('%foo.arg1%', '%foo.arg2%'));
$fooDefinition->setProperty('%foo.property.name%', '%foo.property.value%');
$fooDefinition->setFile('%foo.file%');

$containerBuilder->setAlias('%alias.id%', 'foo');

return $containerBuilder;
}
}
Expand Up @@ -333,6 +333,42 @@ public function testCreateServiceFactory()
$this->assertTrue($builder->get('baz')->called, '->createService() uses another service as factory');
}

public function testLegacyCreateServiceFactory()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);

$builder = new ContainerBuilder();
$builder->register('bar', 'Bar\FooClass');
$builder
->register('foo1', 'Bar\FooClass')
->setFactoryClass('%foo_class%')
->setFactoryMethod('getInstance')
->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')))
;
$builder->setParameter('value', 'bar');
$builder->setParameter('foo_class', 'Bar\FooClass');
$this->assertTrue($builder->get('foo1')->called, '->createService() calls the factory method to create the service instance');
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar')), $builder->get('foo1')->arguments, '->createService() passes the arguments to the factory method');
}

/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testLegacyCreateServiceFactoryService()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);

$builder = new ContainerBuilder();
$builder->register('foo_service', 'Bar\FooClass');
$builder
->register('foo', 'Bar\FooClass')
->setFactoryService('%foo_service%')
->setFactoryMethod('getInstance')
;
$builder->setParameter('foo_service', 'foo_service');
$this->assertTrue($builder->get('foo')->called, '->createService() calls the factory method to create the service instance');
}

/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
Expand Down
Expand Up @@ -83,20 +83,15 @@ public static function getSubscribedEvents()
*
* @param \Exception $exception The \Exception instance
* @param string $message The error message to log
* @param bool $original False when the handling of the exception thrown another exception
*/
protected function logException(\Exception $exception, $message, $original = true)
protected function logException(\Exception $exception, $message)
{
$isCritical = !$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500;
$context = array('exception' => $exception);
if (null !== $this->logger) {
if ($isCritical) {
$this->logger->critical($message, $context);
if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
$this->logger->critical($message, array('exception' => $exception));
} else {
$this->logger->error($message, $context);
$this->logger->error($message, array('exception' => $exception));
}
} elseif (!$original || $isCritical) {
error_log($message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/HttpKernel.php
Expand Up @@ -229,7 +229,7 @@ private function handleException(\Exception $e, $request, $type)
if (!$event->hasResponse()) {
$this->finishRequest($request, $type);

throw $e;
throw new \LogicException('No listeners of the "kernel.exception" event set a Response', 0, $e);
}

$response = $event->getResponse();
Expand Down
Expand Up @@ -102,8 +102,8 @@ public function testHandleRestoresThePreviousRequestOnException($type)
$this->fail('->handle() suppresses the controller exception');
} catch (\PHPUnit_Framework_Exception $exception) {
throw $exception;
} catch (\Exception $actual) {
$this->assertSame($expected, $actual, '->handle() throws the controller exception');
} catch (\LogicException $actual) {
$this->assertSame($expected, $actual->getPrevious(), '->handle() throws the controller exception, wrapped when no listener');
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php
Expand Up @@ -23,14 +23,17 @@

class HttpKernelTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \RuntimeException
*/
public function testHandleWhenControllerThrowsAnExceptionAndRawIsTrue()
{
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));

$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
$exception = new \RuntimeException();
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () use ($exception) { throw $exception; }));

try {
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
$this->fail('LogicException expected');
} catch (\LogicException $e) {
$this->assertSame($exception, $e->getPrevious());
}
}

/**
Expand Down Expand Up @@ -132,7 +135,7 @@ public function testHandleWhenNoControllerIsFound()
$dispatcher = new EventDispatcher();
$kernel = new HttpKernel($dispatcher, $this->getResolver(false));

$kernel->handle(new Request());
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
}

/**
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Component/Translation/Translator.php
Expand Up @@ -354,12 +354,6 @@ private function initializeCacheCatalogue($locale, $forceRefresh = false)
return;
}

if (null === $this->cacheDir) {
$this->initialize();

return $this->loadCatalogue($locale);
}

$this->assertValidLocale($locale);
$cache = new ConfigCache($this->cacheDir.'/catalogue.'.$locale.'.php', $this->debug);
if ($forceRefresh || !$cache->isFresh()) {
Expand Down

0 comments on commit 3ea8943

Please sign in to comment.