[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Cache / Frontend / PhpFrontendTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Cache\Frontend;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Core\Cache\Exception\InvalidDataException;
17
18 /**
19 * Testcase for the PHP source code cache frontend
20 *
21 * This file is a backport from FLOW3
22 */
23 class PhpFrontendTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
24 {
25 /**
26 * @test
27 */
28 public function setChecksIfTheIdentifierIsValid()
29 {
30 $this->expectException(\InvalidArgumentException::class);
31 $this->expectExceptionCode(1233057566);
32
33 $cache = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class)
34 ->setMethods(['isValidEntryIdentifier'])
35 ->disableOriginalConstructor()
36 ->getMock();
37 $cache->expects($this->once())->method('isValidEntryIdentifier')->with('foo')->will($this->returnValue(false));
38 $cache->set('foo', 'bar');
39 }
40
41 /**
42 * @test
43 */
44 public function setPassesPhpSourceCodeTagsAndLifetimeToBackend()
45 {
46 $originalSourceCode = 'return "hello world!";';
47 $modifiedSourceCode = '<?php' . chr(10) . $originalSourceCode . chr(10) . '#';
48 $mockBackend = $this->createMock(\TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface::class);
49 $mockBackend->expects($this->once())->method('set')->with('Foo-Bar', $modifiedSourceCode, ['tags'], 1234);
50 $cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, 'PhpFrontend', $mockBackend);
51 $cache->set('Foo-Bar', $originalSourceCode, ['tags'], 1234);
52 }
53
54 /**
55 * @test
56 */
57 public function setThrowsInvalidDataExceptionOnNonStringValues()
58 {
59 $this->expectException(InvalidDataException::class);
60 $this->expectExceptionCode(1264023824);
61
62 $cache = $this->getMockBuilder(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class)
63 ->setMethods(['dummy'])
64 ->disableOriginalConstructor()
65 ->getMock();
66 $cache->set('Foo-Bar', []);
67 }
68
69 /**
70 * @test
71 */
72 public function requireOnceCallsTheBackendsRequireOnceMethod()
73 {
74 $mockBackend = $this->createMock(\TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface::class);
75 $mockBackend->expects($this->once())->method('requireOnce')->with('Foo-Bar')->will($this->returnValue('hello world!'));
76 $cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, 'PhpFrontend', $mockBackend);
77 $result = $cache->requireOnce('Foo-Bar');
78 $this->assertSame('hello world!', $result);
79 }
80 }