select = $this->getMockBuilder(\Magento\Framework\DB\Select::class) ->disableOriginalConstructor() ->getMock(); $this->connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class) ->disableOriginalConstructor() ->getMock(); $this->connection->expects($this->any())->method('select')->willReturn($this->select); $this->resource = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class) ->disableOriginalConstructor() ->setMethods(['getConnection', 'getMainTable', 'getTable']) ->getMockForAbstractClass(); $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection); $this->resource->expects($this->any())->method('getMainTable')->willReturn('table_test'); $this->resource->expects($this->any())->method('getTable')->willReturn('test'); $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); } }