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\\Db\\LoggerInterface', 'logger', $connection); }
public function testCreate() { $cacheAdapterMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\DdlCache')->disableOriginalConstructor()->getMock(); $loggerMock = $this->getMockBuilder('Magento\\Framework\\DB\\LoggerInterface')->disableOriginalConstructor()->getMock(); $adapterClass = 'Magento\\Framework\\App\\ResourceConnection\\ConnectionAdapterInterface'; $connectionAdapterMock = $this->getMockBuilder($adapterClass)->disableOriginalConstructor()->getMock(); $connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock(); $connectionMock->expects($this->once())->method('setCacheAdapter')->with($cacheAdapterMock)->willReturnSelf(); $connectionAdapterMock->expects($this->once())->method('getConnection')->with($loggerMock)->will($this->returnValue($connectionMock)); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Framework\\App\\ResourceConnection\\ConnectionAdapterInterface')->will($this->returnValue($connectionAdapterMock)); $this->objectManagerMock->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Framework\\DB\\LoggerInterface', $loggerMock], ['Magento\\Framework\\DB\\Adapter\\DdlCache', $cacheAdapterMock]])); $this->assertSame($connectionMock, $this->model->create(['active' => true])); }