Skip to content

Commit 996d354

Browse files
author
Anthony Regeda
committed
Merge pull request #2 from LinguaLeo/add-aggregation-alias
Add aggregation alias
2 parents 1017240 + 81b23da commit 996d354

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"require": {
1212
"php": ">=5.4.0"
1313
},
14+
"require-dev": {
15+
"phpunit/phpunit": "3.7.*"
16+
},
1417
"autoload": {
1518
"psr-0": {
1619
"LinguaLeo\\": "src/"

src/LinguaLeo/DataQuery/Criteria.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public function read(array $fields)
8383
return $this;
8484
}
8585

86-
public function aggregate($func, $field = null)
86+
public function aggregate($func, $field = null, $alias = null)
8787
{
88-
$this->aggregations[] = [$func, $field];
88+
$this->aggregations[] = [$func, $field, $alias];
8989
return $this;
9090
}
9191

tests/LinguaLeo/DataQuery/CriteriaTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
class CriteriaTest extends \PHPUnit_Framework_TestCase
3030
{
31+
/** @var Criteria */
3132
protected $criteria;
3233

3334
public function setUp()
@@ -83,7 +84,11 @@ public function testAggregate()
8384
{
8485
$this->criteria->aggregate('count');
8586
$this->criteria->aggregate('sum', 'a');
86-
$this->assertSame([['count', null], ['sum', 'a']], $this->criteria->aggregations);
87+
$this->criteria->aggregate('sum', 'a', 'sum_alias');
88+
$this->assertSame(
89+
[['count', null, null], ['sum', 'a', null], ['sum', 'a', 'sum_alias']],
90+
$this->criteria->aggregations
91+
);
8792
}
8893

8994
public function testWrite()

0 commit comments

Comments
 (0)