From d67f090003de4b99b6706bad1485918cc1f66ed1 Mon Sep 17 00:00:00 2001 From: Dawid Nowak Date: Mon, 1 Aug 2016 17:57:55 +0200 Subject: [PATCH 1/9] SecurityBundle:BasicAuthenticationListener: removed a default argument on getting a header value it's unnecessary. --- .../Security/Http/Firewall/BasicAuthenticationListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php index ebe96ea2fb..5bbf13d9b8 100644 --- a/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/BasicAuthenticationListener.php @@ -56,7 +56,7 @@ class BasicAuthenticationListener implements ListenerInterface { $request = $event->getRequest(); - if (false === $username = $request->headers->get('PHP_AUTH_USER', false)) { + if (null === $username = $request->headers->get('PHP_AUTH_USER')) { return; } From fb36c5a575d905983e71a52f9bdfeb07e303e857 Mon Sep 17 00:00:00 2001 From: David Maicher Date: Wed, 10 Aug 2016 21:49:44 +0200 Subject: [PATCH 2/9] [Validator] fixed duplicate constraints with parent class interfaces This fixes https://github.com/symfony/symfony/issues/19516 --- .../Factory/LazyLoadingMetadataFactory.php | 4 +-- .../Validator/Tests/Fixtures/Entity.php | 2 +- .../Validator/Tests/Fixtures/EntityParent.php | 2 +- .../LazyLoadingMetadataFactoryTest.php | 35 ++++++++++++------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php b/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php index 6c5c277ed8..b5b202de6d 100644 --- a/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php +++ b/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php @@ -116,9 +116,9 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface $metadata->mergeConstraints($this->getMetadataFor($parent->name)); } - // Include constraints from all implemented interfaces + // Include constraints from all implemented interfaces that have not been processed via parent class yet foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) { - if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) { + if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name || ($parent && $parent->implementsInterface($interface->name))) { continue; } $metadata->mergeConstraints($this->getMetadataFor($interface->name)); diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/Entity.php b/src/Symfony/Component/Validator/Tests/Fixtures/Entity.php index b5e9e0c982..e4eec6be32 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/Entity.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/Entity.php @@ -19,7 +19,7 @@ use Symfony\Component\Validator\ExecutionContextInterface; * @Assert\GroupSequence({"Foo", "Entity"}) * @Assert\Callback({"Symfony\Component\Validator\Tests\Fixtures\CallbackClass", "callback"}) */ -class Entity extends EntityParent implements EntityInterface +class Entity extends EntityParent { /** * @Assert\NotNull diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/EntityParent.php b/src/Symfony/Component/Validator/Tests/Fixtures/EntityParent.php index 422bb28d0b..acbec3d32e 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/EntityParent.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/EntityParent.php @@ -13,7 +13,7 @@ namespace Symfony\Component\Validator\Tests\Fixtures; use Symfony\Component\Validator\Constraints\NotNull; -class EntityParent +class EntityParent implements EntityInterface { protected $firstName; private $internal; diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php index 74ee912cb7..c78d2a72c8 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php @@ -20,13 +20,15 @@ class LazyLoadingMetadataFactoryTest extends \PHPUnit_Framework_TestCase { const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity'; const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent'; + const INTERFACECLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityInterface'; - public function testLoadClassMetadata() + public function testLoadClassMetadataWithInterface() { $factory = new LazyLoadingMetadataFactory(new TestLoader()); $metadata = $factory->getMetadataFor(self::PARENTCLASS); $constraints = array( + new ConstraintA(array('groups' => array('Default', 'EntityInterface', 'EntityParent'))), new ConstraintA(array('groups' => array('Default', 'EntityParent'))), ); @@ -41,12 +43,13 @@ class LazyLoadingMetadataFactoryTest extends \PHPUnit_Framework_TestCase $constraints = array( new ConstraintA(array('groups' => array( 'Default', + 'EntityInterface', 'EntityParent', 'Entity', ))), new ConstraintA(array('groups' => array( 'Default', - 'EntityInterface', + 'EntityParent', 'Entity', ))), new ConstraintA(array('groups' => array( @@ -63,27 +66,36 @@ class LazyLoadingMetadataFactoryTest extends \PHPUnit_Framework_TestCase $cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface'); $factory = new LazyLoadingMetadataFactory(new TestLoader(), $cache); - $tester = $this; - $constraints = array( + $parentClassConstraints = array( + new ConstraintA(array('groups' => array('Default', 'EntityInterface', 'EntityParent'))), new ConstraintA(array('groups' => array('Default', 'EntityParent'))), ); + $interfaceConstraints = array(new ConstraintA(array('groups' => array('Default', 'EntityInterface')))); $cache->expects($this->never()) ->method('has'); - $cache->expects($this->once()) + $cache->expects($this->exactly(2)) ->method('read') - ->with($this->equalTo(self::PARENTCLASS)) + ->withConsecutive( + array($this->equalTo(self::PARENTCLASS)), + array($this->equalTo(self::INTERFACECLASS)) + ) ->will($this->returnValue(false)); - $cache->expects($this->once()) + $cache->expects($this->exactly(2)) ->method('write') - ->will($this->returnCallback(function ($metadata) use ($tester, $constraints) { - $tester->assertEquals($constraints, $metadata->getConstraints()); - })); + ->withConsecutive( + $this->callback(function ($metadata) use ($interfaceConstraints) { + return $interfaceConstraints == $metadata->getConstraints(); + }), + $this->callback(function ($metadata) use ($parentClassConstraints) { + return $parentClassConstraints == $metadata->getConstraints(); + }) + ); $metadata = $factory->getMetadataFor(self::PARENTCLASS); $this->assertEquals(self::PARENTCLASS, $metadata->getClassName()); - $this->assertEquals($constraints, $metadata->getConstraints()); + $this->assertEquals($parentClassConstraints, $metadata->getConstraints()); } public function testReadMetadataFromCache() @@ -92,7 +104,6 @@ class LazyLoadingMetadataFactoryTest extends \PHPUnit_Framework_TestCase $cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface'); $factory = new LazyLoadingMetadataFactory($loader, $cache); - $tester = $this; $metadata = new ClassMetadata(self::PARENTCLASS); $metadata->addConstraint(new ConstraintA()); From 20a69aa1cf2a547274cd0ae3fca8112f730ec3d2 Mon Sep 17 00:00:00 2001 From: JhonnyL Date: Tue, 23 Aug 2016 14:39:28 +0200 Subject: [PATCH 3/9] [FrameworkBundle] Remove duplicated code in RouterDebugCommand --- .../Bundle/FrameworkBundle/Command/RouterDebugCommand.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index 8c29492040..eb4407b8f8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -83,10 +83,10 @@ EOF $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)); } $this->convertController($route); @@ -96,8 +96,6 @@ EOF 'name' => $name, )); } else { - $routes = $this->getContainer()->get('router')->getRouteCollection(); - foreach ($routes as $route) { $this->convertController($route); } From fd27801cf1150f80839f5930a7b1faa9aef22369 Mon Sep 17 00:00:00 2001 From: JhonnyL Date: Tue, 23 Aug 2016 15:45:05 +0200 Subject: [PATCH 4/9] [FrameworkBundle] Remove TranslatorBagInterface check --- .../DependencyInjection/Compiler/LoggingTranslatorPass.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php index dda6bc2959..74d586bf3b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php @@ -26,11 +26,6 @@ class LoggingTranslatorPass implements CompilerPassInterface 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); From c811eb7e8ea44654d35153490e772836420442bd Mon Sep 17 00:00:00 2001 From: Tom Van Looy Date: Tue, 23 Aug 2016 21:36:25 +0200 Subject: [PATCH 5/9] remove duplicate instruction --- src/Symfony/Component/Finder/Tests/Iterator/MockSplFileInfo.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Component/Finder/Tests/Iterator/MockSplFileInfo.php b/src/Symfony/Component/Finder/Tests/Iterator/MockSplFileInfo.php index ec3f643e43..d03a9ac78e 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/MockSplFileInfo.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/MockSplFileInfo.php @@ -95,12 +95,10 @@ class MockSplFileInfo extends \SplFileInfo if (is_string($type)) { switch ($type) { case 'directory': - $this->type = self::TYPE_DIRECTORY; case 'd': $this->type = self::TYPE_DIRECTORY; break; case 'file': - $this->type = self::TYPE_FILE; case 'f': $this->type = self::TYPE_FILE; break; From b66ea5e16ebbc0e2da664e070309116bdcb808bf Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Fri, 12 Aug 2016 08:09:39 -0400 Subject: [PATCH 6/9] added friendly exception when constraint validator does not exist or it is not enabled --- .../Validator/ConstraintValidatorFactoryTest.php | 15 +++++++++++++++ .../Validator/ConstraintValidatorFactory.php | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php index b73c9f81fa..b61851bb0c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Validator/ConstraintValidatorFactoryTest.php @@ -62,4 +62,19 @@ class ConstraintValidatorFactoryTest extends \PHPUnit_Framework_TestCase $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); + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php b/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php index 66f0d012d3..4e36678212 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php +++ b/src/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php @@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; 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; /** @@ -61,6 +62,7 @@ class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface * * @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) @@ -68,6 +70,10 @@ class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface $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]); From acc04601006b166fc54a8660f1a05f25e1373ab4 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Wed, 24 Aug 2016 02:30:10 +0200 Subject: [PATCH 7/9] [DoctrineBridge] Enhance exception message in EntityUserProvider Typo/CS fixes Avoid checking Repository class as it is not always the default one Compromise Change wording Tests this method --- .../Security/User/EntityUserProvider.php | 2 +- .../Security/User/EntityUserProviderTest.php | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index cb8a594583..058eb7167e 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -51,7 +51,7 @@ class EntityUserProvider implements UserProviderInterface $user = $repository->findOneBy(array($this->property => $username)); } else { if (!$repository instanceof UserProviderInterface) { - throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement UserProviderInterface.', get_class($repository))); + 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))); } $user = $repository->loadUserByUsername($username); diff --git a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php index 6203b9dfb2..3c52a7d506 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php @@ -38,6 +38,65 @@ class EntityUserProviderTest extends \PHPUnit_Framework_TestCase $this->assertSame($user1, $provider->refreshUser($user1)); } + public function testLoadUserByUsername() + { + $em = DoctrineTestHelper::createTestEntityManager(); + $this->createSchema($em); + + $user = new User(1, 1, 'user1'); + + $em->persist($user); + $em->flush(); + + $provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name'); + + $this->assertSame($user, $provider->loadUserByUsername('user1')); + } + + public function testLoadUserByUsernameWithUserProviderRepositoryAndWithoutProperty() + { + $user = new User(1, 1, 'user1'); + + $repository = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface') + ->disableOriginalConstructor() + ->getMock(); + $repository + ->expects($this->once()) + ->method('loadUserByUsername') + ->with('user1') + ->willReturn($user); + + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + $em + ->expects($this->once()) + ->method('getRepository') + ->with('Symfony\Bridge\Doctrine\Tests\Fixtures\User') + ->willReturn($repository); + + $provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User'); + $this->assertSame($user, $provider->loadUserByUsername('user1')); + } + + /** + * @expectedException \InvalidArgumentException + * @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. + */ + public function testLoadUserByUsernameWithNonUserProviderRepositoryAndWithoutProperty() + { + $em = DoctrineTestHelper::createTestEntityManager(); + $this->createSchema($em); + + $user = new User(1, 1, 'user1'); + + $em->persist($user); + $em->flush(); + + $provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User'); + $provider->loadUserByUsername('user1'); + } + public function testRefreshUserRequiresId() { $em = DoctrineTestHelper::createTestEntityManager(); From fcd3345e3407dc672b47dccd72b6e754de0b4a51 Mon Sep 17 00:00:00 2001 From: Ener-Getick Date: Thu, 25 Aug 2016 14:47:32 +0200 Subject: [PATCH 8/9] [FrameworkBundle][Security] Remove useless mocks --- .../Tests/Templating/DelegatingEngineTest.php | 3 ++- .../DefaultAuthenticationFailureHandlerTest.php | 5 +++-- .../DefaultAuthenticationSuccessHandlerTest.php | 4 ++-- .../Tests/Authentication/SimpleAuthenticationHandlerTest.php | 3 ++- .../Tests/EntryPoint/FormAuthenticationEntryPointTest.php | 5 +++-- src/Symfony/Component/Security/Http/Tests/FirewallTest.php | 5 +++-- .../Http/Tests/Logout/DefaultLogoutSuccessHandlerTest.php | 3 ++- .../Security/Http/Tests/RememberMe/ResponseListenerTest.php | 3 ++- 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php index 0f88721813..4eaafddfa4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php @@ -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 { @@ -60,7 +61,7 @@ class DelegatingEngineTest extends \PHPUnit_Framework_TestCase 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') diff --git a/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php index 82b5533658..252b124031 100644 --- a/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Security\Http\Tests\Authentication; use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler; use Symfony\Component\Security\Core\Security; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCase @@ -52,7 +53,7 @@ class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCas ->method('createRequest')->with($this->request, '/login') ->will($this->returnValue($subRequest)); - $response = $this->getMock('Symfony\Component\HttpFoundation\Response'); + $response = new Response(); $this->httpKernel->expects($this->once()) ->method('handle')->with($subRequest, HttpKernelInterface::SUB_REQUEST) ->will($this->returnValue($response)); @@ -65,7 +66,7 @@ class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCas public function testRedirect() { - $response = $this->getMock('Symfony\Component\HttpFoundation\Response'); + $response = new Response(); $this->httpUtils->expects($this->once()) ->method('createRedirectResponse')->with($this->request, '/login') ->will($this->returnValue($response)); diff --git a/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php index 4d1847d0b7..ae9f02bad8 100644 --- a/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Security\Http\Tests\Authentication; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler; class DefaultAuthenticationSuccessHandlerTest extends \PHPUnit_Framework_TestCase @@ -157,8 +158,7 @@ class DefaultAuthenticationSuccessHandlerTest extends \PHPUnit_Framework_TestCas private function expectRedirectResponse($path) { - $response = $this->getMock('Symfony\Component\HttpFoundation\Response'); - + $response = new Response(); $this->httpUtils->expects($this->once()) ->method('createRedirectResponse') ->with($this->request, $path) diff --git a/src/Symfony/Component/Security/Http/Tests/Authentication/SimpleAuthenticationHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/Authentication/SimpleAuthenticationHandlerTest.php index 6e79b07a31..8a3188689b 100644 --- a/src/Symfony/Component/Security/Http/Tests/Authentication/SimpleAuthenticationHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Authentication/SimpleAuthenticationHandlerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Security\Http\Tests; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface; @@ -41,7 +42,7 @@ class SimpleAuthenticationHandlerTest extends \PHPUnit_Framework_TestCase // No methods are invoked on the exception; we just assert on its class $this->authenticationException = new AuthenticationException(); - $this->response = $this->getMock('Symfony\Component\HttpFoundation\Response'); + $this->response = new Response(); } public function testOnAuthenticationSuccessFallsBackToDefaultHandlerIfSimpleIsNotASuccessHandler() diff --git a/src/Symfony/Component/Security/Http/Tests/EntryPoint/FormAuthenticationEntryPointTest.php b/src/Symfony/Component/Security/Http/Tests/EntryPoint/FormAuthenticationEntryPointTest.php index 3acb9c2616..75a6be4dfa 100644 --- a/src/Symfony/Component/Security/Http/Tests/EntryPoint/FormAuthenticationEntryPointTest.php +++ b/src/Symfony/Component/Security/Http/Tests/EntryPoint/FormAuthenticationEntryPointTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Security\Http\Tests\EntryPoint; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Http\EntryPoint\FormAuthenticationEntryPoint; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -19,7 +20,7 @@ class FormAuthenticationEntryPointTest extends \PHPUnit_Framework_TestCase public function testStart() { $request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false); - $response = $this->getMock('Symfony\Component\HttpFoundation\Response'); + $response = new Response(); $httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils'); @@ -39,7 +40,7 @@ class FormAuthenticationEntryPointTest extends \PHPUnit_Framework_TestCase { $request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false); $subRequest = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false); - $response = new \Symfony\Component\HttpFoundation\Response('', 200); + $response = new Response('', 200); $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils'); $httpUtils diff --git a/src/Symfony/Component/Security/Http/Tests/FirewallTest.php b/src/Symfony/Component/Security/Http/Tests/FirewallTest.php index 9994737772..1e0c1ef0dd 100644 --- a/src/Symfony/Component/Security/Http/Tests/FirewallTest.php +++ b/src/Symfony/Component/Security/Http/Tests/FirewallTest.php @@ -11,9 +11,10 @@ namespace Symfony\Component\Security\Http\Tests; -use Symfony\Component\Security\Http\Firewall; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\Security\Http\Firewall; class FirewallTest extends \PHPUnit_Framework_TestCase { @@ -46,7 +47,7 @@ class FirewallTest extends \PHPUnit_Framework_TestCase public function testOnKernelRequestStopsWhenThereIsAResponse() { - $response = $this->getMock('Symfony\Component\HttpFoundation\Response'); + $response = new Response(); $first = $this->getMock('Symfony\Component\Security\Http\Firewall\ListenerInterface'); $first diff --git a/src/Symfony/Component/Security/Http/Tests/Logout/DefaultLogoutSuccessHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/Logout/DefaultLogoutSuccessHandlerTest.php index 381a48e57e..8a94e5332d 100644 --- a/src/Symfony/Component/Security/Http/Tests/Logout/DefaultLogoutSuccessHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Logout/DefaultLogoutSuccessHandlerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Security\Http\Tests\Logout; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Http\Logout\DefaultLogoutSuccessHandler; class DefaultLogoutSuccessHandlerTest extends \PHPUnit_Framework_TestCase @@ -18,7 +19,7 @@ class DefaultLogoutSuccessHandlerTest extends \PHPUnit_Framework_TestCase public function testLogout() { $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); - $response = $this->getMock('Symfony\Component\HttpFoundation\Response'); + $response = new Response(); $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils'); $httpUtils->expects($this->once()) diff --git a/src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php b/src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php index 78de8e4d54..23f7df70d3 100644 --- a/src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Http\RememberMe\ResponseListener; use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpKernel\KernelEvents; @@ -81,7 +82,7 @@ class ResponseListenerTest extends \PHPUnit_Framework_TestCase private function getResponse() { - $response = $this->getMock('Symfony\Component\HttpFoundation\Response'); + $response = new Response(); $response->headers = $this->getMock('Symfony\Component\HttpFoundation\ResponseHeaderBag'); return $response; From 54a7eff868cd9be8ebdaade0783b5f27f9cc276d Mon Sep 17 00:00:00 2001 From: Sandro Hopf Date: Thu, 21 Jul 2016 09:37:47 +0200 Subject: [PATCH 9/9] [Validator][GroupSequence] fixed GroupSequence validation ignores PropertyMetadata of parent classes --- .../Validator/Mapping/ClassMetadata.php | 1 + .../Tests/Mapping/ClassMetadataTest.php | 36 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php index 3f4f51b83b..5df8517a47 100644 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php @@ -350,6 +350,7 @@ class ClassMetadata extends ElementMetadata implements ClassMetadataInterface $member = clone $member; foreach ($member->getConstraints() as $constraint) { + $member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint; $constraint->addImplicitGroupName($this->getDefaultGroup()); } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php index a238b1754a..34c62445a4 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php @@ -138,16 +138,33 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase $this->metadata->mergeConstraints($parent); $this->metadata->addPropertyConstraint('firstName', new ConstraintA()); + $constraintA1 = new ConstraintA(array('groups' => array( + 'Default', + 'EntityParent', + 'Entity', + ))); + $constraintA2 = new ConstraintA(array('groups' => array( + 'Default', + 'Entity', + ))); + $constraints = array( - new ConstraintA(array('groups' => array( - 'Default', - 'EntityParent', - 'Entity', - ))), - new ConstraintA(array('groups' => array( - 'Default', - 'Entity', - ))), + $constraintA1, + $constraintA2, + ); + + $constraintsByGroup = array( + 'Default' => array( + $constraintA1, + $constraintA2, + ), + 'EntityParent' => array( + $constraintA1, + ), + 'Entity' => array( + $constraintA1, + $constraintA2, + ), ); $members = $this->metadata->getPropertyMetadata('firstName'); @@ -155,6 +172,7 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase $this->assertCount(1, $members); $this->assertEquals(self::PARENTCLASS, $members[0]->getClassName()); $this->assertEquals($constraints, $members[0]->getConstraints()); + $this->assertEquals($constraintsByGroup, $members[0]->constraintsByGroup); } public function testMemberMetadatas()