6083f65e28b6ab7ff15e747f838d93e3502e80dd
[yaffs-website] / vendor / symfony / validator / Tests / Mapping / Cache / AbstractCacheTest.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 PHPUnit\Framework\TestCase;
15 use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
16 use Symfony\Component\Validator\Mapping\ClassMetadata;
17
18 abstract class AbstractCacheTest extends TestCase
19 {
20     /**
21      * @var CacheInterface
22      */
23     protected $cache;
24
25     public function testWrite()
26     {
27         $meta = $this->getMockBuilder(ClassMetadata::class)
28             ->disableOriginalConstructor()
29             ->setMethods(array('getClassName'))
30             ->getMock();
31
32         $meta->expects($this->once())
33             ->method('getClassName')
34             ->will($this->returnValue('Foo\\Bar'));
35
36         $this->cache->write($meta);
37
38         $this->assertInstanceOf(
39             ClassMetadata::class,
40             $this->cache->read('Foo\\Bar'),
41             'write() stores metadata'
42         );
43     }
44
45     public function testHas()
46     {
47         $meta = $this->getMockBuilder(ClassMetadata::class)
48             ->disableOriginalConstructor()
49             ->setMethods(array('getClassName'))
50             ->getMock();
51
52         $meta->expects($this->once())
53             ->method('getClassName')
54             ->will($this->returnValue('Foo\\Bar'));
55
56         $this->assertFalse($this->cache->has('Foo\\Bar'), 'has() returns false when there is no entry');
57
58         $this->cache->write($meta);
59         $this->assertTrue($this->cache->has('Foo\\Bar'), 'has() returns true when the is an entry');
60     }
61
62     public function testRead()
63     {
64         $meta = $this->getMockBuilder(ClassMetadata::class)
65             ->disableOriginalConstructor()
66             ->setMethods(array('getClassName'))
67             ->getMock();
68
69         $meta->expects($this->once())
70             ->method('getClassName')
71             ->will($this->returnValue('Foo\\Bar'));
72
73         $this->assertFalse($this->cache->read('Foo\\Bar'), 'read() returns false when there is no entry');
74
75         $this->cache->write($meta);
76
77         $this->assertInstanceOf(ClassMetadata::class, $this->cache->read('Foo\\Bar'), 'read() returns metadata');
78     }
79 }