Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GroupRendererTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class GroupRendererTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $model;
20 
24  protected $quoteMock;
25 
29  protected $selectMock;
30 
36  protected function setUp()
37  {
38  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
39  $this->quoteMock = $this->createPartialMock(\Magento\Framework\DB\Platform\Quote::class, ['quoteIdentifier']);
40  $this->selectMock = $this->createPartialMock(\Magento\Framework\DB\Select::class, ['getPart']);
41  $this->model = $objectManager->getObject(
42  \Magento\Framework\DB\Select\GroupRenderer::class,
43  ['quote' => $this->quoteMock]
44  );
45  }
46 
51  public function testRenderNoPart($mapValues)
52  {
53  $sql = 'SELECT';
54  $this->selectMock->expects($this->any())
55  ->method('getPart')
56  ->willReturnMap($mapValues);
57  $this->assertEquals($sql, $this->model->render($this->selectMock, $sql));
58  }
59 
64  public function renderNoPartDataProvider()
65  {
66  return [
67  [[[Select::FROM, false], [Select::GROUP, false]]],
68  [[[Select::FROM, true], [Select::GROUP, false]]],
69  [[[Select::FROM, false], [Select::GROUP, true]]],
70  ];
71  }
72 
73  public function testRender()
74  {
75  $sql = 'SELECT';
76  $expectedResult = $sql . ' ' . Select::SQL_GROUP_BY . ' group1' . ",\n\t" . 'group2';
77  $mapValues = [
78  [Select::FROM, true],
79  [Select::GROUP, ['group1', 'group2']]
80  ];
81  $this->selectMock->expects($this->exactly(3))
82  ->method('getPart')
83  ->willReturnMap($mapValues);
84  $this->quoteMock->expects($this->exactly(2))
85  ->method('quoteIdentifier')
86  ->willReturnArgument(0);
87  $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
88  }
89 }
const SQL_GROUP_BY
Definition: Select.php:73
$objectManager
Definition: bootstrap.php:17
const FROM
Definition: Select.php:49
const GROUP
Definition: Select.php:52