Skip to content

Commit a5afce6

Browse files
Merge branch '3.1'
* 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
2 parents 39fd0e2 + 5767d6a commit a5afce6

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

Command/RouterDebugCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
7878
$io = new SymfonyStyle($input, $output);
7979
$name = $input->getArgument('name');
8080
$helper = new DescriptorHelper();
81+
$routes = $this->getContainer()->get('router')->getRouteCollection();
8182

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

@@ -94,8 +94,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
9494
'output' => $io,
9595
));
9696
} else {
97-
$routes = $this->getContainer()->get('router')->getRouteCollection();
98-
9997
foreach ($routes as $route) {
10098
$this->convertController($route);
10199
}

DependencyInjection/Compiler/LoggingTranslatorPass.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ public function process(ContainerBuilder $container)
2626
return;
2727
}
2828

29-
// skip if the symfony/translation version is lower than 2.6
30-
if (!interface_exists('Symfony\Component\Translation\TranslatorBagInterface')) {
31-
return;
32-
}
33-
3429
if ($container->hasParameter('translator.logging') && $container->getParameter('translator.logging')) {
3530
$translatorAlias = $container->getAlias('translator');
3631
$definition = $container->getDefinition((string) $translatorAlias);

Tests/Templating/DelegatingEngineTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
1313

1414
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
15+
use Symfony\Component\HttpFoundation\Response;
1516

1617
class DelegatingEngineTest extends \PHPUnit_Framework_TestCase
1718
{
@@ -60,7 +61,7 @@ public function testGetInvalidEngine()
6061

6162
public function testRenderResponseWithFrameworkEngine()
6263
{
63-
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
64+
$response = new Response();
6465
$engine = $this->getFrameworkEngineMock('template.php', true);
6566
$engine->expects($this->once())
6667
->method('renderResponse')

Tests/Validator/ConstraintValidatorFactoryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,19 @@ public function testGetInstanceReturnsService()
6262
$factory = new ConstraintValidatorFactory($container, array('validator_constraint_alias' => 'validator_constraint_service'));
6363
$this->assertSame($validator, $factory->getInstance($constraint));
6464
}
65+
66+
/**
67+
* @expectedException \Symfony\Component\Validator\Exception\ValidatorException
68+
*/
69+
public function testGetInstanceInvalidValidatorClass()
70+
{
71+
$constraint = $this->getMock('Symfony\\Component\\Validator\\Constraint');
72+
$constraint
73+
->expects($this->once())
74+
->method('validatedBy')
75+
->will($this->returnValue('Fully\\Qualified\\ConstraintValidator\\Class\\Name'));
76+
77+
$factory = new ConstraintValidatorFactory(new Container());
78+
$factory->getInstance($constraint);
79+
}
6580
}

Validator/ConstraintValidatorFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Validator\Constraint;
1616
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
1717
use Symfony\Component\Validator\ConstraintValidatorInterface;
18+
use Symfony\Component\Validator\Exception\ValidatorException;
1819
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1920

2021
/**
@@ -61,13 +62,18 @@ public function __construct(ContainerInterface $container, array $validators = a
6162
*
6263
* @return ConstraintValidatorInterface A validator for the supplied constraint
6364
*
65+
* @throws ValidatorException When the validator class does not exist
6466
* @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
6567
*/
6668
public function getInstance(Constraint $constraint)
6769
{
6870
$name = $constraint->validatedBy();
6971

7072
if (!isset($this->validators[$name])) {
73+
if (!class_exists($name)) {
74+
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)));
75+
}
76+
7177
$this->validators[$name] = new $name();
7278
} elseif (is_string($this->validators[$name])) {
7379
$this->validators[$name] = $this->container->get($this->validators[$name]);

0 commit comments

Comments
 (0)