diff --git a/src/JamesMoss/Flywheel/Query.php b/src/JamesMoss/Flywheel/Query.php index ae7854a..b74989c 100644 --- a/src/JamesMoss/Flywheel/Query.php +++ b/src/JamesMoss/Flywheel/Query.php @@ -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) { diff --git a/test/JamesMoss/Flywheel/QueryTest.php b/test/JamesMoss/Flywheel/QueryTest.php index fc55730..8aad34b 100644 --- a/test/JamesMoss/Flywheel/QueryTest.php +++ b/test/JamesMoss/Flywheel/QueryTest.php @@ -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';