LegacyApcCacheTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Validator\Mapping\Cache\ApcCache;
  13. /**
  14. * @group legacy
  15. * @requires extension apc
  16. */
  17. class LegacyApcCacheTest extends TestCase
  18. {
  19. protected function setUp()
  20. {
  21. if (!filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) || !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
  22. $this->markTestSkipped('APC is not enabled.');
  23. }
  24. }
  25. public function testWrite()
  26. {
  27. $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
  28. ->disableOriginalConstructor()
  29. ->setMethods(array('getClassName'))
  30. ->getMock();
  31. $meta->expects($this->once())
  32. ->method('getClassName')
  33. ->will($this->returnValue('bar'));
  34. $cache = new ApcCache('foo');
  35. $cache->write($meta);
  36. $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', apc_fetch('foobar'), '->write() stores metadata in APC');
  37. }
  38. public function testHas()
  39. {
  40. $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
  41. ->disableOriginalConstructor()
  42. ->setMethods(array('getClassName'))
  43. ->getMock();
  44. $meta->expects($this->once())
  45. ->method('getClassName')
  46. ->will($this->returnValue('bar'));
  47. apc_delete('foobar');
  48. $cache = new ApcCache('foo');
  49. $this->assertFalse($cache->has('bar'), '->has() returns false when there is no entry');
  50. $cache->write($meta);
  51. $this->assertTrue($cache->has('bar'), '->has() returns true when the is an entry');
  52. }
  53. public function testRead()
  54. {
  55. $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
  56. ->disableOriginalConstructor()
  57. ->setMethods(array('getClassName'))
  58. ->getMock();
  59. $meta->expects($this->once())
  60. ->method('getClassName')
  61. ->will($this->returnValue('bar'));
  62. $cache = new ApcCache('foo');
  63. $cache->write($meta);
  64. $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', $cache->read('bar'), '->read() returns metadata');
  65. }
  66. }