TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Tests/Unit/Resource/BaseTestCase.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
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 
17 use org\bovigo\vfs\vfsStream;
18 
23 {
27  protected $basedir = 'basedir';
28 
29  protected $mountDir;
30 
31  protected $vfsContents = [];
32 
33  protected function setUp()
34  {
35  $this->mountDir = $this->getUniqueId('mount-');
36  $this->basedir = $this->getUniqueId('base-');
37  vfsStream::setup($this->basedir);
38  // Add an entry for the mount directory to the VFS contents
39  $this->vfsContents = [$this->mountDir => []];
40  }
41 
42  protected function getMountRootUrl()
43  {
44  return $this->getUrlInMount('');
45  }
46 
47  protected function mergeToVfsContents($contents)
48  {
50  }
51 
52  protected function initializeVfs()
53  {
54  if (is_callable('org\\bovigo\\vfs\\vfsStream::create') === false) {
55  $this->markTestSkipped('vfsStream::create() does not exist');
56  }
57  vfsStream::create($this->vfsContents);
58  }
59 
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 
88  protected function addToVfs(array $dirStructure)
89  {
90  $this->mergeToVfsContents($dirStructure);
91  }
92 
99  protected function getUrl($path)
100  {
101  return vfsStream::url($this->basedir . '/' . ltrim($path, '/'));
102  }
103 
112  protected function _createFileFolderMock($type, $identifier, $mockedMethods)
113  {
114  if (!empty($mockedMethods)) {
115  if (!in_array('getIdentifier', $mockedMethods)) {
116  $mockedMethods[] = 'getIdentifier';
117  }
118  if (!in_array('getName', $mockedMethods)) {
119  $mockedMethods[] = 'getName';
120  }
121  }
122  $mock = $this->getMockBuilder($type)
123  ->setMethods($mockedMethods)
124  ->disableOriginalConstructor()
125  ->getMock();
126  $mock->expects($this->any())->method('getIdentifier')->will($this->returnValue($identifier));
127  $mock->expects($this->any())->method('getName')->will($this->returnValue(basename($identifier)));
128  return $mock;
129  }
130 
138  protected function getSimpleFileMock($identifier, $mockedMethods = [])
139  {
140  return $this->_createFileFolderMock(\TYPO3\CMS\Core\Resource\File::class, $identifier, $mockedMethods);
141  }
142 
150  protected function getSimpleFolderMock($identifier, $mockedMethods = [])
151  {
152  return $this->_createFileFolderMock(\TYPO3\CMS\Core\Resource\Folder::class, $identifier, $mockedMethods);
153  }
154 
164  protected function getFolderMock($identifier, $mockedMethods = [], $subfolders = [], $files = [])
165  {
166  $folder = $this->_createFileFolderMock(\TYPO3\CMS\Core\Resource\Folder::class, $identifier, array_merge($mockedMethods, ['getFiles', 'getSubfolders']));
167  $folder->expects($this->any())->method('getSubfolders')->will($this->returnValue($subfolders));
168  $folder->expects($this->any())->method('getFiles')->will($this->returnValue($files));
169  return $folder;
170  }
171 }
getFolderMock($identifier, $mockedMethods=[], $subfolders=[], $files=[])
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)