You are here

public function LazyLoadingMetadataFactoryTest::testWriteMetadataToCache in Plug 7

File

lib/Symfony/validator/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php, line 61

Class

LazyLoadingMetadataFactoryTest

Namespace

Symfony\Component\Validator\Tests\Mapping\Factory

Code

public function testWriteMetadataToCache() {
  $cache = $this
    ->getMock('Symfony\\Component\\Validator\\Mapping\\Cache\\CacheInterface');
  $factory = new LazyLoadingMetadataFactory(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());
}