Skip to content

Commit

Permalink
Fix integers sorting in wrong direction
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmoss committed Feb 24, 2016
1 parent e973529 commit 88ee49c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/JamesMoss/Flywheel/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function sort(array $array, array $args)
} elseif (is_bool($valueA)) {
$cmp = $valueA - $valueB;
} else {
$cmp = ($valueA == $valueB) ? 0 : (($valueA > $valueB) ? -1 : 1);
$cmp = ($valueA == $valueB) ? 0 : (($valueA < $valueB) ? -1 : 1);
}

if ($args[$i][1] === SORT_DESC) {
Expand Down
22 changes: 22 additions & 0 deletions test/JamesMoss/Flywheel/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ public function testOrdering()
$this->assertEquals('Heard Island and McDonald Islands', $result[$result->count() -1]->id);
}

public function testOrderingWithInteger()
{
$path = __DIR__ . '/fixtures/datastore/querytest';
$config = new Config($path . '/');
$repo = new Repository('countries', $config);
$query = new Query($repo);

$query->orderBy('population DESC');

$result = $query->execute();

$this->assertEquals('China', $result->first()->id);
$this->assertEquals('India', $result[1]->id);

$query = new Query($repo);
$query->orderBy('population')->where('population', '>', 0);
$result = $query->execute();

$this->assertEquals('Pitcairn Islands', $result->first()->name);
$this->assertEquals('Cocos (Keeling) Islands', $result[1]->name);
}

public function testBadData()
{
$path = __DIR__ . '/fixtures/datastore/querytest';
Expand Down

0 comments on commit 88ee49c

Please sign in to comment.