37 unset($this->_actualUpdateResult);
38 unset($this->_actualWhere);
39 unset($this->_selectMock);
53 $this->_selectMock = $this->createMock(\
Magento\Framework\DB\Select::class);
54 $this->_selectMock->expects($this->any())->method(
'from')->will($this->returnSelf());
55 $this->_selectMock->expects(
60 $this->returnCallback([$this,
'whereCallback'])
63 $connectionMock = $this->createPartialMock(
64 \
Magento\Framework\DB\Adapter\Pdo\Mysql::class,
65 [
'select',
'update',
'fetchAll',
'fetchOne']
67 $connectionMock->expects($this->any())->method(
'select')->will($this->returnValue($this->_selectMock));
68 $connectionMock->expects(
73 $this->returnCallback([$this,
'updateCallback'])
75 $connectionMock->expects($this->any())->method(
'fetchAll')->will($this->returnValue($tableData));
76 $connectionMock->expects($this->any())->method(
'fetchOne')->will($this->returnValue($tableRowsCount));
79 'resource_config' =>
'not_used',
80 'connection_config' =>
'not_used',
81 'module_config' =>
'not_used',
82 'base_dir' =>
'not_used',
83 'path_to_map_file' =>
'not_used',
84 'connection' => $connectionMock,
85 'core_helper' => $this->createMock(\
Magento\Framework\
Json\Helper\Data::class),
86 'aliases_map' => $aliasesMap
100 $replacements = array_values($bind);
102 $this->_actualUpdateResult[] = [
105 'to' => $replacements[0],
118 if (
null === $this->_actualWhere) {
119 $this->_actualWhere = [];
121 if (!empty($condition) &&
false === strpos(
129 $this->_actualWhere[] = $condition;
139 $setupMock = $this->getMockForAbstractClass(\
Magento\Framework\
Setup\ModuleDataSetupInterface::class);
140 $filesystemMock = $this->createMock(\
Magento\Framework\Filesystem::class);
141 $migrationData = $this->createMock(\
Magento\Framework\Module\
Setup\MigrationData::class);
143 $setupModel = new \Magento\Framework\Module\Setup\Migration(
147 'app/etc/aliases_to_classes_map.json',
149 $this->getSerializerMock()
152 $setupModel->appendClassAliasReplace(
157 [
'pk_field1',
'pk_field2'],
161 $expectedRulesList = [
164 'entity_type' =>
'entityType',
165 'content_type' =>
'fieldContentType',
166 'pk_fields' => [
'pk_field1',
'pk_field2'],
167 'additional_where' =>
'additionalWhere',
172 $this->assertAttributeEquals($expectedRulesList,
'_replaceRules', $setupModel);
175 $setupModel->appendClassAliasReplace(
179 'newFieldContentType',
180 [
'new_pk_field1',
'new_pk_field2'],
183 $this->assertAttributeEquals($expectedRulesList,
'_replaceRules', $setupModel);
191 $this->markTestIncomplete(
'Requires refactoring of class that is tested, covers to many methods');
193 $this->_actualUpdateResult = [];
194 $tableRowsCount = count($tableData);
196 $setupMock = $this->getMockForAbstractClass(\
Magento\Framework\
Setup\ModuleDataSetupInterface::class);
197 $filesystemMock = $this->createMock(\
Magento\Framework\Filesystem::class);
198 $migrationData = $this->createMock(\
Magento\Framework\Module\
Setup\MigrationData::class);
200 $setupModel = new \Magento\Framework\Module\Setup\Migration(
204 'app/etc/aliases_to_classes_map.json',
206 $this->getSerializerMock()
209 foreach ($replaceRules as $replaceRule) {
210 call_user_func_array([$setupModel,
'appendClassAliasReplace'], $replaceRule);
213 $setupModel->doUpdateClassAliases();
215 $this->assertEquals($expected[
'updates'], $this->_actualUpdateResult);
217 if (isset($expected[
'where'])) {
218 $this->assertEquals($expected[
'where'], $this->_actualWhere);
221 if (isset($expected[
'aliases_map'])) {
222 $this->assertAttributeEquals($expected[
'aliases_map'],
'_aliasesMap', $setupModel);
234 'plain text replace model' => include
__DIR__ .
'/_files/data_content_plain_model.php',
235 'plain text replace resource' => include
__DIR__ .
'/_files/data_content_plain_resource.php',
236 'plain text replace with pk field' => include
__DIR__ .
'/_files/data_content_plain_pk_fields.php',
237 'xml replace' => include
__DIR__ .
'/_files/data_content_xml.php',
238 'wiki markup replace' => include
__DIR__ .
'/_files/data_content_wiki.php',
239 'serialized php replace' => include
__DIR__ .
'/_files/data_content_serialized.php' 248 $mock = $this->getMockBuilder(\
Magento\Framework\Filesystem::class)->disableOriginalConstructor()->getMock();
256 private function getSerializerMock()
258 $serializerMock = $this->getMockBuilder(\
Magento\Framework\
Serialize\Serializer\Json::class)
261 $serializerMock->expects($this->any())
262 ->method(
'unserialize')
263 ->willReturnCallback(
264 function ($serializedData) {
265 return json_decode($serializedData,
true);
268 return $serializerMock;
testAppendClassAliasReplace()
defined('TESTS_BP')||define('TESTS_BP' __DIR__
updateCallback($table, array $bind, $where)
updateClassAliasesDataProvider()
testDoUpdateClassAliases($replaceRules, $tableData, $expected, $aliasesMap=[])
whereCallback($condition)
_getModelDependencies($tableRowsCount=0, $tableData=[], $aliasesMap=[])