4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Tests\Mapping\Cache;
14 use Doctrine\Common\Cache\ArrayCache;
15 use PHPUnit\Framework\TestCase;
16 use Symfony\Component\Validator\Mapping\Cache\DoctrineCache;
18 class DoctrineCacheTest extends TestCase
22 public function testWrite()
24 $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
25 ->disableOriginalConstructor()
26 ->setMethods(array('getClassName'))
29 $meta->expects($this->once())
30 ->method('getClassName')
31 ->will($this->returnValue('bar'));
33 $this->cache->write($meta);
35 $this->assertInstanceOf(
36 'Symfony\\Component\\Validator\\Mapping\\ClassMetadata',
37 $this->cache->read('bar'),
38 'write() stores metadata'
42 public function testHas()
44 $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
45 ->disableOriginalConstructor()
46 ->setMethods(array('getClassName'))
49 $meta->expects($this->once())
50 ->method('getClassName')
51 ->will($this->returnValue('bar'));
53 $this->assertFalse($this->cache->has('bar'), 'has() returns false when there is no entry');
55 $this->cache->write($meta);
56 $this->assertTrue($this->cache->has('bar'), 'has() returns true when the is an entry');
59 public function testRead()
61 $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
62 ->disableOriginalConstructor()
63 ->setMethods(array('getClassName'))
66 $meta->expects($this->once())
67 ->method('getClassName')
68 ->will($this->returnValue('bar'));
70 $this->assertFalse($this->cache->read('bar'), 'read() returns false when there is no entry');
72 $this->cache->write($meta);
74 $this->assertInstanceOf(
75 'Symfony\\Component\\Validator\\Mapping\\ClassMetadata',
76 $this->cache->read('bar'),
77 'read() returns metadata'
81 protected function setUp()
83 $this->cache = new DoctrineCache(new ArrayCache());