Version 1
[yaffs-website] / vendor / symfony / validator / Tests / Mapping / Cache / LegacyApcCacheTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Validator\Tests\Mapping\Cache;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Validator\Mapping\Cache\ApcCache;
16
17 /**
18  * @group legacy
19  * @requires extension apc
20  */
21 class LegacyApcCacheTest extends TestCase
22 {
23     protected function setUp()
24     {
25         if (!ini_get('apc.enabled') || !ini_get('apc.enable_cli')) {
26             $this->markTestSkipped('APC is not enabled.');
27         }
28     }
29
30     public function testWrite()
31     {
32         $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
33             ->disableOriginalConstructor()
34             ->setMethods(array('getClassName'))
35             ->getMock();
36
37         $meta->expects($this->once())
38             ->method('getClassName')
39             ->will($this->returnValue('bar'));
40
41         $cache = new ApcCache('foo');
42         $cache->write($meta);
43
44         $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', apc_fetch('foobar'), '->write() stores metadata in APC');
45     }
46
47     public function testHas()
48     {
49         $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
50             ->disableOriginalConstructor()
51             ->setMethods(array('getClassName'))
52             ->getMock();
53
54         $meta->expects($this->once())
55             ->method('getClassName')
56             ->will($this->returnValue('bar'));
57
58         apc_delete('foobar');
59
60         $cache = new ApcCache('foo');
61         $this->assertFalse($cache->has('bar'), '->has() returns false when there is no entry');
62
63         $cache->write($meta);
64         $this->assertTrue($cache->has('bar'), '->has() returns true when the is an entry');
65     }
66
67     public function testRead()
68     {
69         $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata')
70             ->disableOriginalConstructor()
71             ->setMethods(array('getClassName'))
72             ->getMock();
73
74         $meta->expects($this->once())
75             ->method('getClassName')
76             ->will($this->returnValue('bar'));
77
78         $cache = new ApcCache('foo');
79         $cache->write($meta);
80
81         $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', $cache->read('bar'), '->read() returns metadata');
82     }
83 }