Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GridStructureTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class GridStructureTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $resource;
18 
22  protected $flatScopeResolver;
23 
27  protected $connection;
28 
32  protected $object;
33 
34  protected function setUp()
35  {
36  $this->connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
37  ->getMock();
38  $this->resource = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41  $this->flatScopeResolver = $this->getMockBuilder(
42  \Magento\Framework\Indexer\ScopeResolver\FlatScopeResolver::class
43  )
44  ->disableOriginalConstructor()
45  ->getMock();
46  $this->resource->expects($this->any())
47  ->method('getConnection')
48  ->with('write')
49  ->willReturn($this->connection);
50  $this->object = new GridStructure(
51  $this->resource,
52  $this->flatScopeResolver
53  );
54  }
55 
56  public function testDelete()
57  {
58  $index = 'index';
59  $table = 'index_table';
60 
61  $this->flatScopeResolver->expects($this->once())
62  ->method('resolve')
63  ->with($index, [])
64  ->willReturn($table);
65  $this->connection->expects($this->once())
66  ->method('isTableExists')
67  ->with($table)
68  ->willReturn(true);
69  $this->connection->expects($this->once())
70  ->method('dropTable')
71  ->with($table);
72 
73  $this->object->delete($index);
74  }
75 
76  public function testCreate()
77  {
78  $index = 'index';
79  $fields = [
80  [
81  'type' => 'searchable',
82  'name' => 'field',
83  'dataType' => 'int'
84  ]
85  ];
86  $tableName = 'index_table';
87  $idxName = 'idxName';
88 
89  $table = $this->getMockBuilder(\Magento\Framework\DB\Ddl\Table::class)
90  ->disableOriginalConstructor()
91  ->getMock();
92  $this->flatScopeResolver->expects($this->once())
93  ->method('resolve')
94  ->with($index, [])
95  ->willReturn($tableName);
96  $this->connection->expects($this->once())
97  ->method('newTable')
98  ->with($tableName)
99  ->willReturn($table);
100  $table->expects($this->any())
101  ->method('addColumn')
102  ->willReturnMap(
103  [
104  ['entity_id', Table::TYPE_INTEGER, 10, ['unsigned' => true, 'nullable' => false], 'Entity ID'],
105  ['field', Table::TYPE_INTEGER, null]
106  ]
107  );
108  $this->connection->expects($this->once())
109  ->method('createTable')
110  ->with($table);
111  $this->resource->expects($this->once())
112  ->method('getIdxName')
114  ->willReturn($idxName);
115  $table->expects($this->once())
116  ->method('addIndex')
117  ->with($idxName, ['field'], ['type' => AdapterInterface::INDEX_TYPE_FULLTEXT]);
118  $this->object->create($index, $fields);
119  }
120 }
$tableName
Definition: trigger.php:13
$fields
Definition: details.phtml:14
$table
Definition: trigger.php:14
$index
Definition: list.phtml:44