/** * Query the dimensions. * * @param string $name Dimension name * @param string $value Dimension value * * @return Query\Dimensions */ public function dimension($name = null, $value = null) { $query = new Query\Dimensions($this->mongo, $this->entity, $this->ref, $this->dateRange); if (!empty($name)) { if (!empty($value)) { $query->setDimension($name, $value); } else { $query->setDimension($name); } } return $query; }
public function testGroups() { $defaultGroup = ['_id' => '$ts', 'totalCount' => ['$sum' => '$count.100']]; $pipeline = $this->instance->getPipeline(); $this->assertSame($defaultGroup, $pipeline[2]['$group']); $this->instance->groupByDimensionName(); $pipeline = $this->instance->getPipeline(); $defaultGroup['_id'] = '$name'; $this->assertSame($defaultGroup, $pipeline[2]['$group']); $this->instance->groupByDimensionValue(); $pipeline = $this->instance->getPipeline(); $defaultGroup['_id'] = ['name' => '$name', 'value' => '$value']; $this->assertSame($defaultGroup, $pipeline[2]['$group']); $this->instance->groupByEntityName(); $pipeline = $this->instance->getPipeline(); $defaultGroup['_id'] = '$entity'; $this->assertSame($defaultGroup, $pipeline[2]['$group']); }