DoctrineParserCacheTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Bridge\Doctrine\Tests\ExpressionLanguage;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Bridge\Doctrine\ExpressionLanguage\DoctrineParserCache;
  13. class DoctrineParserCacheTest extends TestCase
  14. {
  15. public function testFetch()
  16. {
  17. $doctrineCacheMock = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
  18. $parserCache = new DoctrineParserCache($doctrineCacheMock);
  19. $doctrineCacheMock->expects($this->once())
  20. ->method('fetch')
  21. ->will($this->returnValue('bar'));
  22. $result = $parserCache->fetch('foo');
  23. $this->assertEquals('bar', $result);
  24. }
  25. public function testFetchUnexisting()
  26. {
  27. $doctrineCacheMock = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
  28. $parserCache = new DoctrineParserCache($doctrineCacheMock);
  29. $doctrineCacheMock
  30. ->expects($this->once())
  31. ->method('fetch')
  32. ->will($this->returnValue(false));
  33. $this->assertNull($parserCache->fetch(''));
  34. }
  35. public function testSave()
  36. {
  37. $doctrineCacheMock = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
  38. $parserCache = new DoctrineParserCache($doctrineCacheMock);
  39. $expression = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ParsedExpression')
  40. ->disableOriginalConstructor()
  41. ->getMock();
  42. $doctrineCacheMock->expects($this->once())
  43. ->method('save')
  44. ->with('foo', $expression);
  45. $parserCache->save('foo', $expression);
  46. }
  47. }