19b29227d6d8d6f0451d25f0ba8c274dad081da7
[yaffs-website] / vendor / symfony / validator / Tests / Mapping / Cache / DoctrineCacheTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Tests\Mapping\Cache;
13
14 use Doctrine\Common\Cache\ArrayCache;
15 use PHPUnit\Framework\TestCase;
16 use Symfony\Component\Validator\Mapping\Cache\DoctrineCache;
17
18 class DoctrineCacheTest extends TestCase
19 {
20     private $cache;
21
22     public function testWrite()
23     {
24         $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
25             ->disableOriginalConstructor()
26             ->setMethods(array('getClassName'))
27             ->getMock();
28
29         $meta->expects($this->once())
30             ->method('getClassName')
31             ->will($this->returnValue('bar'));
32
33         $this->cache->write($meta);
34
35         $this->assertInstanceOf(
36             'Symfony\\Component\\Validator\\Mapping\\ClassMetadata',
37             $this->cache->read('bar'),
38             'write() stores metadata'
39         );
40     }
41
42     public function testHas()
43     {
44         $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
45             ->disableOriginalConstructor()
46             ->setMethods(array('getClassName'))
47             ->getMock();
48
49         $meta->expects($this->once())
50             ->method('getClassName')
51             ->will($this->returnValue('bar'));
52
53         $this->assertFalse($this->cache->has('bar'), 'has() returns false when there is no entry');
54
55         $this->cache->write($meta);
56         $this->assertTrue($this->cache->has('bar'), 'has() returns true when the is an entry');
57     }
58
59     public function testRead()
60     {
61         $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
62             ->disableOriginalConstructor()
63             ->setMethods(array('getClassName'))
64             ->getMock();
65
66         $meta->expects($this->once())
67             ->method('getClassName')
68             ->will($this->returnValue('bar'));
69
70         $this->assertFalse($this->cache->read('bar'), 'read() returns false when there is no entry');
71
72         $this->cache->write($meta);
73
74         $this->assertInstanceOf(
75             'Symfony\\Component\\Validator\\Mapping\\ClassMetadata',
76             $this->cache->read('bar'),
77             'read() returns metadata'
78         );
79     }
80
81     protected function setUp()
82     {
83         $this->cache = new DoctrineCache(new ArrayCache());
84     }
85 }