TYPO3 CMS  TYPO3_8-7
BaseTestCase.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  */
16 
18 
22 abstract class BaseTestCase extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
27  protected $basedir = 'basedir';
28 
29  protected $mountDir;
30 
31  protected $vfsContents = [];
32 
33  protected function setUp()
34  {
35  parent::setUp();
36  $this->mountDir = $this->getUniqueId('mount-');
37  $this->basedir = $this->getUniqueId('base-');
38  vfsStream::setup($this->basedir);
39  // Add an entry for the mount directory to the VFS contents
40  $this->vfsContents = [$this->mountDir => []];
41  }
42 
43  protected function getMountRootUrl()
44  {
45  return $this->getUrlInMount('');
46  }
47 
48  protected function mergeToVfsContents($contents)
49  {
51  }
52 
53  protected function initializeVfs()
54  {
55  if (is_callable('org\\bovigo\\vfs\\vfsStream::create') === false) {
56  $this->markTestSkipped('vfsStream::create() does not exist');
57  }
58  vfsStream::create($this->vfsContents);
59  }
60 
66  protected function addToMount(array $dirStructure)
67  {
68  $this->mergeToVfsContents([$this->mountDir => $dirStructure]);
69  }
70 
77  protected function getUrlInMount($path)
78  {
79  return vfsStream::url($this->basedir . '/' . $this->mountDir . '/' . ltrim($path, '/'));
80  }
81 
87  protected function addToVfs(array $dirStructure)
88  {
89  $this->mergeToVfsContents($dirStructure);
90  }
91 
98  protected function getUrl($path)
99  {
100  return vfsStream::url($this->basedir . '/' . ltrim($path, '/'));
101  }
102 
111  protected function _createFileFolderMock($type, $identifier, $mockedMethods)
112  {
113  if (!empty($mockedMethods)) {
114  if (!in_array('getIdentifier', $mockedMethods)) {
115  $mockedMethods[] = 'getIdentifier';
116  }
117  if (!in_array('getName', $mockedMethods)) {
118  $mockedMethods[] = 'getName';
119  }
120  }
121  $mock = $this->getMockBuilder($type)
122  ->setMethods($mockedMethods)
123  ->disableOriginalConstructor()
124  ->getMock();
125  $mock->expects($this->any())->method('getIdentifier')->will($this->returnValue($identifier));
126  $mock->expects($this->any())->method('getName')->will($this->returnValue(basename($identifier)));
127  return $mock;
128  }
129 
137  protected function getSimpleFileMock($identifier, $mockedMethods = [])
138  {
139  return $this->_createFileFolderMock(\TYPO3\CMS\Core\Resource\File::class, $identifier, $mockedMethods);
140  }
141 
149  protected function getSimpleFolderMock($identifier, $mockedMethods = [])
150  {
151  return $this->_createFileFolderMock(\TYPO3\CMS\Core\Resource\Folder::class, $identifier, $mockedMethods);
152  }
153 
163  protected function getFolderMock($identifier, $mockedMethods = [], $subfolders = [], $files = [])
164  {
165  $folder = $this->_createFileFolderMock(\TYPO3\CMS\Core\Resource\Folder::class, $identifier, array_merge($mockedMethods, ['getFiles', 'getSubfolders']));
166  $folder->expects($this->any())->method('getSubfolders')->will($this->returnValue($subfolders));
167  $folder->expects($this->any())->method('getFiles')->will($this->returnValue($files));
168  return $folder;
169  }
170 }
getSimpleFileMock($identifier, $mockedMethods=[])
getFolderMock($identifier, $mockedMethods=[], $subfolders=[], $files=[])
_createFileFolderMock($type, $identifier, $mockedMethods)
getSimpleFolderMock($identifier, $mockedMethods=[])
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)