41 private $objectManagerHelper;
46 private $shardingMock;
51 private $resourceConnectionMock;
56 private $statementFactoryMock;
61 private $dbSchemaWriterMock;
66 private $statementAggregatorFactoryMock;
71 private $createTableOperation;
80 $this->shardingMock = $this->getMockBuilder(Sharding::class)
81 ->disableOriginalConstructor()
83 $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class)
84 ->disableOriginalConstructor()
86 $this->statementFactoryMock = $this->getMockBuilder(StatementFactory::class)
87 ->disableOriginalConstructor()
89 $this->dbSchemaWriterMock = $this->getMockBuilder(DbSchemaWriterInterface::class)
90 ->getMockForAbstractClass();
91 $this->statementAggregatorFactoryMock = $this->getMockBuilder(StatementAggregatorFactory::class)
92 ->disableOriginalConstructor()
94 $this->createTableOperation = $this->getMockBuilder(CreateTable::class)
95 ->disableOriginalConstructor()
97 $this->createTableOperation->expects(self::exactly(2))
98 ->method(
'getOperationName')
99 ->willReturn(
'create_table');
100 $this->dropElement = $this->getMockBuilder(DropElement::class)
101 ->disableOriginalConstructor()
103 $this->objectManagerHelper =
new ObjectManagerHelper($this);
104 $this->model = $this->objectManagerHelper->getObject(
105 \
Magento\Framework\Setup\Declaration\Schema\OperationsExecutor::class,
108 'create_table' => $this->createTableOperation,
109 'drop_element' => $this->dropElement
111 'dataSaviorsCollection' => [],
112 'sharding' => $this->shardingMock,
113 'resourceConnection' => $this->resourceConnectionMock,
114 'statementFactory' => $this->statementFactoryMock,
115 'dbSchemaWriter' => $this->dbSchemaWriterMock,
116 'statementAggregatorFactory' => $this->statementAggregatorFactoryMock
124 private function prepareTable()
145 $table->addColumns([$column]);
149 public function testExecute()
152 $diff = $this->getMockBuilder(DiffInterface::class)
154 $this->shardingMock->expects(self::exactly(2))
155 ->method(
'getResources')
156 ->willReturn([
'default']);
157 $connectionMock = $this->getMockBuilder(Mysql::class)
158 ->disableOriginalConstructor()
160 $this->resourceConnectionMock->expects(self::exactly(3))
161 ->method(
'getConnection')
163 ->willReturn($connectionMock);
164 $statementAggregator = $this->getMockBuilder(StatementAggregator::class)
165 ->disableOriginalConstructor()
167 $this->statementAggregatorFactoryMock->expects(self::once())
169 ->willReturn($statementAggregator);
170 $elementHistory =
new ElementHistory($this->prepareTable());
173 'create_table' => [$elementHistory]
176 $this->createTableOperation->expects(self::once())
177 ->method(
'doOperation')
178 ->with($elementHistory)
179 ->willReturn([
'TABLE table (`int` INT(11))']);
180 $statementAggregator->expects(self::once())
181 ->method(
'addStatements')
182 ->with([
'TABLE table (`int` INT(11))']);
183 $this->dbSchemaWriterMock->expects(self::once())
185 ->with($statementAggregator);
186 $diff->expects(self::once())
188 ->willReturn($tablesHistories);
189 $this->dropElement->expects(self::at(0))
190 ->method(
'doOperation');
191 $this->model->execute($diff, []);