PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/Unit/Cache/Frontend/PhpFrontendTest.php

https://github.com/christianjul/FLOW3-Composer
PHP | 68 lines | 31 code | 10 blank | 27 comment | 0 complexity | 7f0a838a136ef949bb3c7edc49205065 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. namespace TYPO3\FLOW3\Tests\Unit\Cache\Frontend;
  3. /* *
  4. * This script belongs to the FLOW3 framework. *
  5. * *
  6. * It is free software; you can redistribute it and/or modify it under *
  7. * the terms of the GNU Lesser General Public License, either version 3 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * The TYPO3 project - inspiring people to share! *
  11. * */
  12. /**
  13. * Testcase for the PHP source code cache frontend
  14. *
  15. */
  16. class PhpFrontendTest extends \TYPO3\FLOW3\Tests\UnitTestCase {
  17. /**
  18. * @expectedException \InvalidArgumentException
  19. * @test
  20. */
  21. public function setChecksIfTheIdentifierIsValid() {
  22. $cache = $this->getMock('TYPO3\FLOW3\Cache\Frontend\StringFrontend', array('isValidEntryIdentifier'), array(), '', FALSE);
  23. $cache->expects($this->once())->method('isValidEntryIdentifier')->with('foo')->will($this->returnValue(FALSE));
  24. $cache->set('foo', 'bar');
  25. }
  26. /**
  27. * @test
  28. */
  29. public function setPassesPhpSourceCodeTagsAndLifetimeToBackend() {
  30. $originalSourceCode = 'return "hello world!";';
  31. $modifiedSourceCode = '<?php' . chr(10) . $originalSourceCode . chr(10) . '#';
  32. $mockBackend = $this->getMock('TYPO3\FLOW3\Cache\Backend\PhpCapableBackendInterface', array(), array(), '', FALSE);
  33. $mockBackend->expects($this->once())->method('set')->with('Foo-Bar', $modifiedSourceCode, array('tags'), 1234);
  34. $cache = $this->getAccessibleMock('TYPO3\FLOW3\Cache\Frontend\PhpFrontend', array('dummy'), array(), '', FALSE);
  35. $cache->_set('backend', $mockBackend);
  36. $cache->set('Foo-Bar', $originalSourceCode, array('tags'), 1234);
  37. }
  38. /**
  39. * @test
  40. * @expectedException \TYPO3\FLOW3\Cache\Exception\InvalidDataException
  41. */
  42. public function setThrowsInvalidDataExceptionOnNonStringValues() {
  43. $cache = $this->getMock('TYPO3\FLOW3\Cache\Frontend\PhpFrontend', array('dummy'), array(), '', FALSE);
  44. $cache->set('Foo-Bar', array());
  45. }
  46. /**
  47. * @test
  48. */
  49. public function requireOnceCallsTheBackendsRequireOnceMethod() {
  50. $mockBackend = $this->getMock('TYPO3\FLOW3\Cache\Backend\PhpCapableBackendInterface', array(), array(), '', FALSE);
  51. $mockBackend->expects($this->once())->method('requireOnce')->with('Foo-Bar')->will($this->returnValue('hello world!'));
  52. $cache = $this->getAccessibleMock('TYPO3\FLOW3\Cache\Frontend\PhpFrontend', array('dummy'), array(), '', FALSE);
  53. $cache->_set('backend', $mockBackend);
  54. $result = $cache->requireOnce('Foo-Bar');
  55. $this->assertSame('hello world!', $result);
  56. }
  57. }
  58. ?>