TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
PhpFrontendTest.php
Go to the documentation of this file.
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  */
17 
24 {
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 
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 
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 
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 }
static makeInstance($className,...$constructorArguments)