getMockBuilder(UrlGenerator::class) ->getMock(); /** @var PHPUnit_Framework_MockObject_MockObject|Application $app */ $app = $this->getMockBuilder(Application::class) ->setMethods(['make', 'instance']) ->getMock(); $app->expects($this->once()) ->method('make') ->with(UrlGenerator::class) ->willReturn($urlGenerator); $app->expects($this->once()) ->method('instance') ->with('routing.urlGenerator', $urlGenerator); $serviceProvider = new RoutingServiceProvider($app); $serviceProvider->register(); } }