From 3c0e77a9573eccb182e33cef5c7a135f3bf4aa9f Mon Sep 17 00:00:00 2001 From: tzaoh Date: Sat, 30 Apr 2016 13:11:48 +0200 Subject: [PATCH] Correcting some gaps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit · Added a second test for chinpei215 request. · use "||" instead of "or" in conditionals · "elseif" instead of "else if" --- src/Filesystem/Folder.php | 4 ++-- tests/TestCase/Filesystem/FolderTest.php | 27 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Filesystem/Folder.php b/src/Filesystem/Folder.php index c151ee1827c..b734df052bc 100644 --- a/src/Filesystem/Folder.php +++ b/src/Filesystem/Folder.php @@ -213,10 +213,10 @@ public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = f } if ($sort || $this->sort) { - if ($sort === self::SORT_TIME or $this->sort === self::SORT_TIME) { + if ($sort === self::SORT_TIME || $this->sort === self::SORT_TIME) { ksort($dirs); ksort($files); - } else if ($sort === self::SORT_NAME or $this->sort === self::SORT_NAME) { + } elseif ($sort === self::SORT_NAME || $this->sort === self::SORT_NAME) { sort($dirs); sort($files); } diff --git a/tests/TestCase/Filesystem/FolderTest.php b/tests/TestCase/Filesystem/FolderTest.php index c5c2fe7112f..e57085aac4e 100644 --- a/tests/TestCase/Filesystem/FolderTest.php +++ b/tests/TestCase/Filesystem/FolderTest.php @@ -1271,4 +1271,31 @@ public function testSortByTime() $this->assertSame(['file_2.tmp', 'file_1.tmp'], $results); } + + /** + * testSortByTime2 method + * + * Verify that the order using modified time is correct. + * + * @return void + */ + public function testSortByTime2() + { + $Folder = new Folder(TMP . 'tests', true); + + $fileA = new File($Folder->pwd() . DS . 'a.txt'); + $fileA->create(); + + $fileC = new File($Folder->pwd() . DS . 'c.txt'); + $fileC->create(); + + sleep(1); + + $fileB = new File($Folder->pwd() . DS . 'b.txt'); + $fileB->create(); + + $results = $Folder->find('.*', Folder::SORT_TIME); + + $this->assertSame(['a.txt', 'c.txt', 'b.txt'], $results); + } }