‪TYPO3CMS  10.4
PhpFrontendTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪PhpFrontendTest extends UnitTestCase
29 {
34  {
35  $this->expectException(\InvalidArgumentException::class);
36  $this->expectExceptionCode(1264023823);
37 
38  $cache = $this->getMockBuilder(PhpFrontend::class)
39  ->setMethods(['isValidEntryIdentifier'])
40  ->disableOriginalConstructor()
41  ->getMock();
42  $cache->expects(self::once())->method('isValidEntryIdentifier')->with('foo')->willReturn(false);
43  $cache->set('foo', 'bar');
44  }
45 
50  {
51  $originalSourceCode = 'return "hello world!";';
52  $modifiedSourceCode = '<?php' . chr(10) . $originalSourceCode . chr(10) . '#';
53  $mockBackend = $this->createMock(PhpCapableBackendInterface::class);
54  $mockBackend->expects(self::once())->method('set')->with('Foo-Bar', $modifiedSourceCode, ['tags'], 1234);
55  $cache = GeneralUtility::makeInstance(PhpFrontend::class, 'PhpFrontend', $mockBackend);
56  $cache->set('Foo-Bar', $originalSourceCode, ['tags'], 1234);
57  }
58 
63  {
64  $this->expectException(InvalidDataException::class);
65  $this->expectExceptionCode(1264023824);
66 
67  $cache = $this->getMockBuilder(PhpFrontend::class)
68  ->setMethods(['dummy'])
69  ->disableOriginalConstructor()
70  ->getMock();
71  $cache->set('Foo-Bar', []);
72  }
73 
78  {
79  $mockBackend = $this->createMock(PhpCapableBackendInterface::class);
80  $mockBackend->expects(self::once())->method('requireOnce')->with('Foo-Bar')->willReturn('hello world!');
81  $cache = GeneralUtility::makeInstance(PhpFrontend::class, 'PhpFrontend', $mockBackend);
82  $result = $cache->requireOnce('Foo-Bar');
83  self::assertSame('hello world!', $result);
84  }
85 
90  {
91  $mockBackend = $this->createMock(SimpleFileBackend::class);
92  $mockBackend->expects(self::once())->method('require')->with('Foo-Bar')->willReturn('hello world!');
93  $cache = GeneralUtility::makeInstance(PhpFrontend::class, 'PhpFrontend', $mockBackend);
94  $result = $cache->require('Foo-Bar');
95  self::assertSame('hello world!', $result);
96  }
97 }
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\setPassesPhpSourceCodeTagsAndLifetimeToBackend
‪setPassesPhpSourceCodeTagsAndLifetimeToBackend()
Definition: PhpFrontendTest.php:49
‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend
Definition: PhpFrontend.php:25
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend
Definition: AbstractFrontendTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\setThrowsInvalidDataExceptionOnNonStringValues
‪setThrowsInvalidDataExceptionOnNonStringValues()
Definition: PhpFrontendTest.php:62
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\requireOnceCallsTheBackendsRequireOnceMethod
‪requireOnceCallsTheBackendsRequireOnceMethod()
Definition: PhpFrontendTest.php:77
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\requireCallsTheBackendsRequireMethod
‪requireCallsTheBackendsRequireMethod()
Definition: PhpFrontendTest.php:89
‪TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface
Definition: PhpCapableBackendInterface.php:23
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest
Definition: PhpFrontendTest.php:29
‪TYPO3\CMS\Core\Cache\Exception\InvalidDataException
Definition: InvalidDataException.php:24
‪TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend
Definition: SimpleFileBackend.php:33
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\setChecksIfTheIdentifierIsValid
‪setChecksIfTheIdentifierIsValid()
Definition: PhpFrontendTest.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46