resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class) ->disableOriginalConstructor() ->getMock(); $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) ->disableOriginalConstructor() ->getMock(); $this->connectionMock = $this->getMockBuilder(MysqlPdoAdapter::class) ->disableOriginalConstructor() ->getMock(); $this->connectionNewMock = $this->getMockBuilder(MysqlPdoAdapter::class) ->disableOriginalConstructor() ->getMock(); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->connectionFactory = $this->objectManagerHelper->getObject( ConnectionFactory::class, [ 'resourceConnection' => $this->resourceConnectionMock, 'objectManager' => $this->objectManagerMock, ] ); } public function testGetConnection() { $connectionName = 'read'; $this->resourceConnectionMock ->expects($this->once()) ->method('getConnection') ->with($connectionName) ->willReturn($this->connectionMock); $this->connectionMock ->expects($this->once()) ->method('getConfig') ->with() ->willReturn(['persistent' => 1]); $this->objectManagerMock ->expects($this->once()) ->method('create') ->with(get_class($this->connectionMock), ['config' => ['use_buffered_query' => false]]) ->willReturn($this->connectionNewMock); $this->assertSame($this->connectionNewMock, $this->connectionFactory->getConnection($connectionName)); } }