25 private $deploymentConfigMock;
30 private $connectionFactoryMock;
35 private $objectManager;
44 $this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
45 ->disableOriginalConstructor()
48 $this->connectionFactoryMock = $this->getMockBuilder(ConnectionFactoryInterface::class)
51 $this->configMock = $this->getMockBuilder(ConfigInterface::class)->getMock();
54 $this->unit = $this->objectManager->getObject(
55 ResourceConnection::class,
57 'deploymentConfig' => $this->deploymentConfigMock,
58 'connectionFactory' => $this->connectionFactoryMock,
59 'config' => $this->configMock,
64 public function testGetTablePrefixWithInjectedPrefix()
68 ResourceConnection::class,
70 'deploymentConfig' => $this->deploymentConfigMock,
71 'connectionFactory' => $this->connectionFactoryMock,
72 'config' => $this->configMock,
73 'tablePrefix' =>
'some_prefix' 82 $this->deploymentConfigMock->expects(self::once())
85 ->willReturn(
'pref_');
86 self::assertEquals(
'pref_', $this->unit->getTablePrefix());
91 $this->deploymentConfigMock->expects(self::once())->method(
'get')
93 ->willReturn([
'config']);
94 $this->connectionFactoryMock->expects(self::once())->method(
'create')
96 ->willReturn(
'connection');
98 self::assertEquals(
'connection', $this->unit->getConnectionByName(
'default'));
103 $unit = $this->objectManager->getObject(
104 ResourceConnection::class,
106 'deploymentConfig' => $this->deploymentConfigMock,
107 'connections' => [
'default_process_' . getmypid() =>
'existing_connection']
110 $this->deploymentConfigMock->expects(self::never())->method(
'get');
112 self::assertEquals(
'existing_connection', $unit->getConnectionByName(
'default'));
117 $this->configMock->expects(self::once())->method(
'getConnectionName')->with(
'default');
119 $this->unit->closeConnection(
'default');
const CONFIG_PATH_DB_PREFIX
testGetConnectionByName()
const CONFIG_PATH_DB_CONNECTIONS
testGetExistingConnectionByName()