Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SelectBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class SelectBuilderTest extends \PHPUnit\Framework\TestCase
14 {
18  private $selectBuilder;
19 
23  private $resourceConnectionMock;
24 
28  private $connectionMock;
29 
33  private $selectMock;
34 
38  protected function setUp()
39  {
40  $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class)
41  ->disableOriginalConstructor()
42  ->getMock();
43 
44  $this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
45  ->disableOriginalConstructor()
46  ->getMock();
47 
48  $this->selectMock = $this->getMockBuilder(Select::class)
49  ->disableOriginalConstructor()
50  ->getMock();
51 
52  $this->selectBuilder = new SelectBuilder($this->resourceConnectionMock);
53  }
54 
55  public function testCreate()
56  {
57  $connectionName = 'MySql';
58  $from = ['customer c'];
59  $columns = ['id', 'name', 'price'];
60  $filter = 'filter';
61  $joins = [
62  ['link-type' => 'left', 'table' => 'customer', 'condition' => 'in'],
63  ['link-type' => 'inner', 'table' => 'price', 'condition' => 'eq'],
64  ['link-type' => 'right', 'table' => 'attribute', 'condition' => 'neq'],
65  ];
66  $groups = ['id', 'name'];
67  $this->selectBuilder->setConnectionName($connectionName);
68  $this->selectBuilder->setFrom($from);
69  $this->selectBuilder->setColumns($columns);
70  $this->selectBuilder->setFilters([$filter]);
71  $this->selectBuilder->setJoins($joins);
72  $this->selectBuilder->setGroup($groups);
73  $this->resourceConnectionMock->expects($this->once())
74  ->method('getConnection')
75  ->with($connectionName)
76  ->willReturn($this->connectionMock);
77  $this->connectionMock->expects($this->once())
78  ->method('select')
79  ->willReturn($this->selectMock);
80  $this->selectMock->expects($this->once())
81  ->method('from')
82  ->with($from, []);
83  $this->selectMock->expects($this->once())
84  ->method('columns')
85  ->with($columns);
86  $this->selectMock->expects($this->once())
87  ->method('where')
88  ->with($filter);
89  $this->selectMock->expects($this->once())
90  ->method('joinLeft')
91  ->with($joins[0]['table'], $joins[0]['condition'], []);
92  $this->selectMock->expects($this->once())
93  ->method('joinInner')
94  ->with($joins[1]['table'], $joins[1]['condition'], []);
95  $this->selectMock->expects($this->once())
96  ->method('joinRight')
97  ->with($joins[2]['table'], $joins[2]['condition'], []);
98  $this->selectBuilder->create();
99  }
100 }
$columns
Definition: default.phtml:15