DoctrineCacheTest.php 2.5 KB

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