‪TYPO3CMS  9.5
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 
17 use org\bovigo\vfs\vfsStream;
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19 
23 abstract class ‪BaseTestCase extends UnitTestCase
24 {
28  protected ‪$basedir = 'basedir';
29 
30  protected ‪$mountDir;
31 
32  protected ‪$vfsContents = [];
33 
34  protected function ‪setUp()
35  {
36  parent::setUp();
37  $this->mountDir = $this->getUniqueId('mount-');
38  $this->basedir = $this->getUniqueId('base-');
39  vfsStream::setup($this->basedir);
40  // Add an entry for the mount directory to the VFS contents
41  $this->vfsContents = [$this->mountDir => []];
42  }
43 
44  protected function ‪getMountRootUrl()
45  {
46  return $this->‪getUrlInMount('');
47  }
48 
49  protected function ‪mergeToVfsContents($contents)
50  {
52  }
53 
54  protected function ‪initializeVfs()
55  {
56  vfsStream::create($this->vfsContents);
57  }
58 
64  protected function ‪addToMount(array $dirStructure)
65  {
66  $this->‪mergeToVfsContents([$this->mountDir => $dirStructure]);
67  }
68 
75  protected function ‪getUrlInMount($path)
76  {
77  return vfsStream::url($this->basedir . '/' . $this->mountDir . '/' . ltrim($path, '/'));
78  }
79 
85  protected function ‪addToVfs(array $dirStructure)
86  {
87  $this->‪mergeToVfsContents($dirStructure);
88  }
89 
96  protected function ‪getUrl($path)
97  {
98  return vfsStream::url($this->basedir . '/' . ltrim($path, '/'));
99  }
100 
109  protected function ‪_createFileFolderMock($type, $identifier, $mockedMethods)
110  {
111  if (!empty($mockedMethods)) {
112  if (!in_array('getIdentifier', $mockedMethods)) {
113  $mockedMethods[] = 'getIdentifier';
114  }
115  if (!in_array('getName', $mockedMethods)) {
116  $mockedMethods[] = 'getName';
117  }
118  }
119  $mock = $this->getMockBuilder($type)
120  ->setMethods($mockedMethods)
121  ->disableOriginalConstructor()
122  ->getMock();
123  $mock->expects($this->any())->method('getIdentifier')->will($this->returnValue($identifier));
124  $mock->expects($this->any())->method('getName')->will($this->returnValue(basename($identifier)));
125  return $mock;
126  }
127 
135  protected function ‪getSimpleFileMock($identifier, $mockedMethods = [])
136  {
137  return $this->‪_createFileFolderMock(\‪TYPO3\CMS\Core\Resource\File::class, $identifier, $mockedMethods);
138  }
139 
147  protected function ‪getSimpleFolderMock($identifier, $mockedMethods = [])
148  {
149  return $this->‪_createFileFolderMock(\‪TYPO3\CMS\Core\Resource\Folder::class, $identifier, $mockedMethods);
150  }
151 
161  protected function ‪getFolderMock($identifier, $mockedMethods = [], $subfolders = [], $files = [])
162  {
163  $folder = $this->‪_createFileFolderMock(\‪TYPO3\CMS\Core\Resource\Folder::class, $identifier, array_merge($mockedMethods, ['getFiles', 'getSubfolders']));
164  $folder->expects($this->any())->method('getSubfolders')->will($this->returnValue($subfolders));
165  $folder->expects($this->any())->method('getFiles')->will($this->returnValue($files));
166  return $folder;
167  }
168 }
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
Definition: BaseTestCase.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getFolderMock
‪TYPO3 CMS Core Resource File TYPO3 CMS Core Resource Folder getFolderMock($identifier, $mockedMethods=[], $subfolders=[], $files=[])
Definition: BaseTestCase.php:160
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\addToVfs
‪addToVfs(array $dirStructure)
Definition: BaseTestCase.php:84
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\$mountDir
‪$mountDir
Definition: BaseTestCase.php:29
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\_createFileFolderMock
‪TYPO3 CMS Core Resource File TYPO3 CMS Core Resource Folder _createFileFolderMock($type, $identifier, $mockedMethods)
Definition: BaseTestCase.php:108
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\$basedir
‪string $basedir
Definition: BaseTestCase.php:27
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getMountRootUrl
‪getMountRootUrl()
Definition: BaseTestCase.php:43
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getSimpleFileMock
‪TYPO3 CMS Core Resource File PHPUnit_Framework_MockObject_MockObject getSimpleFileMock($identifier, $mockedMethods=[])
Definition: BaseTestCase.php:134
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\$vfsContents
‪$vfsContents
Definition: BaseTestCase.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getUrlInMount
‪string getUrlInMount($path)
Definition: BaseTestCase.php:74
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getSimpleFolderMock
‪TYPO3 CMS Core Resource Folder getSimpleFolderMock($identifier, $mockedMethods=[])
Definition: BaseTestCase.php:146
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\setUp
‪setUp()
Definition: BaseTestCase.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\mergeToVfsContents
‪mergeToVfsContents($contents)
Definition: BaseTestCase.php:48
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\getUrl
‪string getUrl($path)
Definition: BaseTestCase.php:95
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\addToMount
‪addToMount(array $dirStructure)
Definition: BaseTestCase.php:63
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase\initializeVfs
‪initializeVfs()
Definition: BaseTestCase.php:53