Skip to content

Commit 0cf50e2

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 98051e9 + 224ebc0 commit 0cf50e2

23 files changed

+136
-48
lines changed

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"symfony/framework-bundle": "self.version",
4949
"symfony/http-foundation": "self.version",
5050
"symfony/http-kernel": "self.version",
51+
"symfony/inflector": "self.version",
5152
"symfony/intl": "self.version",
5253
"symfony/ldap": "self.version",
5354
"symfony/monolog-bridge": "self.version",
@@ -94,6 +95,9 @@
9495
"phpdocumentor/reflection-docblock": "<3.0",
9596
"phpdocumentor/type-resolver": "<0.2.0"
9697
},
98+
"provide": {
99+
"psr/cache-implementation": "1.0"
100+
},
97101
"autoload": {
98102
"psr-4": {
99103
"Symfony\\Bridge\\Doctrine\\": "src/Symfony/Bridge/Doctrine/",

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function loadUserByUsername($username)
5151
$user = $repository->findOneBy(array($this->property => $username));
5252
} else {
5353
if (!$repository instanceof UserLoaderInterface) {
54-
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.', get_class($repository)));
54+
throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Component\Security\Core\User\UserProviderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, get_class($repository)));
5555
}
5656

5757
$user = $repository->loadUserByUsername($username);

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,39 @@ public function testRefreshUserGetsUserByPrimaryKey()
3838
$this->assertSame($user1, $provider->refreshUser($user1));
3939
}
4040

41+
public function testLoadUserByUsername()
42+
{
43+
$em = DoctrineTestHelper::createTestEntityManager();
44+
$this->createSchema($em);
45+
46+
$user = new User(1, 1, 'user1');
47+
48+
$em->persist($user);
49+
$em->flush();
50+
51+
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
52+
53+
$this->assertSame($user, $provider->loadUserByUsername('user1'));
54+
}
55+
56+
/**
57+
* @expectedException \InvalidArgumentException
58+
* @expectedExceptionMessage You must either make the "Symfony\Bridge\Doctrine\Tests\Fixtures\User" entity Doctrine Repository ("Doctrine\ORM\EntityRepository") implement "Symfony\Component\Security\Core\User\UserProviderInterface" or set the "property" option in the corresponding entity provider configuration.
59+
*/
60+
public function testLoadUserByUsernameWithNonUserProviderRepositoryAndWithoutProperty()
61+
{
62+
$em = DoctrineTestHelper::createTestEntityManager();
63+
$this->createSchema($em);
64+
65+
$user = new User(1, 1, 'user1');
66+
67+
$em->persist($user);
68+
$em->flush();
69+
70+
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User');
71+
$provider->loadUserByUsername('user1');
72+
}
73+
4174
public function testRefreshUserRequiresId()
4275
{
4376
$em = DoctrineTestHelper::createTestEntityManager();

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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);

src/Symfony/Bundle/FrameworkBundle/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')

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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]);

src/Symfony/Component/Finder/Tests/Iterator/MockSplFileInfo.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,10 @@ public function setType($type)
9595
if (is_string($type)) {
9696
switch ($type) {
9797
case 'directory':
98-
$this->type = self::TYPE_DIRECTORY;
9998
case 'd':
10099
$this->type = self::TYPE_DIRECTORY;
101100
break;
102101
case 'file':
103-
$this->type = self::TYPE_FILE;
104102
case 'f':
105103
$this->type = self::TYPE_FILE;
106104
break;

src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function handle(GetResponseEvent $event)
5656
{
5757
$request = $event->getRequest();
5858

59-
if (false === $username = $request->headers->get('PHP_AUTH_USER', false)) {
59+
if (null === $username = $request->headers->get('PHP_AUTH_USER')) {
6060
return;
6161
}
6262

0 commit comments

Comments
 (0)