Skip to content

Commit

Permalink
Correcting some gaps
Browse files Browse the repository at this point in the history
·  Added a second test for chinpei215 request.
· use "||" instead of "or" in conditionals
· "elseif" instead of "else if"
  • Loading branch information
tzaoh committed Apr 30, 2016
1 parent 5a6d315 commit 3c0e77a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Filesystem/Folder.php
Expand Up @@ -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);
}
Expand Down
27 changes: 27 additions & 0 deletions tests/TestCase/Filesystem/FolderTest.php
Expand Up @@ -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);
}
}

0 comments on commit 3c0e77a

Please sign in to comment.