Skip to content

Commit

Permalink
Merge pull request #2 from LinguaLeo/add-aggregation-alias
Browse files Browse the repository at this point in the history
Add aggregation alias
  • Loading branch information
Anthony Regeda committed Oct 14, 2014
2 parents 1017240 + 81b23da commit 996d354
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-0": {
"LinguaLeo\\": "src/"
Expand Down
4 changes: 2 additions & 2 deletions src/LinguaLeo/DataQuery/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public function read(array $fields)
return $this;
}

public function aggregate($func, $field = null)
public function aggregate($func, $field = null, $alias = null)
{
$this->aggregations[] = [$func, $field];
$this->aggregations[] = [$func, $field, $alias];
return $this;
}

Expand Down
7 changes: 6 additions & 1 deletion tests/LinguaLeo/DataQuery/CriteriaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

class CriteriaTest extends \PHPUnit_Framework_TestCase
{
/** @var Criteria */
protected $criteria;

public function setUp()
Expand Down Expand Up @@ -83,7 +84,11 @@ public function testAggregate()
{
$this->criteria->aggregate('count');
$this->criteria->aggregate('sum', 'a');
$this->assertSame([['count', null], ['sum', 'a']], $this->criteria->aggregations);
$this->criteria->aggregate('sum', 'a', 'sum_alias');
$this->assertSame(
[['count', null, null], ['sum', 'a', null], ['sum', 'a', 'sum_alias']],
$this->criteria->aggregations
);
}

public function testWrite()
Expand Down

0 comments on commit 996d354

Please sign in to comment.