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
This commit is contained in:
commit
b05de7d2be
@ -52,7 +52,7 @@ class EntityUserProvider implements UserProviderInterface
|
||||
} 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);
|
||||
|
@ -38,6 +38,68 @@ 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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
@ -86,10 +86,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));
|
||||
}
|
||||
|
||||
@ -102,8 +102,6 @@ EOF
|
||||
'output' => $io,
|
||||
));
|
||||
} else {
|
||||
$routes = $this->getContainer()->get('router')->getRouteCollection();
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->convertController($route);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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')
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
@ -47,7 +48,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));
|
||||
@ -60,7 +61,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));
|
||||
|
@ -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
|
||||
@ -171,8 +172,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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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());
|
||||
|
||||
|
Reference in New Issue
Block a user