Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #256 from alcaeus/aggregation-group-allow-operators
Browse files Browse the repository at this point in the history
Allow using operators in group stages
  • Loading branch information
alcaeus committed Mar 18, 2016
2 parents 2ffb37a + 2eb3c8e commit ab3e697
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
17 changes: 1 addition & 16 deletions lib/Doctrine/MongoDB/Aggregation/Stage/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,8 @@
* @author alcaeus <[email protected]>
* @since 1.2
*/
class Group extends Stage
class Group extends Operator
{
/**
* @var Expr
*/
protected $expr;

/**
* {@inheritdoc}
*/
public function __construct(Builder $builder)
{
$this->expr = new Expr();

parent::__construct($builder);
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/Doctrine/MongoDB/Tests/Aggregation/Stage/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@ public function testGroupFromBuilder()

$this->assertSame(array(array('$group' => array('_id' => '$field', 'count' => array('$sum' => 1)))), $builder->getPipeline());
}

public function testGroupWithOperatorInId()
{
$groupStage = new Group($this->getTestAggregationBuilder());
$groupStage
->field('_id')
->year('$dateField')
->field('count')
->sum(1);

$this->assertSame(array('$group' => array('_id' => ['$year' => '$dateField'], 'count' => array('$sum' => 1))), $groupStage->getExpression());
}
}

0 comments on commit ab3e697

Please sign in to comment.