ApcCacheTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\Tests\Component\Validator\Mapping\Cache;
  11. use Symfony\Component\Validator\Mapping\Cache\ApcCache;
  12. class ApcCacheTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected function setUp()
  15. {
  16. if (!extension_loaded('apc')) {
  17. $this->markTestSkipped('APC is not loaded.');
  18. }
  19. }
  20. public function testWrite()
  21. {
  22. $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
  23. ->disableOriginalConstructor()
  24. ->setMethods(array('getClassName'))
  25. ->getMock();
  26. $meta->expects($this->once())
  27. ->method('getClassName')
  28. ->will($this->returnValue('bar'));
  29. $cache = new ApcCache('foo');
  30. $cache->write($meta);
  31. $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', apc_fetch('foobar'), '->write() stores metadata in APC');
  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. apc_delete('foobar');
  43. $cache = new ApcCache('foo');
  44. $this->assertFalse($cache->has('bar'), '->has() returns false when there is no entry');
  45. $cache->write($meta);
  46. $this->assertTrue($cache->has('bar'), '->has() returns true when the is an entry');
  47. }
  48. public function testRead()
  49. {
  50. $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
  51. ->disableOriginalConstructor()
  52. ->setMethods(array('getClassName'))
  53. ->getMock();
  54. $meta->expects($this->once())
  55. ->method('getClassName')
  56. ->will($this->returnValue('bar'));
  57. $cache = new ApcCache('foo');
  58. $cache->write($meta);
  59. $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', $cache->read('bar'), '->read() returns metadata');
  60. }
  61. }