/** * @param bool $readToIndex * @dataProvider insertFromTableData */ public function testInsertFromTable($readToIndex) { $sourceTable = 'catalog_category_flat'; $destTable = 'catalog_category_flat'; $resultColumns = [0 => 'column']; $tableColumns = ['column' => 'column']; $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false); $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false); $connectionMock->expects($this->any())->method('describeTable')->will($this->returnValue($tableColumns)); $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock)); $selectMock->expects($this->any())->method('from')->will($this->returnSelf()); if ($readToIndex) { $connectionCustomMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\CustomAdapterInterface', ['describeTable', 'query', 'select', 'insertArray'], [], '', false); $pdoMock = $this->getMock('Zend_Db_Statement_Pdo', [], [], '', false); $connectionCustomMock->expects($this->any())->method('query')->will($this->returnValue($selectMock)); $connectionCustomMock->expects($this->any())->method('select')->will($this->returnValue($selectMock)); $connectionCustomMock->expects($this->any())->method('describeTable')->will($this->returnValue($tableColumns)); $connectionCustomMock->expects($this->exactly(1))->method('insertArray')->with($destTable, $resultColumns)->will($this->returnValue(1)); $connectionMock->expects($this->any())->method('query')->will($this->returnValue($pdoMock)); $pdoMock->expects($this->at(0))->method('fetch')->will($this->returnValue([$tableColumns])); $pdoMock->expects($this->at(1))->method('fetch')->will($this->returnValue([$tableColumns])); $this->model->newIndexAdapter(); $this->_resourceMock->expects($this->at(0))->method('getConnection')->with('core_write')->will($this->returnValue($connectionMock)); $this->_resourceMock->expects($this->at(1))->method('getConnection')->with('core_new_write')->will($this->returnValue($connectionCustomMock)); } else { $selectMock->expects($this->once())->method('insertFromSelect')->with($destTable, $resultColumns)->will($this->returnSelf()); $this->_resourceMock->expects($this->any())->method('getTableName')->will($this->returnArgument(0)); $this->_resourceMock->expects($this->any())->method('getConnection')->with('core_write')->will($this->returnValue($connectionMock)); } $this->assertInstanceOf('Magento\\Indexer\\Test\\Unit\\Model\\Resource\\AbstractResourceStub', $this->model->insertFromTable($sourceTable, $destTable, $readToIndex)); }