public function ClassMetadataFactoryTest::testWriteMetadataToCache

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Mapping/ClassMetadataFactoryTest.php, line 62

Class

ClassMetadataFactoryTest

Namespace

Symfony\Component\Validator\Tests\Mapping

Code

public function testWriteMetadataToCache() {
  $cache = $this
    ->getMock('Symfony\\Component\\Validator\\Mapping\\Cache\\CacheInterface');
  $factory = new ClassMetadataFactory(new TestLoader(), $cache);
  $tester = $this;
  $constraints = array(
    new ConstraintA(array(
      'groups' => array(
        'Default',
        'EntityParent',
      ),
    )),
  );
  $cache
    ->expects($this
    ->never())
    ->method('has');
  $cache
    ->expects($this
    ->once())
    ->method('read')
    ->with($this
    ->equalTo(self::PARENTCLASS))
    ->will($this
    ->returnValue(false));
  $cache
    ->expects($this
    ->once())
    ->method('write')
    ->will($this
    ->returnCallback(function ($metadata) use ($tester, $constraints) {
    $tester
      ->assertEquals($constraints, $metadata
      ->getConstraints());
  }));
  $metadata = $factory
    ->getMetadataFor(self::PARENTCLASS);
  $this
    ->assertEquals(self::PARENTCLASS, $metadata
    ->getClassName());
  $this
    ->assertEquals($constraints, $metadata
    ->getConstraints());
}