]> git.mxchange.org Git - friendica-addons.git/blob
447316111b8402bd9d1f6cbe42078a5c8bebb9ab
[friendica-addons.git] /
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\ExpressionLanguage\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\ExpressionLanguage\ParsedExpression;
16 use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheAdapter;
17 use Symfony\Component\ExpressionLanguage\Node\Node;
18
19 /**
20  * @group legacy
21  */
22 class ParserCacheAdapterTest extends TestCase
23 {
24     public function testGetItem()
25     {
26         $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
27
28         $key = 'key';
29         $value = 'value';
30         $parserCacheAdapter = new ParserCacheAdapter($poolMock);
31
32         $poolMock
33             ->expects($this->once())
34             ->method('fetch')
35             ->with($key)
36             ->willReturn($value)
37         ;
38
39         $cacheItem = $parserCacheAdapter->getItem($key);
40
41         $this->assertEquals($cacheItem->get(), $value);
42         $this->assertEquals($cacheItem->isHit(), true);
43     }
44
45     public function testSave()
46     {
47         $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
48         $cacheItemMock = $this->getMockBuilder('Psr\Cache\CacheItemInterface')->getMock();
49         $key = 'key';
50         $value = new ParsedExpression('1 + 1', new Node(array(), array()));
51         $parserCacheAdapter = new ParserCacheAdapter($poolMock);
52
53         $poolMock
54             ->expects($this->once())
55             ->method('save')
56             ->with($key, $value)
57         ;
58
59         $cacheItemMock
60             ->expects($this->once())
61             ->method('getKey')
62             ->willReturn($key)
63         ;
64
65         $cacheItemMock
66             ->expects($this->once())
67             ->method('get')
68             ->willReturn($value)
69         ;
70
71         $cacheItem = $parserCacheAdapter->save($cacheItemMock);
72     }
73
74     public function testGetItems()
75     {
76         $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
77         $parserCacheAdapter = new ParserCacheAdapter($poolMock);
78         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
79
80         $parserCacheAdapter->getItems();
81     }
82
83     public function testHasItem()
84     {
85         $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
86         $key = 'key';
87         $parserCacheAdapter = new ParserCacheAdapter($poolMock);
88         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
89
90         $parserCacheAdapter->hasItem($key);
91     }
92
93     public function testClear()
94     {
95         $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
96         $parserCacheAdapter = new ParserCacheAdapter($poolMock);
97         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
98
99         $parserCacheAdapter->clear();
100     }
101
102     public function testDeleteItem()
103     {
104         $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
105         $key = 'key';
106         $parserCacheAdapter = new ParserCacheAdapter($poolMock);
107         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
108
109         $parserCacheAdapter->deleteItem($key);
110     }
111
112     public function testDeleteItems()
113     {
114         $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
115         $keys = array('key');
116         $parserCacheAdapter = new ParserCacheAdapter($poolMock);
117         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
118
119         $parserCacheAdapter->deleteItems($keys);
120     }
121
122     public function testSaveDeferred()
123     {
124         $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
125         $parserCacheAdapter = new ParserCacheAdapter($poolMock);
126         $cacheItemMock = $this->getMockBuilder('Psr\Cache\CacheItemInterface')->getMock();
127         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
128
129         $parserCacheAdapter->saveDeferred($cacheItemMock);
130     }
131
132     public function testCommit()
133     {
134         $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
135         $parserCacheAdapter = new ParserCacheAdapter($poolMock);
136         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
137
138         $parserCacheAdapter->commit();
139     }
140 }