[TASK] Make sysext/core/Tests/Unit/Resource/ notice free 28/57228/8
authorJan Helke <typo3@helke.de>
Fri, 22 Jun 2018 16:00:27 +0000 (18:00 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 16 Aug 2018 10:14:35 +0000 (12:14 +0200)
Releases: master
Resolves: #85270
Change-Id: I31794c8e5ac90cce3c93bca8a8c0b502ada42c24
Reviewed-on: https://review.typo3.org/57228
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Resource/AbstractFile.php
typo3/sysext/core/Classes/Resource/Driver/DriverRegistry.php
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Classes/Resource/File.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorIntegrationTest.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php

index 060abb3..66f354c 100644 (file)
@@ -422,7 +422,7 @@ abstract class AbstractFile implements FileInterface
      */
     public function getCombinedIdentifier()
     {
-        if (is_array($this->properties) && MathUtility::canBeInterpretedAsInteger($this->properties['storage'])) {
+        if (!empty($this->properties['storage']) && MathUtility::canBeInterpretedAsInteger($this->properties['storage'])) {
             $combinedIdentifier = $this->properties['storage'] . ':' . $this->getIdentifier();
         } else {
             $combinedIdentifier = $this->getStorage()->getUid() . ':' . $this->getIdentifier();
index 9635623..f952f2d 100644 (file)
@@ -36,8 +36,8 @@ class DriverRegistry implements \TYPO3\CMS\Core\SingletonInterface
     {
         $driverConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'];
         foreach ($driverConfigurations as $shortName => $driverConfig) {
-            $shortName = $shortName ?: $driverConfig['shortName'];
-            $this->registerDriverClass($driverConfig['class'], $shortName, $driverConfig['label'] ?? null, $driverConfig['flexFormDS'] ?? null);
+            $shortName = $shortName ?: $driverConfig['shortName'] ?? '';
+            $this->registerDriverClass($driverConfig['class'] ?? '', $shortName, $driverConfig['label'] ?? '', $driverConfig['flexFormDS'] ?? '');
         }
     }
 
index 9f7f579..f138b65 100644 (file)
@@ -139,6 +139,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver
      * @throws Exception\InvalidConfigurationException
      * @param array $configuration
      * @return string
+     * @throws Exception\InvalidPathException
      */
     protected function calculateBasePath(array $configuration)
     {
index 2cd846d..cd46b6a 100644 (file)
@@ -210,7 +210,7 @@ class File extends AbstractFile
             $this->name = $properties['name'];
         }
 
-        if ($this->properties['uid'] != 0 && isset($properties['uid'])) {
+        if (isset($properties['uid']) && $this->properties['uid'] != 0) {
             unset($properties['uid']);
         }
         foreach ($properties as $key => $value) {
index 08a16f5..64a688e 100644 (file)
@@ -171,14 +171,14 @@ class ResourceStorage implements ResourceStorageInterface
     public function __construct(Driver\DriverInterface $driver, array $storageRecord)
     {
         $this->storageRecord = $storageRecord;
-        $this->configuration = $this->getResourceFactoryInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
+        $this->configuration = $this->getResourceFactoryInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration'] ?? '');
         $this->capabilities =
-            ($this->storageRecord['is_browsable'] ? self::CAPABILITY_BROWSABLE : 0) |
-            ($this->storageRecord['is_public'] ? self::CAPABILITY_PUBLIC : 0) |
-            ($this->storageRecord['is_writable'] ? self::CAPABILITY_WRITABLE : 0);
+            ($this->storageRecord['is_browsable'] ?? null ? self::CAPABILITY_BROWSABLE : 0) |
+            ($this->storageRecord['is_public'] ?? null ? self::CAPABILITY_PUBLIC : 0) |
+            ($this->storageRecord['is_writable'] ?? null ? self::CAPABILITY_WRITABLE : 0);
 
         $this->driver = $driver;
-        $this->driver->setStorageUid($storageRecord['uid']);
+        $this->driver->setStorageUid($storageRecord['uid'] ?? null);
         $this->driver->mergeConfigurationCapabilities($this->capabilities);
         try {
             $this->driver->processConfiguration();
@@ -272,7 +272,7 @@ class ResourceStorage implements ResourceStorageInterface
      */
     public function getUid()
     {
-        return (int)$this->storageRecord['uid'];
+        return (int)($this->storageRecord['uid'] ?? 0);
     }
 
     /**
index ff8bda3..82fe085 100644 (file)
@@ -1488,18 +1488,18 @@ class GeneralUtility
             $tagName = $k;
             // Construct the tag name.
             // Use tag based on grand-parent + parent tag name
-            if (isset($options['grandParentTagMap'][$stackData['grandParentTagName'] . '/' . $stackData['parentTagName']])) {
+            if (isset($stackData['grandParentTagName'], $stackData['parentTagName'], $options['grandParentTagMap'][$stackData['grandParentTagName'] . '/' . $stackData['parentTagName']])) {
                 $attr .= ' index="' . htmlspecialchars($tagName) . '"';
                 $tagName = (string)$options['grandParentTagMap'][$stackData['grandParentTagName'] . '/' . $stackData['parentTagName']];
-            } elseif (isset($options['parentTagMap'][$stackData['parentTagName'] . ':_IS_NUM']) && MathUtility::canBeInterpretedAsInteger($tagName)) {
+            } elseif (isset($stackData['parentTagName'], $options['parentTagMap'][$stackData['parentTagName'] . ':_IS_NUM']) && MathUtility::canBeInterpretedAsInteger($tagName)) {
                 // Use tag based on parent tag name + if current tag is numeric
                 $attr .= ' index="' . htmlspecialchars($tagName) . '"';
                 $tagName = (string)$options['parentTagMap'][$stackData['parentTagName'] . ':_IS_NUM'];
-            } elseif (isset($options['parentTagMap'][$stackData['parentTagName'] . ':' . $tagName])) {
+            } elseif (isset($stackData['parentTagName'], $options['parentTagMap'][$stackData['parentTagName'] . ':' . $tagName])) {
                 // Use tag based on parent tag name + current tag
                 $attr .= ' index="' . htmlspecialchars($tagName) . '"';
                 $tagName = (string)$options['parentTagMap'][$stackData['parentTagName'] . ':' . $tagName];
-            } elseif (isset($options['parentTagMap'][$stackData['parentTagName']])) {
+            } elseif (isset($stackData['parentTagName'], $options['parentTagMap'][$stackData['parentTagName']])) {
                 // Use tag based on parent tag name:
                 $attr .= ' index="' . htmlspecialchars($tagName) . '"';
                 $tagName = (string)$options['parentTagMap'][$stackData['parentTagName']];
@@ -1513,7 +1513,7 @@ class GeneralUtility
                     $attr .= ' index="' . $tagName . '"';
                     $tagName = $options['useIndexTagForNum'] ?: 'numIndex';
                 }
-            } elseif ($options['useIndexTagForAssoc']) {
+            } elseif (!empty($options['useIndexTagForAssoc'])) {
                 // Use tag for all associative keys:
                 $attr .= ' index="' . htmlspecialchars($tagName) . '"';
                 $tagName = $options['useIndexTagForAssoc'];
@@ -1523,7 +1523,7 @@ class GeneralUtility
             // If the value is an array then we will call this function recursively:
             if (is_array($v)) {
                 // Sub elements:
-                if ($options['alt_options'][$stackData['path'] . '/' . $tagName]) {
+                if (isset($options['alt_options']) && $options['alt_options'][($stackData['path'] ?? '') . '/' . $tagName]) {
                     $subOptions = $options['alt_options'][$stackData['path'] . '/' . $tagName];
                     $clearStackPath = $subOptions['clearStackPath'];
                 } else {
@@ -1535,12 +1535,12 @@ class GeneralUtility
                 } else {
                     $content = $nl . self::array2xml($v, $NSprefix, $level + 1, '', $spaceInd, $subOptions, [
                             'parentTagName' => $tagName,
-                            'grandParentTagName' => $stackData['parentTagName'],
-                            'path' => $clearStackPath ? '' : $stackData['path'] . '/' . $tagName
+                            'grandParentTagName' => $stackData['parentTagName'] ?? '',
+                            'path' => $clearStackPath ? '' : ($stackData['path'] ?? '') . '/' . $tagName
                         ]) . ($spaceInd >= 0 ? str_pad('', ($level + 1) * $indentN, $indentChar) : '');
                 }
                 // Do not set "type = array". Makes prettier XML but means that empty arrays are not restored with xml2array
-                if ((int)$options['disableTypeAttrib'] != 2) {
+                if (!isset($options['disableTypeAttrib']) || (int)$options['disableTypeAttrib'] != 2) {
                     $attr .= ' type="array"';
                 }
             } else {
index 3aff051..967d3ed 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 declare(strict_types = 1);
+
 namespace TYPO3\CMS\Core\Tests\Unit\Resource\Driver;
 
 /*
@@ -125,7 +126,11 @@ class LocalDriverTest extends BaseTestCase
         }
         /** @var LocalDriver $driver */
         $mockedDriverMethods[] = 'isPathValid';
-        $driver = $this->getAccessibleMock(LocalDriver::class, $mockedDriverMethods, [$driverConfiguration]);
+        $driver = $this->getAccessibleMock(
+            LocalDriver::class,
+            $mockedDriverMethods,
+            [$driverConfiguration]
+        );
         $driver->expects($this->any())
             ->method('isPathValid')
             ->will(
@@ -193,7 +198,13 @@ class LocalDriverTest extends BaseTestCase
     public function determineBaseUrlUrlEncodesUriParts(): void
     {
         /** @var LocalDriver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface $driver */
-        $driver = $this->getAccessibleMock(LocalDriver::class, ['hasCapability'], [], '', false);
+        $driver = $this->getAccessibleMock(
+            LocalDriver::class,
+            ['hasCapability'],
+            [],
+            '',
+            false
+        );
         $driver->expects($this->once())
             ->method('hasCapability')
             ->with(ResourceStorage::CAPABILITY_PUBLIC)
@@ -364,7 +375,7 @@ class LocalDriverTest extends BaseTestCase
     /**
      * @test
      * @dataProvider getSpecificFileInformationDataProvider
-     * @param $expectedValue
+     * @param string|int $expectedValue
      * @param string $property
      */
     public function getSpecificFileInformationReturnsRequestedFileInformation($expectedValue, string $property): void
@@ -373,7 +384,7 @@ class LocalDriverTest extends BaseTestCase
         $subFolder = vfsStream::newDirectory('fileadmin');
         $root->addChild($subFolder);
         // Load fixture files and folders from disk
-        $directory = vfsStream::copyFromFileSystem(__DIR__ . '/Fixtures/', $subFolder, 1024*1024);
+        $directory = vfsStream::copyFromFileSystem(__DIR__ . '/Fixtures/', $subFolder, 1024 * 1024);
         if (in_array($property, ['mtime', 'ctime', 'atime'])) {
             $expectedValue = $directory->getChild('Dummy.html')->filemtime();
         }
@@ -563,7 +574,10 @@ class LocalDriverTest extends BaseTestCase
             'baseUri' => $baseUri
         ]);
         $publicUrl = $subject->getPublicUrl($fileIdentifier);
-        $this->assertTrue(GeneralUtility::isValidUrl($publicUrl), 'getPublicUrl did not return a valid URL:' . $publicUrl);
+        $this->assertTrue(
+            GeneralUtility::isValidUrl($publicUrl),
+            'getPublicUrl did not return a valid URL:' . $publicUrl
+        );
     }
 
     /**
@@ -579,7 +593,11 @@ class LocalDriverTest extends BaseTestCase
         $this->assertEquals($fileContents, $subject->getFileContents('/file.ext'), 'File contents could not be read');
         $newFileContents = 'asdfgh';
         $subject->setFileContents('/file.ext', $newFileContents);
-        $this->assertEquals($newFileContents, $subject->getFileContents('/file.ext'), 'New file contents could not be read.');
+        $this->assertEquals(
+            $newFileContents,
+            $subject->getFileContents('/file.ext'),
+            'New file contents could not be read.'
+        );
     }
 
     /**
@@ -640,7 +658,7 @@ class LocalDriverTest extends BaseTestCase
             ]
         );
         /** @var $subject LocalDriver */
-        list($basedir, $subject) = $this->prepareRealTestEnvironment();
+        [$basedir, $subject] = $this->prepareRealTestEnvironment();
         mkdir($basedir . '/someDir');
         $subject->createFile('testfile.txt', '/someDir');
         $this->assertEquals((int)$testpattern, (int)(decoct(fileperms($basedir . '/someDir/testfile.txt') & 0777)));
@@ -658,7 +676,7 @@ class LocalDriverTest extends BaseTestCase
         $subFolder = vfsStream::newDirectory('fileadmin');
         $root->addChild($subFolder);
         // Load fixture files and folders from disk
-        vfsStream::copyFromFileSystem(__DIR__ . '/Fixtures/', $subFolder, 1024*1024);
+        vfsStream::copyFromFileSystem(__DIR__ . '/Fixtures/', $subFolder, 1024 * 1024);
         FileStreamWrapper::init(Environment::getPublicPath() . '/');
         FileStreamWrapper::registerOverlayPath('fileadmin/', 'vfs://root/fileadmin/', false);
 
@@ -706,7 +724,7 @@ class LocalDriverTest extends BaseTestCase
         $this->addToMount($dirStructure);
         $subject = $this->createDriver(
             [],
-                // Mocked because finfo() can not deal with vfs streams and throws warnings
+            // Mocked because finfo() can not deal with vfs streams and throws warnings
             ['getMimeTypeOfFile']
         );
         $fileList = $subject->getFilesInFolder('/');
@@ -731,7 +749,7 @@ class LocalDriverTest extends BaseTestCase
         $this->addToMount($dirStructure);
         $subject = $this->createDriver(
             [],
-                // Mocked because finfo() can not deal with vfs streams and throws warnings
+            // Mocked because finfo() can not deal with vfs streams and throws warnings
             ['getMimeTypeOfFile']
         );
         $fileList = $subject->getFilesInFolder('/', 0, 0, true);
@@ -801,7 +819,7 @@ class LocalDriverTest extends BaseTestCase
         $this->addToMount($dirStructure);
         $subject = $this->createDriver(
             [],
-                // Mocked because finfo() can not deal with vfs streams and throws warnings
+            // Mocked because finfo() can not deal with vfs streams and throws warnings
             ['getMimeTypeOfFile']
         );
         $filterCallbacks = [
@@ -926,7 +944,7 @@ class LocalDriverTest extends BaseTestCase
 
     /**
      * @test
-     * @covers LocalDriver::getFileForLocalProcessing
+     * @covers \TYPO3\CMS\Core\Resource\Driver\LocalDriver::getFileForLocalProcessing
      */
     public function getFileForLocalProcessingCreatesCopyOfFileByDefault(): void
     {
@@ -981,7 +999,7 @@ class LocalDriverTest extends BaseTestCase
     public function permissionsAreCorrectlyRetrievedForAllowedFile(): void
     {
         /** @var $subject LocalDriver */
-        list($basedir, $subject) = $this->prepareRealTestEnvironment();
+        [$basedir, $subject] = $this->prepareRealTestEnvironment();
         touch($basedir . '/someFile');
         chmod($basedir . '/someFile', 448);
         clearstatcache();
@@ -993,13 +1011,13 @@ class LocalDriverTest extends BaseTestCase
      */
     public function permissionsAreCorrectlyRetrievedForForbiddenFile(): void
     {
-        if (function_exists('posix_getegid') && posix_getegid() === 0) {
+        if (\function_exists('posix_getegid') && posix_getegid() === 0) {
             $this->markTestSkipped('Test skipped if run on linux as root');
         } elseif (Environment::isWindows()) {
             $this->markTestSkipped('Test skipped if run on Windows system');
         }
         /** @var $subject LocalDriver */
-        list($basedir, $subject) = $this->prepareRealTestEnvironment();
+        [$basedir, $subject] = $this->prepareRealTestEnvironment();
         touch($basedir . '/someForbiddenFile');
         chmod($basedir . '/someForbiddenFile', 0);
         clearstatcache();
@@ -1012,7 +1030,7 @@ class LocalDriverTest extends BaseTestCase
     public function permissionsAreCorrectlyRetrievedForAllowedFolder(): void
     {
         /** @var $subject LocalDriver */
-        list($basedir, $subject) = $this->prepareRealTestEnvironment();
+        [$basedir, $subject] = $this->prepareRealTestEnvironment();
         mkdir($basedir . '/someFolder');
         chmod($basedir . '/someFolder', 448);
         clearstatcache();
@@ -1030,7 +1048,7 @@ class LocalDriverTest extends BaseTestCase
             $this->markTestSkipped('Test skipped if run on Windows system');
         }
         /** @var $subject LocalDriver */
-        list($basedir, $subject) = $this->prepareRealTestEnvironment();
+        [$basedir, $subject] = $this->prepareRealTestEnvironment();
         mkdir($basedir . '/someForbiddenFolder');
         chmod($basedir . '/someForbiddenFolder', 0);
         clearstatcache();
@@ -1185,7 +1203,7 @@ class LocalDriverTest extends BaseTestCase
         ]);
         $subject = $this->createDriver(
             [],
-                // Mocked because finfo() can not deal with vfs streams and throws warnings
+            // Mocked because finfo() can not deal with vfs streams and throws warnings
             ['getMimeTypeOfFile']
         );
         $newIdentifier = $subject->moveFileWithinStorage('/someFile', '/targetFolder/', 'file');
@@ -1284,8 +1302,12 @@ class LocalDriverTest extends BaseTestCase
      * @param string $newFolderName
      * @param string $expectedNewIdentifier
      */
-    public function renamingFoldersChangesFolderNameOnDisk(array $filesystemStructure, string $oldFolderIdentifier, string $newFolderName, string $expectedNewIdentifier)
-    {
+    public function renamingFoldersChangesFolderNameOnDisk(
+        array $filesystemStructure,
+        string $oldFolderIdentifier,
+        string $newFolderName,
+        string $expectedNewIdentifier
+    ): void {
         $this->addToMount($filesystemStructure);
         $subject = $this->createDriver();
         $mapping = $subject->renameFolder($oldFolderIdentifier, $newFolderName);
@@ -1418,7 +1440,10 @@ class LocalDriverTest extends BaseTestCase
         $subject = $this->createDriver();
         $mappingInformation = $subject->moveFolderWithinStorage('/sourceFolder/', '/targetFolder/', 'sourceFolder');
         $this->assertEquals('/targetFolder/sourceFolder/file', $mappingInformation['/sourceFolder/file']);
-        $this->assertEquals('/targetFolder/sourceFolder/subFolder/file', $mappingInformation['/sourceFolder/subFolder/file']);
+        $this->assertEquals(
+            '/targetFolder/sourceFolder/subFolder/file',
+            $mappingInformation['/sourceFolder/subFolder/file']
+        );
         $this->assertEquals('/targetFolder/sourceFolder/subFolder/', $mappingInformation['/sourceFolder/subFolder/']);
     }
 
@@ -1459,7 +1484,7 @@ class LocalDriverTest extends BaseTestCase
      */
     public function copyFolderWithinStorageCopiesSingleSubFolderToNewFolderName(): void
     {
-        list($basePath, $subject) = $this->prepareRealTestEnvironment();
+        [$basePath, $subject] = $this->prepareRealTestEnvironment();
         GeneralUtility::mkdir_deep($basePath . '/sourceFolder/subFolder');
         GeneralUtility::mkdir_deep($basePath . '/targetFolder');
 
@@ -1472,7 +1497,7 @@ class LocalDriverTest extends BaseTestCase
      */
     public function copyFolderWithinStorageCopiesFileInSingleSubFolderToNewFolderName(): void
     {
-        list($basePath, $subject) = $this->prepareRealTestEnvironment();
+        [$basePath, $subject] = $this->prepareRealTestEnvironment();
         GeneralUtility::mkdir_deep($basePath . '/sourceFolder/subFolder');
         GeneralUtility::mkdir_deep($basePath . '/targetFolder');
         file_put_contents($basePath . '/sourceFolder/subFolder/file', $this->getUniqueId());
index 0ee19b4..1fc68a4 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 
 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
 
@@ -24,11 +25,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  */
 class ResourceCompressorIntegrationTest extends BaseTestCase
 {
-    /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
-
     /**
      * @var TestableResourceCompressor
      */
@@ -44,7 +40,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
      */
     protected $fixtureDirFromTest;
 
-    public function setUp()
+    public function setUp(): void
     {
         $this->fixtureDir = 'sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/';
         $this->fixtureDirFromTest = GeneralUtility::fixWindowsFilePath(__DIR__ . '/ResourceCompressorTest/Fixtures/');
@@ -53,7 +49,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
     /**
      * @test
      */
-    public function constructorCreatesTargetDirectory()
+    public function constructorCreatesTargetDirectory(): void
     {
         $this->resourceCompressor = new TestableResourceCompressor();
         $dir = Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
@@ -63,7 +59,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
     /**
      * @test
      */
-    public function constructorCreatesHtaccessFileIfSet()
+    public function constructorCreatesHtaccessFileIfSet(): void
     {
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = true;
         $this->resourceCompressor = new TestableResourceCompressor();
@@ -74,7 +70,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
     /**
      * @test
      */
-    public function constructorDoesNotCreateHtaccessFileIfSetToFalse()
+    public function constructorDoesNotCreateHtaccessFileIfSetToFalse(): void
     {
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = false;
         $this->resourceCompressor = new TestableResourceCompressor();
@@ -85,7 +81,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
     /**
      * @test
      */
-    public function concatenateCssFiles()
+    public function concatenateCssFiles(): void
     {
         $files = [
             'sampleFile1' => [
@@ -107,7 +103,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
     /**
      * @test
      */
-    public function concatenateCssFilesWorksWithFileFromNonRootPath()
+    public function concatenateCssFilesWorksWithFileFromNonRootPath(): void
     {
         $testFile = Environment::getPublicPath() . '/typo3temp/var/transient/css_input_with_import.css';
         $this->testFilesToDelete[] = $testFile;
@@ -129,7 +125,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
         self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(Environment::getPublicPath() . '/' . $mergedFile['file']), $expected);
     }
 
-    public function tearDown()
+    public function tearDown(): void
     {
         $this->testFilesToDelete[] = Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
         parent::tearDown();
index 949a913..4a6a30e 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
 
 /*
@@ -26,6 +28,7 @@ use TYPO3\CMS\Core\Resource\FileInterface;
 use TYPO3\CMS\Core\Resource\FileRepository;
 use TYPO3\CMS\Core\Resource\Folder;
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
+use TYPO3\CMS\Core\Resource\Index\Indexer;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
@@ -36,11 +39,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  */
 class ResourceStorageTest extends BaseTestCase
 {
-    /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
-
     /**
      * @var bool Reset singletons created by subject
      */
@@ -54,7 +52,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * Set up
      */
-    protected function setUp()
+    protected function setUp(): void
     {
         parent::setUp();
         /** @var FileRepository|\PHPUnit_Framework_MockObject_MockObject $fileRepositoryMock */
@@ -80,13 +78,26 @@ class ResourceStorageTest extends BaseTestCase
      * @param array $storageRecord
      * @param array $mockedMethods
      */
-    protected function prepareSubject(array $configuration, $mockPermissionChecks = false, AbstractDriver $driverObject = null, array $storageRecord = [], array $mockedMethods = [])
-    {
-        $permissionMethods = ['assureFileAddPermissions', 'checkFolderActionPermission', 'checkFileActionPermission', 'checkUserActionPermission', 'checkFileExtensionPermission', 'isWithinFileMountBoundaries', 'assureFileRenamePermissions'];
+    protected function prepareSubject(
+        array $configuration,
+        bool $mockPermissionChecks = false,
+        AbstractDriver $driverObject = null,
+        array $storageRecord = [],
+        array $mockedMethods = []
+    ): void {
+        $permissionMethods = [
+            'assureFileAddPermissions',
+            'checkFolderActionPermission',
+            'checkFileActionPermission',
+            'checkUserActionPermission',
+            'checkFileExtensionPermission',
+            'isWithinFileMountBoundaries',
+            'assureFileRenamePermissions'
+        ];
         $configuration = $this->convertConfigurationArrayToFlexformXml($configuration);
         $overruleArray = ['configuration' => $configuration];
         ArrayUtility::mergeRecursiveWithOverrule($storageRecord, $overruleArray);
-        if ($driverObject == null) {
+        if ($driverObject === null) {
             $driverObject = $this->getMockForAbstractClass(AbstractDriver::class, [], '', false);
         }
         if ($mockPermissionChecks) {
@@ -98,7 +109,7 @@ class ResourceStorageTest extends BaseTestCase
             ->setMethods(array_unique($mockedMethods))
             ->setConstructorArgs([$driverObject, $storageRecord])
             ->getMock();
-        $this->subject->expects($this->any())->method('getIndexer')->will($this->returnValue($this->createMock(\TYPO3\CMS\Core\Resource\Index\Indexer::class)));
+        $this->subject->expects($this->any())->method('getIndexer')->will($this->returnValue($this->createMock(Indexer::class)));
         if ($mockPermissionChecks) {
             foreach ($permissionMethods as $method) {
                 $this->subject->expects($this->any())->method($method)->will($this->returnValue(true));
@@ -113,7 +124,7 @@ class ResourceStorageTest extends BaseTestCase
      * @return string
      * @see GeneralUtility::array2xml()
      */
-    protected function convertConfigurationArrayToFlexformXml(array $configuration)
+    protected function convertConfigurationArrayToFlexformXml(array $configuration): string
     {
         $flexFormArray = ['data' => ['sDEF' => ['lDEF' => []]]];
         foreach ($configuration as $key => $value) {
@@ -133,8 +144,11 @@ class ResourceStorageTest extends BaseTestCase
      * @param array $mockedDriverMethods
      * @return \TYPO3\CMS\Core\Resource\Driver\LocalDriver|\PHPUnit_Framework_MockObject_MockObject
      */
-    protected function createDriverMock($driverConfiguration, ResourceStorage $storageObject = null, $mockedDriverMethods = [])
-    {
+    protected function createDriverMock(
+        $driverConfiguration,
+        ResourceStorage $storageObject = null,
+        array $mockedDriverMethods = []
+    ) {
         $this->initializeVfs();
 
         if (!isset($driverConfiguration['basePath'])) {
@@ -163,7 +177,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @return array
      */
-    public function capabilitiesDataProvider()
+    public function capabilitiesDataProvider(): array
     {
         return [
             'only public' => [
@@ -208,8 +222,9 @@ class ResourceStorageTest extends BaseTestCase
      * @test
      * @dataProvider capabilitiesDataProvider
      * @TODO: Rewrite or move to functional suite
+     * @param array $capabilities
      */
-    public function capabilitiesOfStorageObjectAreCorrectlySet(array $capabilities)
+    public function capabilitiesOfStorageObjectAreCorrectlySet(array $capabilities): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $storageRecord = [
@@ -227,26 +242,41 @@ class ResourceStorageTest extends BaseTestCase
             null
         );
         $this->prepareSubject([], false, $mockedDriver, $storageRecord);
-        $this->assertEquals($capabilities['public'], $this->subject->isPublic(), 'Capability "public" is not correctly set.');
-        $this->assertEquals($capabilities['writable'], $this->subject->isWritable(), 'Capability "writable" is not correctly set.');
-        $this->assertEquals($capabilities['browsable'], $this->subject->isBrowsable(), 'Capability "browsable" is not correctly set.');
+        $this->assertEquals(
+            $capabilities['public'],
+            $this->subject->isPublic(),
+            'Capability "public" is not correctly set.'
+        );
+        $this->assertEquals(
+            $capabilities['writable'],
+            $this->subject->isWritable(),
+            'Capability "writable" is not correctly set.'
+        );
+        $this->assertEquals(
+            $capabilities['browsable'],
+            $this->subject->isBrowsable(),
+            'Capability "browsable" is not correctly set.'
+        );
     }
 
     /**
      * @test
      * @TODO: Rewrite or move to functional suite
      */
-    public function fileAndFolderListFiltersAreInitializedWithDefaultFilters()
+    public function fileAndFolderListFiltersAreInitializedWithDefaultFilters(): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $this->prepareSubject([]);
-        $this->assertEquals($GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['defaultFilterCallbacks'], $this->subject->getFileAndFolderNameFilters());
+        $this->assertEquals(
+            $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['defaultFilterCallbacks'],
+            $this->subject->getFileAndFolderNameFilters()
+        );
     }
 
     /**
      * @test
      */
-    public function addFileFailsIfFileDoesNotExist()
+    public function addFileFailsIfFileDoesNotExist(): void
     {
         /** @var Folder|\PHPUnit_Framework_MockObject_MockObject $mockedFolder */
         $mockedFolder = $this->createMock(Folder::class);
@@ -259,7 +289,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function getPublicUrlReturnsNullIfStorageIsNotOnline()
+    public function getPublicUrlReturnsNullIfStorageIsNotOnline(): void
     {
         /** @var $driver LocalDriver|\PHPUnit_Framework_MockObject_MockObject */
         $driver = $this->getMockBuilder(LocalDriver::class)
@@ -283,7 +313,7 @@ class ResourceStorageTest extends BaseTestCase
      *
      * @return array
      */
-    public function checkFolderPermissionsFilesystemPermissionsDataProvider()
+    public function checkFolderPermissionsFilesystemPermissionsDataProvider(): array
     {
         return [
             'read action on readable/writable folder' => [
@@ -311,12 +341,15 @@ class ResourceStorageTest extends BaseTestCase
      * @param array $permissionsFromDriver The permissions as returned from the driver
      * @param bool $expectedResult
      */
-    public function checkFolderPermissionsRespectsFilesystemPermissions($action, $permissionsFromDriver, $expectedResult)
-    {
+    public function checkFolderPermissionsRespectsFilesystemPermissions(
+        string $action,
+        array $permissionsFromDriver,
+        bool $expectedResult
+    ): void {
         /** @var $mockedDriver LocalDriver|\PHPUnit_Framework_MockObject_MockObject */
         $mockedDriver = $this->createMock(LocalDriver::class);
         $mockedDriver->expects($this->any())->method('getPermissions')->will($this->returnValue($permissionsFromDriver));
-        /** @var $mockedFolder Folder|\PHPUnit_Framework_MockObject_MockObject  */
+        /** @var $mockedFolder Folder|\PHPUnit_Framework_MockObject_MockObject */
         $mockedFolder = $this->createMock(Folder::class);
         // Let all other checks pass
         /** @var $subject ResourceStorage|\PHPUnit_Framework_MockObject_MockObject */
@@ -335,7 +368,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function checkUserActionPermissionsAlwaysReturnsTrueIfNoUserPermissionsAreSet()
+    public function checkUserActionPermissionsAlwaysReturnsTrueIfNoUserPermissionsAreSet(): void
     {
         $this->prepareSubject([]);
         $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
@@ -344,14 +377,17 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function checkUserActionPermissionReturnsFalseIfPermissionIsSetToZero()
+    public function checkUserActionPermissionReturnsFalseIfPermissionIsSetToZero(): void
     {
         $this->prepareSubject([]);
         $this->subject->setUserPermissions(['readFolder' => true, 'writeFile' => true]);
         $this->assertTrue($this->subject->checkUserActionPermission('read', 'folder'));
     }
 
-    public function checkUserActionPermission_arbitraryPermissionDataProvider()
+    /**
+     * @return array
+     */
+    public function checkUserActionPermission_arbitraryPermissionDataProvider(): array
     {
         return [
             'all lower cased' => [
@@ -379,7 +415,7 @@ class ResourceStorageTest extends BaseTestCase
      * @test
      * @dataProvider checkUserActionPermission_arbitraryPermissionDataProvider
      */
-    public function checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, $action, $type)
+    public function checkUserActionPermissionAcceptsArbitrarilyCasedArguments(array $permissions, string $action, string $type): void
     {
         $this->prepareSubject([]);
         $this->subject->setUserPermissions($permissions);
@@ -389,7 +425,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function userActionIsDisallowedIfPermissionIsSetToFalse()
+    public function userActionIsDisallowedIfPermissionIsSetToFalse(): void
     {
         $this->prepareSubject([]);
         $this->subject->setEvaluatePermissions(true);
@@ -400,7 +436,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function userActionIsDisallowedIfPermissionIsNotSet()
+    public function userActionIsDisallowedIfPermissionIsNotSet(): void
     {
         $this->prepareSubject([]);
         $this->subject->setEvaluatePermissions(true);
@@ -411,7 +447,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function getEvaluatePermissionsWhenSetFalse()
+    public function getEvaluatePermissionsWhenSetFalse(): void
     {
         $this->prepareSubject([]);
         $this->subject->setEvaluatePermissions(false);
@@ -421,7 +457,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function getEvaluatePermissionsWhenSetTrue()
+    public function getEvaluatePermissionsWhenSetTrue(): void
     {
         $this->prepareSubject([]);
         $this->subject->setEvaluatePermissions(true);
@@ -433,7 +469,7 @@ class ResourceStorageTest extends BaseTestCase
      * @group integration
      * @TODO: Rewrite or move to functional suite
      */
-    public function setFileContentsUpdatesObjectProperties()
+    public function setFileContentsUpdatesObjectProperties(): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $this->initializeVfs();
@@ -489,7 +525,7 @@ class ResourceStorageTest extends BaseTestCase
      * @group integration
      * @TODO: Rewrite or move to functional suite
      */
-    public function moveFileCallsDriversMethodsWithCorrectArguments()
+    public function moveFileCallsDriversMethodsWithCorrectArguments(): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $localFilePath = '/path/to/localFile';
@@ -523,7 +559,11 @@ class ResourceStorageTest extends BaseTestCase
             ->setConstructorArgs([['basePath' => $this->getMountRootUrl()]])
             ->getMock();
         $mockedDriver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfoDummy));
-        $mockedDriver->expects($this->once())->method('addFile')->with($localFilePath, '/targetFolder/', $this->equalTo('file.ext'))->will($this->returnValue('/targetFolder/file.ext'));
+        $mockedDriver->expects($this->once())->method('addFile')->with(
+            $localFilePath,
+            '/targetFolder/',
+            $this->equalTo('file.ext')
+        )->will($this->returnValue('/targetFolder/file.ext'));
         /** @var $subject ResourceStorage */
         $subject = $this->getMockBuilder(ResourceStorage::class)
             ->setMethods(['assureFileMovePermissions'])
@@ -537,7 +577,7 @@ class ResourceStorageTest extends BaseTestCase
      * @group integration
      * @TODO: Rewrite or move to functional suite
      */
-    public function storageUsesInjectedFilemountsToCheckForMountBoundaries()
+    public function storageUsesInjectedFilemountsToCheckForMountBoundaries(): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $mockedFile = $this->getSimpleFileMock('/mountFolder/file');
@@ -558,7 +598,7 @@ class ResourceStorageTest extends BaseTestCase
      * @test
      * @TODO: Rewrite or move to functional suite
      */
-    public function createFolderChecksIfParentFolderExistsBeforeCreatingFolder()
+    public function createFolderChecksIfParentFolderExistsBeforeCreatingFolder(): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
@@ -573,7 +613,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled()
+    public function deleteFolderThrowsExceptionIfFolderIsNotEmptyAndRecursiveDeleteIsDisabled(): void
     {
         $this->expectException(\RuntimeException::class);
         $this->expectExceptionCode(1325952534);
@@ -594,13 +634,16 @@ class ResourceStorageTest extends BaseTestCase
      * @test
      * @TODO: Rewrite or move to functional suite
      */
-    public function createFolderCallsDriverForFolderCreation()
+    public function createFolderCallsDriverForFolderCreation(): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $mockedParentFolder = $this->getSimpleFolderMock('/someFolder/');
         $this->prepareSubject([], true);
         $mockedDriver = $this->createDriverMock([], $this->subject);
-        $mockedDriver->expects($this->once())->method('createFolder')->with($this->equalTo('newFolder'), $this->equalTo('/someFolder/'))->will($this->returnValue(true));
+        $mockedDriver->expects($this->once())->method('createFolder')->with(
+            $this->equalTo('newFolder'),
+            $this->equalTo('/someFolder/')
+        )->will($this->returnValue(true));
         $mockedDriver->expects($this->once())->method('folderExists')->with($this->equalTo('/someFolder/'))->will($this->returnValue(true));
         $this->subject->createFolder('newFolder', $mockedParentFolder);
     }
@@ -609,7 +652,7 @@ class ResourceStorageTest extends BaseTestCase
      * @test
      * @TODO: Rewrite or move to functional suite
      */
-    public function createFolderCanRecursivelyCreateFolders()
+    public function createFolderCanRecursivelyCreateFolders(): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $this->addToMount(['someFolder' => []]);
@@ -626,7 +669,7 @@ class ResourceStorageTest extends BaseTestCase
      * @test
      * @TODO: Rewrite or move to functional suite
      */
-    public function createFolderUsesRootFolderAsParentFolderIfNotGiven()
+    public function createFolderUsesRootFolderAsParentFolderIfNotGiven(): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $this->prepareSubject([], true);
@@ -640,7 +683,7 @@ class ResourceStorageTest extends BaseTestCase
      * @test
      * @TODO: Rewrite or move to functional suite
      */
-    public function createFolderCreatesNestedStructureEvenIfPartsAlreadyExist()
+    public function createFolderCreatesNestedStructureEvenIfPartsAlreadyExist(): void
     {
         $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
         $this->addToMount([
@@ -658,7 +701,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function createFolderThrowsExceptionIfParentFolderDoesNotExist()
+    public function createFolderThrowsExceptionIfParentFolderDoesNotExist(): void
     {
         $this->expectException(\InvalidArgumentException::class);
         $this->expectExceptionCode(1325689164);
@@ -672,7 +715,7 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function renameFileRenamesFileAsRequested()
+    public function renameFileRenamesFileAsRequested(): void
     {
         $mockedDriver = $this->createDriverMock([], $this->subject);
         $mockedDriver->expects($this->once())->method('renameFile')->will($this->returnValue('bar'));
@@ -688,13 +731,25 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function renameFileRenamesWithUniqueNameIfConflictAndConflictModeIsRename()
+    public function renameFileRenamesWithUniqueNameIfConflictAndConflictModeIsRename(): void
     {
         $mockedDriver = $this->createDriverMock([], $this->subject);
-        $mockedDriver->expects($this->any())->method('renameFile')->will($this->onConsecutiveCalls($this->throwException(new ExistingTargetFileNameException('foo', 1489593090)), 'bar_01'));
+        $mockedDriver->expects($this->any())->method('renameFile')->will($this->onConsecutiveCalls($this->throwException(new ExistingTargetFileNameException(
+            'foo',
+            1489593090
+        )), 'bar_01'));
         //$mockedDriver->expects($this->at(1))->method('renameFile')->will($this->returnValue('bar_01'));
-        $mockedDriver->expects($this->any())->method('sanitizeFileName')->will($this->onConsecutiveCalls('bar', 'bar_01'));
-        $this->prepareSubject([], true, $mockedDriver, [], ['emitPreFileRenameSignal', 'emitPostFileRenameSignal', 'getUniqueName']);
+        $mockedDriver->expects($this->any())->method('sanitizeFileName')->will($this->onConsecutiveCalls(
+            'bar',
+            'bar_01'
+        ));
+        $this->prepareSubject(
+            [],
+            true,
+            $mockedDriver,
+            [],
+            ['emitPreFileRenameSignal', 'emitPostFileRenameSignal', 'getUniqueName']
+        );
         /** @var File $file */
         $file = new File(['identifier' => 'foo', 'name' => 'foo'], $this->subject);
         $this->subject->expects($this->once())->method('getUniqueName')->will($this->returnValue('bar_01'));
@@ -707,10 +762,13 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function renameFileThrowsExceptionIfConflictAndConflictModeIsCancel()
+    public function renameFileThrowsExceptionIfConflictAndConflictModeIsCancel(): void
     {
         $mockedDriver = $this->createDriverMock([], $this->subject);
-        $mockedDriver->expects($this->once())->method('renameFile')->will($this->throwException(new ExistingTargetFileNameException('foo', 1489593099)));
+        $mockedDriver->expects($this->once())->method('renameFile')->will($this->throwException(new ExistingTargetFileNameException(
+            'foo',
+            1489593099
+        )));
         $this->prepareSubject([], true, $mockedDriver, [], ['emitPreFileRenameSignal', 'emitPostFileRenameSignal']);
         /** @var File $file */
         $file = new File(['identifier' => 'foo', 'name' => 'foo'], $this->subject);
@@ -721,12 +779,21 @@ class ResourceStorageTest extends BaseTestCase
     /**
      * @test
      */
-    public function renameFileReplacesIfConflictAndConflictModeIsReplace()
+    public function renameFileReplacesIfConflictAndConflictModeIsReplace(): void
     {
         $mockedDriver = $this->createDriverMock([], $this->subject);
-        $mockedDriver->expects($this->once())->method('renameFile')->will($this->throwException(new ExistingTargetFileNameException('foo', 1489593098)));
+        $mockedDriver->expects($this->once())->method('renameFile')->will($this->throwException(new ExistingTargetFileNameException(
+            'foo',
+            1489593098
+        )));
         $mockedDriver->expects($this->any())->method('sanitizeFileName')->will($this->returnValue('bar'));
-        $this->prepareSubject([], true, $mockedDriver, [], ['emitPreFileRenameSignal', 'emitPostFileRenameSignal', 'replaceFile', 'getPublicUrl', 'getResourceFactoryInstance']);
+        $this->prepareSubject([], true, $mockedDriver, [], [
+            'emitPreFileRenameSignal',
+            'emitPostFileRenameSignal',
+            'replaceFile',
+            'getPublicUrl',
+            'getResourceFactoryInstance'
+        ]);
         $this->subject->expects($this->once())->method('getPublicUrl')->will($this->returnValue('somePath'));
         $resourceFactory = $this->prophesize(ResourceFactory::class);
         $file = $this->prophesize(FileInterface::class);