minor #33644 [Validator] fix tests (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Validator] fix tests

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Commits
-------

04f79c5536 fix tests
This commit is contained in:
Nicolas Grekas 2019-09-20 09:50:32 +02:00
commit 1818445dbc
1 changed files with 5 additions and 24 deletions

View File

@ -12,7 +12,9 @@
namespace Symfony\Component\Validator\Tests\Mapping\Factory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Mapping\Cache\Psr6Cache;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
@ -78,41 +80,20 @@ class LazyLoadingMetadataFactoryTest extends TestCase
public function testWriteMetadataToCache()
{
$cache = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Cache\CacheInterface')->getMock();
$cache = new Psr6Cache(new ArrayAdapter());
$factory = new LazyLoadingMetadataFactory(new TestLoader(), $cache);
$parentClassConstraints = [
new ConstraintA(['groups' => ['Default', 'EntityParent']]),
new ConstraintA(['groups' => ['Default', 'EntityInterfaceA', 'EntityParent']]),
];
$interfaceAConstraints = [
new ConstraintA(['groups' => ['Default', 'EntityInterfaceA']]),
];
$cache->expects($this->never())
->method('has');
$cache->expects($this->exactly(2))
->method('read')
->withConsecutive(
[$this->equalTo(self::PARENT_CLASS)],
[$this->equalTo(self::INTERFACE_A_CLASS)]
)
->willReturn(false);
$cache->expects($this->exactly(2))
->method('write')
->withConsecutive(
$this->callback(function ($metadata) use ($interfaceAConstraints) {
return $interfaceAConstraints == $metadata->getConstraints();
}),
$this->callback(function ($metadata) use ($parentClassConstraints) {
return $parentClassConstraints == $metadata->getConstraints();
})
);
$metadata = $factory->getMetadataFor(self::PARENT_CLASS);
$this->assertEquals(self::PARENT_CLASS, $metadata->getClassName());
$this->assertEquals($parentClassConstraints, $metadata->getConstraints());
$this->assertInstanceOf(ClassMetadata::class, $cache->read(self::PARENT_CLASS));
$this->assertInstanceOf(ClassMetadata::class, $cache->read(self::INTERFACE_A_CLASS));
}
public function testReadMetadataFromCache()