32 private $deploymentConfig;
46 $this->connectionFactory = $this->getMockBuilder(ConnectionFactoryInterface::class)
47 ->setMethods([
'create'])
48 ->getMockForAbstractClass();
50 ->disableOriginalConstructor()
51 ->setMethods([
'getConnectionName'])
53 $this->config->expects($this->any())
54 ->method(
'getConnectionName')
55 ->with(self::RESOURCE_NAME)
56 ->will($this->returnValue(self::CONNECTION_NAME));
58 $this->deploymentConfig = $this->createMock(\
Magento\Framework\
App\DeploymentConfig::class);
59 $this->deploymentConfig
60 ->expects($this->any())
68 'host' =>
'localhost',
69 'dbname' =>
'magento',
70 'username' =>
'username',
81 $this->connection = $this->getMockForAbstractClass(\
Magento\Framework\DB\Adapter\AdapterInterface::class);
82 $this->connection->expects($this->any())
83 ->method(
'getTableName')
84 ->will($this->returnArgument(0));
88 $this->connectionFactory,
89 $this->deploymentConfig
99 $this->resource->getConnectionByName(
'invalid');
104 $this->connectionFactory->expects($this->once())
106 ->will($this->returnValue($this->connection));
107 $this->assertSame($this->connection, $this->resource->getConnection(self::RESOURCE_NAME));
108 $this->assertSame($this->connection, $this->resource->getConnection(self::RESOURCE_NAME));
119 $this->connectionFactory->expects($this->once())
121 ->will($this->returnValue($this->connection));
122 $this->assertSame($expected, $this->resource->getTableName($modelEntity));
131 [
'tableName', self::TABLE_PREFIX .
'tableName'],
132 [[
'tableName',
'tableSuffix'], self::TABLE_PREFIX .
'tableName_tableSuffix'],
146 $this->connectionFactory->expects($this->once())
148 ->will($this->returnValue($this->connection));
149 $this->resource->setMappedTableName(
$tableName, $mappedName);
150 $this->assertSame($expected, $this->resource->getTableName($modelEntity));
159 [
'tableName',
'tableName',
'mappedTableName',
'mappedTableName'],
160 [[
'tableName',
'tableSuffix'],
'tableName',
'mappedTableName',
'mappedTableName_tableSuffix'],
167 $calculatedTableName = self::TABLE_PREFIX .
'table';
169 $indexType =
'index_type';
170 $expectedIdxName =
'idxName';
172 $this->connection->expects($this->once())
173 ->method(
'getIndexName')
174 ->with($calculatedTableName,
$fields, $indexType)
175 ->will($this->returnValue($expectedIdxName));
176 $this->connectionFactory->expects($this->once())
178 ->will($this->returnValue($this->connection));
180 $this->assertEquals(
'idxName', $this->resource->getIdxName(
$table,
$fields, $indexType));
186 $calculatedTableName = self::TABLE_PREFIX .
'table';
187 $refTable =
'ref_table';
188 $calculatedRefTableName = self::TABLE_PREFIX .
'ref_table';
189 $columnName =
'columnName';
190 $refColumnName =
'refColumnName';
192 $this->connection->expects($this->once())
193 ->method(
'getForeignKeyName')
194 ->with($calculatedTableName, $columnName, $calculatedRefTableName, $refColumnName)
195 ->will($this->returnValue(
'fkName'));
196 $this->connectionFactory->expects($this->once())
198 ->will($this->returnValue($this->connection));
200 $this->assertEquals(
'fkName', $this->resource->getFkName(
$table, $columnName, $refTable, $refColumnName));
208 $triggerName =
'trg_subject_table_before_insert';
210 $this->connectionFactory->expects($this->once())
212 ->will($this->returnValue($this->connection));
213 $this->connection->expects($this->once())
214 ->method(
'getTriggerName')
216 ->willReturn($triggerName);
217 $this->assertSame($triggerName, $this->resource->getTriggerName(
$tableName, $time, $event));
getTableNameMappedDataProvider()
testGetTableNameMapped($modelEntity, $tableName, $mappedName, $expected)
testGetConnectionInitConnection()
const CONFIG_PATH_DB_PREFIX
const CONFIG_PATH_DB_CONNECTIONS
testGetTableName($modelEntity, $expected)
getTableNameDataProvider()