Skip to content

Commit

Permalink
Merge branch '2.7' into 2.8
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicolas-grekas committed Aug 26, 2016
2 parents 69fbdc9 + af81c8c commit b05de7d
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 50 deletions.
Expand Up @@ -52,7 +52,7 @@ public function loadUserByUsername($username)
} else {
if (!$repository instanceof UserLoaderInterface) {
if (!$repository instanceof UserProviderInterface) {
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.', 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)));
}

@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);
Expand Down
Expand Up @@ -38,6 +38,68 @@ public function testRefreshUserGetsUserByPrimaryKey()
$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'));
}

/**
* @group legacy
*/
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();
Expand Down
Expand Up @@ -86,10 +86,10 @@ protected function execute(InputInterface $input, OutputInterface $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 @@ -102,8 +102,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
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
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
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);
}
}
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
Expand Up @@ -95,12 +95,10 @@ public function setType($type)
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;
Expand Down
Expand Up @@ -56,7 +56,7 @@ public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();

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

Expand Down
Expand Up @@ -13,6 +13,7 @@

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
Expand Down Expand Up @@ -47,7 +48,7 @@ public function testForward()
->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));
Expand All @@ -60,7 +61,7 @@ public function testForward()

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));
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -171,8 +172,7 @@ public function testRefererTargetPathIsIgnoredByDefault()

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)
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -41,7 +42,7 @@ protected function setUp()
// 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()
Expand Down
Expand Up @@ -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;

Expand All @@ -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');
Expand All @@ -39,7 +40,7 @@ public function testStartWithUseForward()
{
$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
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Security/Http/Tests/FirewallTest.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -46,7 +47,7 @@ public function testOnKernelRequestRegistersExceptionListener()

public function testOnKernelRequestStopsWhenThereIsAResponse()
{
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
$response = new Response();

$first = $this->getMock('Symfony\Component\Security\Http\Firewall\ListenerInterface');
$first
Expand Down
Expand Up @@ -11,14 +11,15 @@

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
{
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())
Expand Down
Expand Up @@ -15,6 +15,7 @@
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;

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

private function getResponse()
{
$response = $this->getMock('Symfony\Component\HttpFoundation\Response');
$response = new Response();
$response->headers = $this->getMock('Symfony\Component\HttpFoundation\ResponseHeaderBag');

return $response;
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Expand Up @@ -350,6 +350,7 @@ public function mergeConstraints(ClassMetadata $source)
$member = clone $member;

foreach ($member->getConstraints() as $constraint) {
$member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint;
$constraint->addImplicitGroupName($this->getDefaultGroup());
}

Expand Down
Expand Up @@ -116,9 +116,9 @@ public function getMetadataFor($value)
$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));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Tests/Fixtures/Entity.php
Expand Up @@ -19,7 +19,7 @@
* @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
Expand Down
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\Validator\Constraints\NotNull;

class EntityParent
class EntityParent implements EntityInterface
{
protected $firstName;
private $internal;
Expand Down

0 comments on commit b05de7d

Please sign in to comment.