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\ApcCache;
19 * @requires extension apc
21 class LegacyApcCacheTest extends TestCase
23 protected function setUp()
25 if (!ini_get('apc.enabled') || !ini_get('apc.enable_cli')) {
26 $this->markTestSkipped('APC is not enabled.');
30 public function testWrite()
32 $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
33 ->disableOriginalConstructor()
34 ->setMethods(array('getClassName'))
37 $meta->expects($this->once())
38 ->method('getClassName')
39 ->will($this->returnValue('bar'));
41 $cache = new ApcCache('foo');
44 $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', apc_fetch('foobar'), '->write() stores metadata in APC');
47 public function testHas()
49 $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
50 ->disableOriginalConstructor()
51 ->setMethods(array('getClassName'))
54 $meta->expects($this->once())
55 ->method('getClassName')
56 ->will($this->returnValue('bar'));
60 $cache = new ApcCache('foo');
61 $this->assertFalse($cache->has('bar'), '->has() returns false when there is no entry');
64 $this->assertTrue($cache->has('bar'), '->has() returns true when the is an entry');
67 public function testRead()
69 $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
70 ->disableOriginalConstructor()
71 ->setMethods(array('getClassName'))
74 $meta->expects($this->once())
75 ->method('getClassName')
76 ->will($this->returnValue('bar'));
78 $cache = new ApcCache('foo');
81 $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', $cache->read('bar'), '->read() returns metadata');