public function testBuild() { $expectedResult = ['count' => 'count(main_table.value)']; $this->requestBucket->expects($this->once())->method('getMetrics')->willReturn([$this->metric]); $this->metric->expects($this->once())->method('getType')->willReturn('count'); $metrics = $this->metrics->build($this->requestBucket); $this->assertEquals($expectedResult, $metrics); }
/** * {@inheritdoc} */ public function build(DataProviderInterface $dataProvider, array $dimensions, RequestBucketInterface $bucket, Table $entityIdsTable) { $metrics = $this->metricsBuilder->build($bucket); $select = $dataProvider->getDataSet($bucket, $dimensions, $entityIdsTable); $select->columns($metrics); $select->group(RequestBucketInterface::FIELD_VALUE); return $dataProvider->execute($select); }
/** * {@inheritdoc} */ public function build(DataProviderInterface $dataProvider, array $dimensions, RequestBucketInterface $bucket, Table $entityIdsTable) { /** @var RangeBucket $bucket */ $select = $dataProvider->getDataSet($bucket, $dimensions, $entityIdsTable); $metrics = $this->metricsBuilder->build($bucket); /** @var Select $fullQuery */ $fullQuery = $this->connection->select(); $fullQuery->from(['main_table' => $select], null); $fullQuery = $this->generateCase($fullQuery, $bucket->getRanges()); $fullQuery->columns($metrics); $fullQuery->group(new \Zend_Db_Expr('1')); return $dataProvider->execute($fullQuery); }
/** * Test for method "build" */ public function testBuild() { $productIds = [1, 2, 3]; $metrics = ['count' => 'count(*)']; $this->select->expects($this->once())->method('where')->withConsecutive(['main_table.entity_id IN (?)', $productIds]); $this->select->expects($this->once())->method('columns')->withConsecutive([$metrics]); $this->select->expects($this->once())->method('group')->withConsecutive(['value']); $this->metricsBuilder->expects($this->once())->method('build')->willReturn($metrics); $this->dataProvider->expects($this->once())->method('getDataSet')->willReturn($this->select); $this->dataProvider->expects($this->once())->method('execute')->willReturn($this->select); $result = $this->term->build($this->dataProvider, [], $this->bucket, $productIds); $this->assertEquals($this->select, $result); }
/** * Test for method "build" */ public function testBuild() { $metrics = ['count' => 'count(*)']; $this->select->expects($this->once())->method('columns')->withConsecutive([$metrics]); $this->select->expects($this->once())->method('group')->withConsecutive(['value']); $this->metricsBuilder->expects($this->once())->method('build')->willReturn($metrics); $this->dataProvider->expects($this->once())->method('getDataSet')->willReturn($this->select); $this->dataProvider->expects($this->once())->method('execute')->willReturn($this->select); /** @var \Magento\Framework\DB\Ddl\Table|\PHPUnit_Framework_MockObject_MockObject $table */ $table = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock(); $result = $this->term->build($this->dataProvider, [], $this->bucket, $table); $this->assertEquals($this->select, $result); }
/** * Test for method "build" */ public function testBuild() { $this->metricsBuilder->expects($this->once())->method('build')->willReturn(['metrics']); $this->bucket->expects($this->once())->method('getRanges')->willReturn([$this->range, $this->range, $this->range]); $this->range->expects($this->at(0))->method('getFrom')->willReturn(''); $this->range->expects($this->at(1))->method('getTo')->willReturn(50); $this->range->expects($this->at(2))->method('getFrom')->willReturn(50); $this->range->expects($this->at(3))->method('getTo')->willReturn(100); $this->range->expects($this->at(4))->method('getFrom')->willReturn(100); $this->range->expects($this->at(5))->method('getTo')->willReturn(''); $this->adapter->expects($this->once())->method('getCaseSql')->withConsecutive([''], [['`value` < 50' => "'*_50'", '`value` BETWEEN 50 AND 100' => "'50_100'", '`value` >= 100' => "'100_*'"]]); $this->dataProvider->expects($this->once())->method('getDataSet')->willReturn($this->select); $this->dataProvider->expects($this->once())->method('execute')->willReturn($this->select); $result = $this->builder->build($this->dataProvider, [], $this->bucket, [1, 2, 3]); $this->assertEquals($this->select, $result); }
/** * Test for method "build" */ public function testBuild() { $this->metricsBuilder->expects($this->once())->method('build')->willReturn(['metrics']); $this->bucket->expects($this->once())->method('getRanges')->willReturn([$this->range, $this->range, $this->range]); $this->range->expects($this->at(0))->method('getFrom')->willReturn(''); $this->range->expects($this->at(1))->method('getTo')->willReturn(50); $this->range->expects($this->at(2))->method('getFrom')->willReturn(50); $this->range->expects($this->at(3))->method('getTo')->willReturn(100); $this->range->expects($this->at(4))->method('getFrom')->willReturn(100); $this->range->expects($this->at(5))->method('getTo')->willReturn(''); $this->connectionMock->expects($this->once())->method('getCaseSql')->withConsecutive([''], [['`value` < 50' => "'*_50'", '`value` BETWEEN 50 AND 100' => "'50_100'", '`value` >= 100' => "'100_*'"]]); $this->dataProvider->expects($this->once())->method('getDataSet')->willReturn($this->select); $this->dataProvider->expects($this->once())->method('execute')->willReturn($this->select); /** @var \Magento\Framework\DB\Ddl\Table|\PHPUnit_Framework_MockObject_MockObject $table */ $table = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock(); $result = $this->builder->build($this->dataProvider, [], $this->bucket, $table); $this->assertEquals($this->select, $result); }