public function setUp() { $this->connectionFactory = $this->getMockBuilder(ConnectionFactoryInterface::class)->setMethods(['create'])->getMockForAbstractClass(); $this->config = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection\\ConfigInterface')->disableOriginalConstructor()->setMethods(['getConnectionName'])->getMock(); $this->config->expects($this->any())->method('getConnectionName')->with(self::RESOURCE_NAME)->will($this->returnValue(self::CONNECTION_NAME)); $this->deploymentConfig = $this->getMock('Magento\\Framework\\App\\DeploymentConfig', [], [], '', false); $this->deploymentConfig->expects($this->any())->method('get')->willReturnMap([[ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS . '/connection-name', null, ['host' => 'localhost', 'dbname' => 'magento', 'username' => 'username']], [ConfigOptionsListConstants::CONFIG_PATH_DB_PREFIX, null, self::TABLE_PREFIX]]); $this->connection = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface'); $this->connection->expects($this->any())->method('getTableName')->will($this->returnArgument(0)); $this->resource = new ResourceConnection($this->config, $this->connectionFactory, $this->deploymentConfig); }
/** * Initialise data for configuration * @return void */ protected function initData() { $data = $this->cache->load($this->cacheId); if (false === $data) { $singleQuery = $this->config->getConnectionName('checkout_setup') == 'default' ? true : false; $data['checkout'] = $singleQuery; $this->cache->save(serialize($data), $this->cacheId, $this->cacheTags); } else { $data = unserialize($data); } $this->merge($data); }
/** * Retrieve connection to resource specified by $resourceName * * @param string $resourceName * @return \Magento\Framework\DB\Adapter\AdapterInterface * @throws \DomainException * @codeCoverageIgnore */ public function getConnection($resourceName = self::DEFAULT_CONNECTION) { $connectionName = $this->config->getConnectionName($resourceName); return $this->getConnectionByName($connectionName); }