Skip to content

Commit 3c0e77a

Browse files
author
tzaoh
committed
Correcting some gaps
· Added a second test for chinpei215 request. · use "||" instead of "or" in conditionals · "elseif" instead of "else if"
1 parent 5a6d315 commit 3c0e77a

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Filesystem/Folder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = f
213213
}
214214

215215
if ($sort || $this->sort) {
216-
if ($sort === self::SORT_TIME or $this->sort === self::SORT_TIME) {
216+
if ($sort === self::SORT_TIME || $this->sort === self::SORT_TIME) {
217217
ksort($dirs);
218218
ksort($files);
219-
} else if ($sort === self::SORT_NAME or $this->sort === self::SORT_NAME) {
219+
} elseif ($sort === self::SORT_NAME || $this->sort === self::SORT_NAME) {
220220
sort($dirs);
221221
sort($files);
222222
}

tests/TestCase/Filesystem/FolderTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,4 +1271,31 @@ public function testSortByTime()
12711271

12721272
$this->assertSame(['file_2.tmp', 'file_1.tmp'], $results);
12731273
}
1274+
1275+
/**
1276+
* testSortByTime2 method
1277+
*
1278+
* Verify that the order using modified time is correct.
1279+
*
1280+
* @return void
1281+
*/
1282+
public function testSortByTime2()
1283+
{
1284+
$Folder = new Folder(TMP . 'tests', true);
1285+
1286+
$fileA = new File($Folder->pwd() . DS . 'a.txt');
1287+
$fileA->create();
1288+
1289+
$fileC = new File($Folder->pwd() . DS . 'c.txt');
1290+
$fileC->create();
1291+
1292+
sleep(1);
1293+
1294+
$fileB = new File($Folder->pwd() . DS . 'b.txt');
1295+
$fileB->create();
1296+
1297+
$results = $Folder->find('.*', Folder::SORT_TIME);
1298+
1299+
$this->assertSame(['a.txt', 'c.txt', 'b.txt'], $results);
1300+
}
12741301
}

0 commit comments

Comments
 (0)