Skip to content

Commit

Permalink
Merge pull request #14 from ClanCats/developer
Browse files Browse the repository at this point in the history
Fixed order expression array
  • Loading branch information
mario-deluna authored Feb 4, 2019
2 parents 9bff15c + 9b92d5b commit 3485e53
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/Query/Sql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,17 @@ public function orderBy($columns, $direction = 'asc')
{
$this->orders[] = array($columns, $direction); return $this;
}

foreach ($columns as $key => $column)
{
if (is_numeric($key))
{
$this->orders[$column] = $direction;
if ($column instanceof Expression)
{
$this->orders[] = array($column, $direction);
} else {
$this->orders[$column] = $direction;
}
} else {
$this->orders[$key] = $column;
}
Expand Down
10 changes: 1 addition & 9 deletions tests/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@

class Builder_Test extends \PHPUnit\Framework\TestCase
{
/**
* Builder::extend test
*/
public function testExtend()
{
Builder::extend('phpunit', '\\This\\Should\\Work', '\\Without\\The\\Class\\Existing');
}

/**
* Builder::extend test
*
Expand Down Expand Up @@ -130,4 +122,4 @@ public function testQueryClassesAsExpected()

$hydrahon->table('test')->insert(['foo' => 'bar'])->execute();
}
}
}
11 changes: 10 additions & 1 deletion tests/Query/Sql/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ public function testOrderByRaw()

// simple
$this->assertAttributes($this->createQuery()->orderBy($raw), array('orders' => array(array($raw, 'asc'))));

// in array
$this->assertAttributes($this->createQuery()->orderBy([$raw, $raw]), array('orders' => array(array($raw, 'asc'), array($raw, 'asc'))));

// in array order
$this->assertAttributes($this->createQuery()->orderBy([$raw, $raw], 'desc'), array('orders' => array(array($raw, 'desc'), array($raw, 'desc'))));

// in array mixing
$this->assertAttributes($this->createQuery()->orderBy([$raw, 'foo' => 'asc'], 'desc'), array('orders' => array(array($raw, 'desc'), 'foo' => 'asc')));
}

/**
Expand Down Expand Up @@ -304,4 +313,4 @@ public function testGroupResults()
$this->assertEquals('Johnna', $grouped[22][5]['name']);
$this->assertEquals('Johnna', $grouped[20][2]['name']);
}
}
}

0 comments on commit 3485e53

Please sign in to comment.