Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HavingRendererTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class HavingRendererTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $model;
20 
24  protected $selectMock;
25 
31  protected function setUp()
32  {
33  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
34  $this->selectMock = $this->createPartialMock(\Magento\Framework\DB\Select::class, ['getPart']);
35  $this->model = $objectManager->getObject(\Magento\Framework\DB\Select\HavingRenderer::class);
36  }
37 
42  public function testRenderNoPart($mapValues)
43  {
44  $sql = 'SELECT';
45  $this->selectMock->expects($this->any())
46  ->method('getPart')
47  ->willReturnMap($mapValues);
48  $this->assertEquals($sql, $this->model->render($this->selectMock, $sql));
49  }
50 
55  public function renderNoPartDataProvider()
56  {
57  return [
58  [[[Select::FROM, false], [Select::HAVING, false]]],
59  [[[Select::FROM, true], [Select::HAVING, false]]],
60  [[[Select::FROM, false], [Select::HAVING, true]]],
61  ];
62  }
63 
64  public function testRender()
65  {
66  $sql = 'SELECT';
67  $expectedResult = $sql . ' ' . Select::SQL_HAVING . ' having1 having2';
68  $mapValues = [
69  [Select::FROM, true],
70  [Select::HAVING, ['having1', 'having2']]
71  ];
72  $this->selectMock->expects($this->any())
73  ->method('getPart')
74  ->willReturnMap($mapValues);
75  $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
76  }
77 }
const HAVING
Definition: Select.php:53
$objectManager
Definition: bootstrap.php:17
const FROM
Definition: Select.php:49
const SQL_HAVING
Definition: Select.php:75