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 PHPUnit\Framework\TestCase;
15 use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
16 use Symfony\Component\Validator\Mapping\ClassMetadata;
18 abstract class AbstractCacheTest extends TestCase
25 public function testWrite()
27 $meta = $this->getMockBuilder(ClassMetadata::class)
28 ->disableOriginalConstructor()
29 ->setMethods(array('getClassName'))
32 $meta->expects($this->once())
33 ->method('getClassName')
34 ->will($this->returnValue('Foo\\Bar'));
36 $this->cache->write($meta);
38 $this->assertInstanceOf(
40 $this->cache->read('Foo\\Bar'),
41 'write() stores metadata'
45 public function testHas()
47 $meta = $this->getMockBuilder(ClassMetadata::class)
48 ->disableOriginalConstructor()
49 ->setMethods(array('getClassName'))
52 $meta->expects($this->once())
53 ->method('getClassName')
54 ->will($this->returnValue('Foo\\Bar'));
56 $this->assertFalse($this->cache->has('Foo\\Bar'), 'has() returns false when there is no entry');
58 $this->cache->write($meta);
59 $this->assertTrue($this->cache->has('Foo\\Bar'), 'has() returns true when the is an entry');
62 public function testRead()
64 $meta = $this->getMockBuilder(ClassMetadata::class)
65 ->disableOriginalConstructor()
66 ->setMethods(array('getClassName'))
69 $meta->expects($this->once())
70 ->method('getClassName')
71 ->will($this->returnValue('Foo\\Bar'));
73 $this->assertFalse($this->cache->read('Foo\\Bar'), 'read() returns false when there is no entry');
75 $this->cache->write($meta);
77 $this->assertInstanceOf(ClassMetadata::class, $this->cache->read('Foo\\Bar'), 'read() returns metadata');