Skip to content

Commit

Permalink
Merge branch '3.1'
Browse files Browse the repository at this point in the history
* 3.1:
  fix typo
  add "provides" for psr/cache-implementation
  [Validator][GroupSequence] fixed GroupSequence validation ignores PropertyMetadata of parent classes
  [FrameworkBundle][Security] Remove useless mocks
  Add symfony/inflector to composer.json "replaces"
  [DoctrineBridge] Enhance exception message in EntityUserProvider
  added friendly exception when constraint validator does not exist or it is not enabled
  remove duplicate instruction
  [FrameworkBundle] Remove TranslatorBagInterface check
  [FrameworkBundle] Remove duplicated code in RouterDebugCommand
  [Validator] fixed duplicate constraints with parent class interfaces
  SecurityBundle:BasicAuthenticationListener: removed a default argument on getting a header value
  • Loading branch information
nicolas-grekas committed Aug 26, 2016
2 parents 39fd0e2 + 5767d6a commit a5afce6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
6 changes: 2 additions & 4 deletions Command/RouterDebugCommand.php
Expand Up @@ -78,10 +78,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new SymfonyStyle($input, $output);
$name = $input->getArgument('name');
$helper = new DescriptorHelper();
$routes = $this->getContainer()->get('router')->getRouteCollection();

if ($name) {
$route = $this->getContainer()->get('router')->getRouteCollection()->get($name);
if (!$route) {
if (!$route = $routes->get($name)) {
throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
}

Expand All @@ -94,8 +94,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
'output' => $io,
));
} else {
$routes = $this->getContainer()->get('router')->getRouteCollection();

foreach ($routes as $route) {
$this->convertController($route);
}
Expand Down
5 changes: 0 additions & 5 deletions DependencyInjection/Compiler/LoggingTranslatorPass.php
Expand Up @@ -26,11 +26,6 @@ public function process(ContainerBuilder $container)
return;
}

// skip if the symfony/translation version is lower than 2.6
if (!interface_exists('Symfony\Component\Translation\TranslatorBagInterface')) {
return;
}

if ($container->hasParameter('translator.logging') && $container->getParameter('translator.logging')) {
$translatorAlias = $container->getAlias('translator');
$definition = $container->getDefinition((string) $translatorAlias);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Templating/DelegatingEngineTest.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;

use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
use Symfony\Component\HttpFoundation\Response;

class DelegatingEngineTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -60,7 +61,7 @@ public function testGetInvalidEngine()

public function testRenderResponseWithFrameworkEngine()
{
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
$response = new Response();
$engine = $this->getFrameworkEngineMock('template.php', true);
$engine->expects($this->once())
->method('renderResponse')
Expand Down
15 changes: 15 additions & 0 deletions Tests/Validator/ConstraintValidatorFactoryTest.php
Expand Up @@ -62,4 +62,19 @@ public function testGetInstanceReturnsService()
$factory = new ConstraintValidatorFactory($container, array('validator_constraint_alias' => 'validator_constraint_service'));
$this->assertSame($validator, $factory->getInstance($constraint));
}

/**
* @expectedException \Symfony\Component\Validator\Exception\ValidatorException
*/
public function testGetInstanceInvalidValidatorClass()
{
$constraint = $this->getMock('Symfony\\Component\\Validator\\Constraint');
$constraint
->expects($this->once())
->method('validatedBy')
->will($this->returnValue('Fully\\Qualified\\ConstraintValidator\\Class\\Name'));

$factory = new ConstraintValidatorFactory(new Container());
$factory->getInstance($constraint);
}
}
6 changes: 6 additions & 0 deletions Validator/ConstraintValidatorFactory.php
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
Expand Down Expand Up @@ -61,13 +62,18 @@ public function __construct(ContainerInterface $container, array $validators = a
*
* @return ConstraintValidatorInterface A validator for the supplied constraint
*
* @throws ValidatorException When the validator class does not exist
* @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
*/
public function getInstance(Constraint $constraint)
{
$name = $constraint->validatedBy();

if (!isset($this->validators[$name])) {
if (!class_exists($name)) {
throw new ValidatorException(sprintf('Constraint validator "%s" does not exist or it is not enabled. Check the "validatedBy" method in your constraint class "%s".', $name, get_class($constraint)));
}

$this->validators[$name] = new $name();
} elseif (is_string($this->validators[$name])) {
$this->validators[$name] = $this->container->get($this->validators[$name]);
Expand Down

0 comments on commit a5afce6

Please sign in to comment.