‪TYPO3CMS  9.5
PhpFrontendTest.php
Go to the documentation of this file.
1 <?php
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  */
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪PhpFrontendTest extends UnitTestCase
23 {
28  {
29  $this->expectException(\InvalidArgumentException::class);
30  $this->expectExceptionCode(1264023823);
31 
32  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class)
33  ->setMethods(['isValidEntryIdentifier'])
34  ->disableOriginalConstructor()
35  ->getMock();
36  $cache->expects($this->once())->method('isValidEntryIdentifier')->with('foo')->will($this->returnValue(false));
37  $cache->set('foo', 'bar');
38  }
39 
44  {
45  $originalSourceCode = 'return "hello world!";';
46  $modifiedSourceCode = '<?php' . chr(10) . $originalSourceCode . chr(10) . '#';
47  $mockBackend = $this->createMock(\‪TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface::class);
48  $mockBackend->expects($this->once())->method('set')->with('Foo-Bar', $modifiedSourceCode, ['tags'], 1234);
49  $cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, 'PhpFrontend', $mockBackend);
50  $cache->set('Foo-Bar', $originalSourceCode, ['tags'], 1234);
51  }
52 
57  {
58  $this->expectException(InvalidDataException::class);
59  $this->expectExceptionCode(1264023824);
60 
61  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class)
62  ->setMethods(['dummy'])
63  ->disableOriginalConstructor()
64  ->getMock();
65  $cache->set('Foo-Bar', []);
66  }
67 
72  {
73  $mockBackend = $this->createMock(\‪TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface::class);
74  $mockBackend->expects($this->once())->method('requireOnce')->with('Foo-Bar')->will($this->returnValue('hello world!'));
75  $cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, 'PhpFrontend', $mockBackend);
76  $result = $cache->requireOnce('Foo-Bar');
77  $this->assertSame('hello world!', $result);
78  }
79 
84  {
85  $mockBackend = $this->createMock(\‪TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend::class);
86  $mockBackend->expects($this->once())->method('require')->with('Foo-Bar')->will($this->returnValue('hello world!'));
87  $cache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, 'PhpFrontend', $mockBackend);
88  $result = $cache->require('Foo-Bar');
89  $this->assertSame('hello world!', $result);
90  }
91 }
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\setPassesPhpSourceCodeTagsAndLifetimeToBackend
‪setPassesPhpSourceCodeTagsAndLifetimeToBackend()
Definition: PhpFrontendTest.php:43
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend
Definition: AbstractFrontendTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\setThrowsInvalidDataExceptionOnNonStringValues
‪setThrowsInvalidDataExceptionOnNonStringValues()
Definition: PhpFrontendTest.php:56
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\requireOnceCallsTheBackendsRequireOnceMethod
‪requireOnceCallsTheBackendsRequireOnceMethod()
Definition: PhpFrontendTest.php:71
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\requireCallsTheBackendsRequireMethod
‪requireCallsTheBackendsRequireMethod()
Definition: PhpFrontendTest.php:83
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest
Definition: PhpFrontendTest.php:23
‪TYPO3\CMS\Core\Cache\Exception\InvalidDataException
Definition: InvalidDataException.php:21
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\PhpFrontendTest\setChecksIfTheIdentifierIsValid
‪setChecksIfTheIdentifierIsValid()
Definition: PhpFrontendTest.php:27