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