-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Validator] Fix issue 12302 - cache constraints #20740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Symfony\Component\Validator\Tests\Mapping\Factory; | ||
|
||
use Symfony\Component\Validator\Constraints\Callback; | ||
use Symfony\Component\Validator\Mapping\ClassMetadata; | ||
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; | ||
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface; | ||
|
@@ -30,8 +31,8 @@ public function testLoadClassMetadataWithInterface() | |
$metadata = $factory->getMetadataFor(self::PARENT_CLASS); | ||
|
||
$constraints = array( | ||
new ConstraintA(array('groups' => array('Default', 'EntityInterfaceA', 'EntityParent'))), | ||
new ConstraintA(array('groups' => array('Default', 'EntityParent'))), | ||
new ConstraintA(array('groups' => array('Default', 'EntityInterfaceA', 'EntityParent'))), | ||
); | ||
|
||
$this->assertEquals($constraints, $metadata->getConstraints()); | ||
|
@@ -43,10 +44,9 @@ public function testMergeParentConstraints() | |
$metadata = $factory->getMetadataFor(self::CLASS_NAME); | ||
|
||
$constraints = array( | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra line |
||
new ConstraintA(array('groups' => array( | ||
'Default', | ||
'EntityInterfaceA', | ||
'EntityParent', | ||
'Entity', | ||
))), | ||
new ConstraintA(array('groups' => array( | ||
|
@@ -56,8 +56,8 @@ public function testMergeParentConstraints() | |
))), | ||
new ConstraintA(array('groups' => array( | ||
'Default', | ||
'EntityParentInterface', | ||
'EntityInterfaceB', | ||
'EntityInterfaceA', | ||
'EntityParent', | ||
'Entity', | ||
))), | ||
new ConstraintA(array('groups' => array( | ||
|
@@ -67,8 +67,11 @@ public function testMergeParentConstraints() | |
))), | ||
new ConstraintA(array('groups' => array( | ||
'Default', | ||
'EntityParentInterface', | ||
'EntityInterfaceB', | ||
'Entity', | ||
))), | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra line |
||
); | ||
|
||
$this->assertEquals($constraints, $metadata->getConstraints()); | ||
|
@@ -80,8 +83,8 @@ public function testWriteMetadataToCache() | |
$factory = new LazyLoadingMetadataFactory(new TestLoader(), $cache); | ||
|
||
$parentClassConstraints = array( | ||
new ConstraintA(array('groups' => array('Default', 'EntityInterfaceA', 'EntityParent'))), | ||
new ConstraintA(array('groups' => array('Default', 'EntityParent'))), | ||
new ConstraintA(array('groups' => array('Default', 'EntityInterfaceA', 'EntityParent'))), | ||
); | ||
$interfaceAConstraints = array( | ||
new ConstraintA(array('groups' => array('Default', 'EntityInterfaceA'))), | ||
|
@@ -127,12 +130,43 @@ public function testReadMetadataFromCache() | |
|
||
$cache->expects($this->never()) | ||
->method('has'); | ||
$cache->expects($this->once()) | ||
$cache->expects($this->exactly(2)) | ||
->method('read') | ||
->will($this->returnValue($metadata)); | ||
->withConsecutive( | ||
array(self::PARENT_CLASS), | ||
array(self::INTERFACE_A_CLASS) | ||
) | ||
->willReturnCallback(function ($name) use ($metadata) { | ||
if (self::PARENT_CLASS == $name) { | ||
return $metadata; | ||
} | ||
|
||
return new ClassMetadata(self::INTERFACE_A_CLASS); | ||
}); | ||
|
||
$this->assertEquals($metadata, $factory->getMetadataFor(self::PARENT_CLASS)); | ||
} | ||
|
||
public function testMetadataCacheWithRuntimeConstraint() | ||
{ | ||
$cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface'); | ||
$factory = new LazyLoadingMetadataFactory(new TestLoader(), $cache); | ||
|
||
$cache | ||
->expects($this->any()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 spaces indendation (same below) |
||
->method('write') | ||
->will($this->returnCallback(function ($metadata) { serialize($metadata);})) | ||
; | ||
|
||
$cache->expects($this->any()) | ||
->method('read') | ||
->will($this->returnValue(false)); | ||
|
||
$metadata = $factory->getMetadataFor(self::PARENT_CLASS); | ||
$metadata->addConstraint(new Callback(function () {})); | ||
|
||
$metadata = $factory->getMetadataFor(self::CLASS_NAME); | ||
} | ||
} | ||
|
||
class TestLoader implements LoaderInterface | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be made private?