[TASK] getFilesInDirCanOrderByMtime-test should use vfs 17/27717/6
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Wed, 19 Feb 2014 12:33:05 +0000 (13:33 +0100)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Wed, 19 Feb 2014 13:09:27 +0000 (14:09 +0100)
As the other tests in GeneralUtilityTest also
getFilesInDirCanOrderByMtime() should use vfs.
Otherwise we might run into random problems if some
mtimes are equal.

Change-Id: Ic5ad10bd5beedb26c00d48602ebd5455525e4826
Resolves: #56121
Releases: 6.2
Reviewed-on: https://review.typo3.org/27717
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index 1995c27..f42d71e 100644 (file)
@@ -3350,7 +3350,22 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        '.secret.txt' => 'sammon',
                );
                \vfsStream::setup('test', NULL, $structure);
-               return \vfsStream::url('test');
+               $vfsUrl = \vfsStream::url('test');
+
+               if (version_compare(PHP_VERSION, '5.3.0', '>')) {
+                       // set random values for mtime
+                       foreach ($structure as $structureLevel1Key => $structureLevel1Content) {
+                               $newMtime = rand();
+                               if (is_array($structureLevel1Content)) {
+                                       foreach ($structureLevel1Content as $structureLevel2Key => $structureLevel2Content) {
+                                               touch($vfsUrl . '/' . $structureLevel1Key . '/' . $structureLevel2Key, $newMtime);
+                                       }
+                               } else {
+                                       touch($vfsUrl . '/' . $structureLevel1Key, $newMtime);
+                               }
+                       }
+               }
+               return $vfsUrl;
        }
 
        /**
@@ -3416,10 +3431,10 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
-       public function getFilesInDirCanOrderAlphabetically() {
+       public function getFilesInDirDoesSortAlphabeticallyByDefault() {
                $vfsStreamUrl = $this->getFilesInDirCreateTestDirectory();
                $this->assertSame(
-                       array_values(Utility\GeneralUtility::getFilesInDir($vfsStreamUrl, '', FALSE, '1')),
+                       array_values(Utility\GeneralUtility::getFilesInDir($vfsStreamUrl, '', FALSE)),
                        array('.secret.txt', 'excludeMe.txt', 'test.css', 'test.js', 'testA.txt', 'testB.txt', 'testC.txt')
                );
        }
@@ -3428,8 +3443,13 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function getFilesInDirCanOrderByMtime() {
+               if (version_compare(PHP_VERSION, '5.4.0', '<')) {
+                       $this->markTestSkipped('touch() does not work with vfsStream in PHP 5.3 and below.');
+               }
+
+               $vfsStreamUrl = $this->getFilesInDirCreateTestDirectory();
                $files = array();
-               $iterator = new \DirectoryIterator(__DIR__);
+               $iterator = new \DirectoryIterator($vfsStreamUrl);
                foreach ($iterator as $fileinfo) {
                        if ($fileinfo->isFile()) {
                                $files[$fileinfo->getFilename()] = $fileinfo->getMTime();
@@ -3437,7 +3457,7 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                }
                asort($files);
                $this->assertSame(
-                       array_values(Utility\GeneralUtility::getFilesInDir(__DIR__, '', FALSE, 'mtime')),
+                       array_values(Utility\GeneralUtility::getFilesInDir($vfsStreamUrl, '', FALSE, 'mtime')),
                        array_keys($files)
                );
        }