8000 Merge branch '2.7' into 2.8 · symfony/symfony@b05de7d · GitHub
[go: up one dir, main page]

Skip to content

Commit b05de7d

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Validator][GroupSequence] fixed GroupSequence validation ignores PropertyMetadata of parent classes [FrameworkBundle][Security] Remove useless mocks [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 69fbdc9 + af81c8c commit b05de7d

22 files changed

+161
-50
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function loadUserByUsername($username)
5252
} else {
5353
if (!$repository instanceof UserLoaderInterface) {
5454
if (!$repository instanceof UserProviderInterface) {
55-
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.', get_class($repository)));
55+
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)));
5656
}
5757

5858
@trigger_error('Implementing loadUserByUsername from Symfony\Component\Security\Core\User\UserProviderInterface is deprecated since version 2.8 and will be removed in 3.0. Implement the Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface instead.', E_USER_DEPRECATED);

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,68 @@ 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+
* @group legacy
58+
*/
59+
public function testLoadUserByUsernameWithUserProviderRepositoryAndWithoutProperty()
60+
{
61+
$user = new User(1, 1, 'user1');
62+
63+
$repository = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')
64+
->disableOriginalConstructor()
65+
->getMock();
66+
$repository
67+
->expects($this->once())
68+
->method('loadUserByUsername')
69+
->with('user1')
70+
->willReturn($user);
71+
72+
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
73+
->disableOriginalConstructor()
74+
->getMock();
75+
$em
76+
->expects($this->once())
77+
->method('getRepository')
78+
->with('Symfony\Bridge\Doctrine\Tests\Fixtures\User')
79+
->willReturn($repository);
80+
81+
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User');
82+
$this->assertSame($user, $provider->loadUserByUsername('user1'));
83+
}
84+
85+
/**
86+
* @expectedException \InvalidArgumentException
87+
* @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.
88+
*/
89+
public function testLoadUserByUsernameWithNonUserProviderRepositoryAndWithoutProperty()
90+
{
91+
$em = DoctrineTestHelper::createTestEntityManager();
92+
$this->createSchema($em);
93+
94+
$user = new User(1, 1, 'user1');
95+
96+
$em->persist($user);
97+
$em->flush();
98+
99+
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User');
100+
$provider->loadUserByUsername('user1');
101+
}
102+
41103
public function testRefreshUserRequiresId()
42104
{
43105
$em = DoctrineTestHelper::createTestEntityManager();

src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
8686

8787
$name = $input->getArgument('name');
8888
$helper = new DescriptorHelper();
89+
$routes = $this->getContainer()->get('router')->getRouteCollection();
8990

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

@@ -102,8 +102,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
102102
'output' => $io,
103103
));
104104
} else {
105-
$routes = $this->getContainer()->get('router')->getRouteCollection();
106-
107105
foreach ($routes as $route) {
108106
$this->convertController($route);
109107
}

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

src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
1515
use Symfony\Component\Security\Core\Security;
16+
use Symfony\Component\HttpFoundation\Response;
1617
use Symfony\Component\HttpKernel\HttpKernelInterface;
1718

1819
class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCase
@@ -47,7 +48,7 @@ public function testForward()
4748
->method('createRequest')->with($this->request, '/login')
4849
->will($this->returnValue($subRequest));
4950

50-
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
51+
$response = new Response();
5152
$this->httpKernel->expects($this->once())
5253
->method('handle')->with($subRequest, HttpKernelInterface::SUB_REQUEST)
5354
->will($this->returnValue($response));
@@ -60,7 +61,7 @@ public function testForward()
6061

6162
public function testRedirect()
6263
{
63-
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
64+
$response = new Response();
6465
$this->httpUtils->expects($this->once())
6566
->method('createRedirectResponse')->with($this->request, '/login')
6667
->will($this->returnValue($response));

src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\Authentication;
1313

14+
use Symfony\Component\HttpFoundation\Response;
1415
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
1516

1617
class DefaultAuthenticationSuccessHandlerTest extends \PHPUnit_Framework_TestCase
@@ -171,8 +172,7 @@ public function testRefererTargetPathIsIgnoredByDefault()
171172

172173
private function expectRedirectResponse($path)
173174
{
174-
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
175-
175+
$response = new Response();
176176
$this->httpUtils->expects($this->once())
177177
->method('createRedirectResponse')
178178
->with($this->request, $path)

src/Symfony/Component/Security/Http/Tests/Authentication/SimpleAuthenticationHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests;
1313

14+
use Symfony\Component\HttpFoundation\Response;
1415
use Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface;
1516
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1617
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
@@ -41,7 +42,7 @@ protected function setUp()
4142
// No methods are invoked on the exception; we just assert on its class
4243
$this->authenticationException = new AuthenticationException();
4344

44-
$this->response = $this->getMock('Symfony\Component\HttpFoundation\Response');
45+
$this->response = new Response();
4546
}
4647

4748
public function testOnAuthenticationSuccessFallsBackToDefaultHandlerIfSimpleIsNotASuccessHandler()

src/Symfony/Component/Security/Http/Tests/EntryPoint/FormAuthenticationEntryPointTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\EntryPoint;
1313

14+
use Symfony\Component\HttpFoundation\Response;
1415
use Symfony\Component\Security\Http\EntryPoint\FormAuthenticationEntryPoint;
1516
use Symfony\Component\HttpKernel\HttpKernelInterface;
1617

@@ -19,7 +20,7 @@ class FormAuthenticationEntryPointTest extends \PHPUnit_Framework_TestCase
1920
public 10000 function testStart()
2021
{
2122
$request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
22-
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
23+
$response = new Response();
2324

2425
$httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
2526
$httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
@@ -39,7 +40,7 @@ public function testStartWithUseForward()
3940
{
4041
$request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
4142
$subRequest = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
42-
$response = new \Symfony\Component\HttpFoundation\Response('', 200);
43+
$response = new Response('', 200);
4344

4445
$httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
4546
$httpUtils

src/Symfony/Component/Security/Http/Tests/FirewallTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests;
1313

14-
use Symfony\Component\Security\Http\Firewall;
14+
use Symfony\Component\HttpFoundation\Response;
1515
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1616
use Symfony\Component\HttpKernel\HttpKernelInterface;
17+
use Symfony\Component\Security\Http\Firewall;
1718

1819
class FirewallTest extends \PHPUnit_Framework_TestCase
1920
{
@@ -46,7 +47,7 @@ public function testOnKernelRequestRegistersExceptionListener()
4647

4748
public function testOnKernelRequestStopsWhenThereIsAResponse()
4849
{
49-
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
50+
$response = new Response();
5051

5152
$first = $this->getMock('Symfony\Component\Security\Http\Firewall\ListenerInterface');
5253
$first

src/Symfony/Component/Security/Http/Tests/Logout/DefaultLogoutSuccessHandlerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\Logout;
1313

14+
use Symfony\Component\HttpFoundation\Response;
1415
use Symfony\Component\Security\Http\Logout\DefaultLogoutSuccessHandler;
1516

1617
class DefaultLogoutSuccessHandlerTest extends \PHPUnit_Framework_TestCase
1718
{
1819
public function testLogout()
1920
{
2021
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
21-
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
22+
$response = new Response();
2223

2324
$httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
2425
$httpUtils->expects($this->once())

src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Security\Http\RememberMe\ResponseListener;
1616
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
1717
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpFoundation\Response;
1819
use Symfony\Component\HttpFoundation\Cookie;
1920
use Symfony\Component\HttpKernel\KernelEvents;
2021

@@ -81,7 +82,7 @@ private function getRequest(array $attributes = array())
8182

8283
private function getResponse()
8384
{
84-
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
85+
$response = new Response();
8586
$response->headers = $this->getMock('Symfony\Component\HttpFoundation\ResponseHeaderBag');
8687

8788
return $response;

src/Symfony/Component/Validator/Mapping/ClassMetadata.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ public function mergeConstraints(ClassMetadata $source)
350350
$member = clone $member;
351351

352352
foreach ($member->getConstraints() as $constraint) {
353+
$member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint;
353354
$constraint->addImplicitGroupName($this->getDefaultGroup());
354355
}
355356

src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ public function getMetadataFor($value)
116116
$metadata->mergeConstraints($this->getMetadataFor($parent->name));
117117
}
118118

119-
// Include constraints from all implemented interfaces
119+
// Include constraints from all implemented interfaces that have not been processed via parent class yet
120120
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
121-
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) {
121+
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name || ($parent && $parent->implementsInterface($interface->name))) {
122122
continue;
123123
}
124124
$metadata->mergeConstraints($this->getMetadataFor($interface->name));

src/Symfony/Component/Validator/Tests/Fixtures/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @Assert\GroupSequence({"Foo", "Entity"})
2020
* @Assert\Callback({"Symfony\Component\Validator\Tests\Fixtures\CallbackClass", "callback"})
2121
*/
22-
class Entity extends EntityParent implements EntityInterface
22+
class Entity extends EntityParent
2323
{
2424
/**
2525
* @Assert\NotNull

src/Symfony/Component/Validator/Tests/Fixtures/EntityParent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Validator\Constraints\NotNull;
1515

16-
class EntityParent
16+
class EntityParent implements EntityInterface
1717
{
1818
protected $firstName;
1919
private $internal;

0 commit comments

Comments
 (0)
0