getMockBuilder(Config::class) ->getMock(); /** @var MockObject|Application $app */ $app = $this->getMockBuilder(Application::class) ->setMethods(['get']) ->getMock(); Application::setInstance($app); $app->expects($this->once()) ->method('get') ->with('config') ->willReturn($config); $config->expects($this->atLeastOnce()) ->method('get') ->with('database') ->willReturn($this->getDbConfig()); $serviceProvider = new DatabaseServiceProvider($app); $serviceProvider->register(); } }