123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\ExpressionLanguage\Tests;
- use PHPUnit\Framework\TestCase;
- use Symfony\Component\ExpressionLanguage\Node\Node;
- use Symfony\Component\ExpressionLanguage\ParsedExpression;
- use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheAdapter;
- /**
- * @group legacy
- */
- class ParserCacheAdapterTest extends TestCase
- {
- public function testGetItem()
- {
- $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
- $key = 'key';
- $value = 'value';
- $parserCacheAdapter = new ParserCacheAdapter($poolMock);
- $poolMock
- ->expects($this->once())
- ->method('fetch')
- ->with($key)
- ->willReturn($value)
- ;
- $cacheItem = $parserCacheAdapter->getItem($key);
- $this->assertEquals($cacheItem->get(), $value);
- $this->assertEquals($cacheItem->isHit(), true);
- }
- public function testSave()
- {
- $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
- $cacheItemMock = $this->getMockBuilder('Psr\Cache\CacheItemInterface')->getMock();
- $key = 'key';
- $value = new ParsedExpression('1 + 1', new Node([], []));
- $parserCacheAdapter = new ParserCacheAdapter($poolMock);
- $poolMock
- ->expects($this->once())
- ->method('save')
- ->with($key, $value)
- ;
- $cacheItemMock
- ->expects($this->once())
- ->method('getKey')
- ->willReturn($key)
- ;
- $cacheItemMock
- ->expects($this->once())
- ->method('get')
- ->willReturn($value)
- ;
- $cacheItem = $parserCacheAdapter->save($cacheItemMock);
- }
- public function testGetItems()
- {
- $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
- $parserCacheAdapter = new ParserCacheAdapter($poolMock);
- $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
- $parserCacheAdapter->getItems();
- }
- public function testHasItem()
- {
- $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
- $key = 'key';
- $parserCacheAdapter = new ParserCacheAdapter($poolMock);
- $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
- $parserCacheAdapter->hasItem($key);
- }
- public function testClear()
- {
- $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
- $parserCacheAdapter = new ParserCacheAdapter($poolMock);
- $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
- $parserCacheAdapter->clear();
- }
- public function testDeleteItem()
- {
- $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
- $key = 'key';
- $parserCacheAdapter = new ParserCacheAdapter($poolMock);
- $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
- $parserCacheAdapter->deleteItem($key);
- }
- public function testDeleteItems()
- {
- $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
- $keys = ['key'];
- $parserCacheAdapter = new ParserCacheAdapter($poolMock);
- $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
- $parserCacheAdapter->deleteItems($keys);
- }
- public function testSaveDeferred()
- {
- $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
- $parserCacheAdapter = new ParserCacheAdapter($poolMock);
- $cacheItemMock = $this->getMockBuilder('Psr\Cache\CacheItemInterface')->getMock();
- $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
- $parserCacheAdapter->saveDeferred($cacheItemMock);
- }
- public function testCommit()
- {
- $poolMock = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface')->getMock();
- $parserCacheAdapter = new ParserCacheAdapter($poolMock);
- $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(\BadMethodCallException::class);
- $parserCacheAdapter->commit();
- }
- }
|