public function testCreate()
 {
     $dbInstance = \Magento\TestFramework\Helper\Bootstrap::getInstance()->getBootstrap()->getApplication()->getDbInstance();
     $dbConfig = ['host' => $dbInstance->getHost(), 'username' => $dbInstance->getUser(), 'password' => $dbInstance->getPassword(), 'dbname' => $dbInstance->getSchema(), 'active' => true];
     $connection = $this->model->create($dbConfig);
     $this->assertInstanceOf('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', $connection);
     $this->assertAttributeInstanceOf('\\Magento\\Framework\\Cache\\FrontendInterface', '_cacheAdapter', $connection);
     $this->assertAttributeInstanceOf('\\Magento\\Framework\\Db\\LoggerInterface', 'logger', $connection);
 }
Пример #2
0
 public function testCreate()
 {
     $cacheAdapterMock = $this->getMockBuilder('Magento\\Framework\\Cache\\FrontendInterface')->disableOriginalConstructor()->getMock();
     $loggerMock = $this->getMockBuilder('Magento\\Framework\\DB\\LoggerInterface')->disableOriginalConstructor()->getMock();
     $connectionAdapterMock = $this->getMockBuilder('Magento\\Framework\\App\\Resource\\ConnectionAdapterInterface')->disableOriginalConstructor()->getMock();
     $adapterInstanceMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock();
     $adapterInstanceMock->expects($this->once())->method('setCacheAdapter')->with($cacheAdapterMock)->willReturnSelf();
     $connectionAdapterMock->expects($this->once())->method('getConnection')->with($loggerMock)->will($this->returnValue($adapterInstanceMock));
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Resource\\ConnectionAdapterInterface')->will($this->returnValue($connectionAdapterMock));
     $poolMock = $this->getMockBuilder('Magento\\Framework\\App\\Cache\\Type\\FrontendPool')->disableOriginalConstructor()->getMock();
     $poolMock->expects($this->once())->method('get')->with(DdlCache::TYPE_IDENTIFIER)->will($this->returnValue($cacheAdapterMock));
     $this->objectManagerMock->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Framework\\DB\\LoggerInterface', $loggerMock], ['Magento\\Framework\\App\\Cache\\Type\\FrontendPool', $poolMock]]));
     $this->assertSame($adapterInstanceMock, $this->model->create(['active' => true]));
 }
Пример #3
0
 public function testCreate()
 {
     $config = ['active' => 1, 'adapter' => 'Magento\\Framework\\App\\Resource\\ConnectionAdapterInterface'];
     $this->localConfig->expects($this->once())->method('getConnection')->with('connection_name')->will($this->returnValue($config));
     $adapterMock = $this->getMock('Magento\\Framework\\App\\Resource\\ConnectionAdapterInterface');
     $this->objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Resource\\ConnectionAdapterInterface', $config)->will($this->returnValue($adapterMock));
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $adapterMock->expects($this->once())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->assertEquals($connectionMock, $this->model->create('connection_name'));
 }
Пример #4
0
 /**
  * Retrieve connection to resource specified by $resourceName
  *
  * @param string $resourceName
  * @return \Magento\Framework\DB\Adapter\AdapterInterface|false
  */
 public function getConnection($resourceName)
 {
     $connectionName = $this->_config->getConnectionName($resourceName);
     if (isset($this->_connections[$connectionName])) {
         return $this->_connections[$connectionName];
     }
     $connection = $this->_connectionFactory->create($connectionName);
     if (!$connection) {
         return false;
     }
     $connection->setCacheAdapter($this->_cache->getFrontend());
     $this->_connections[$connectionName] = $connection;
     return $connection;
 }