Skip to content

Commit

Permalink
fix convert args
Browse files Browse the repository at this point in the history
  • Loading branch information
a.moroz committed Sep 12, 2013
1 parent 72c11de commit 254dea8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ before_script:
- curl -s http://getcomposer.org/installer |php --
- php composer.phar install

script: phpunit
script: phpunit
2 changes: 1 addition & 1 deletion src/Solution/MongoAggregation/Pipeline/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function convertArgs($step)
}
} else {
if (is_string($key)) {
$values[$key] = $args;
$values[$key] = $this->convertArgs($args);
} else {
$values[] = $args;
}
Expand Down
21 changes: 12 additions & 9 deletions tests/Tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,34 @@ public function testModifyPipeline()
public function testQuery1()
{
$pipeline = array(
array(
'$group' => array(
"_id" => array("tags" => '$tags', 'sum' => ['$sum' => '$sumField']),
"authors" => array('$addToSet' => '$author'),
"sum" => array('$sum' => '$fieldSum'),
),
),
array(
'$project' => array(
"author" => 1,
"tags" => 1,
)
),
array('$unwind' => '$tags'),
array(
'$group' => array(
"_id" => array("tags" => '$tags'),
"authors" => array('$addToSet' => '$author'),
),
),

);
$exp = new Expr();

$query = $this->query->addStage('stage1')
->project(['author' => true, 'tags' => true])
->unwind('$tags')
->group(
[
'_id' => ['tags' => '$tags'],
'_id' => ['tags' => '$tags', 'sum' => $exp->sum('$sumField')],
'authors' => $exp->addToSet('$author'),
'sum' => $exp->sum('$fieldSum'),
]
)
->project(['author' => true, 'tags' => true])
->unwind('$tags')
->getQuery();

$this->assertEquals($pipeline, $query->getPipeline());
Expand Down

0 comments on commit 254dea8

Please sign in to comment.