diff --git a/src/LaravelCommode/Common/GhostService/GhostService.php b/src/LaravelCommode/Common/GhostService/GhostService.php index 6f27226..2e6881d 100755 --- a/src/LaravelCommode/Common/GhostService/GhostService.php +++ b/src/LaravelCommode/Common/GhostService/GhostService.php @@ -90,8 +90,9 @@ private function prepareService() /** * Register service proviers in laravel app + * differing from already used ones */ - $this->services($services); + $this->services(array_diff($services, array_keys($this->app->getLoadedProviders()))); /** * Mark current service as registered @@ -223,6 +224,7 @@ private function services(array $services = []) { foreach($services as $service) { + $this->app->forceRegister($service, []); } } diff --git a/tests/GhostService/GhostServiceTest.php b/tests/GhostService/GhostServiceTest.php index e322179..bb66bf6 100644 --- a/tests/GhostService/GhostServiceTest.php +++ b/tests/GhostService/GhostServiceTest.php @@ -86,6 +86,7 @@ public function testRegistrationEmpty() $appMock = $this->buildAppMockForUseTest(); $appMock->shouldReceive('bound')->once()->andReturn(false); + $appMock->shouldReceive('getLoadedProviders')->zeroOrMoreTimes()->andReturn([]); $appMock->shouldReceive('forceRegister')->once(); /** @@ -105,6 +106,7 @@ public function testRegistration() $appMock = $this->buildAppMockForUseTest(); $appMock->shouldReceive('bound')->once()->andReturn(true); + $appMock->shouldReceive('getLoadedProviders')->zeroOrMoreTimes()->andReturn([]); /** * @var \PHPUnit_Framework_MockObject_MockObject|GhostService $service @@ -128,6 +130,7 @@ public function testUsesAllNew() $resolver = new Resolver($resolverAppMock); $appMock = $this->buildAppMock(); + $appMock->shouldReceive('getLoadedProviders')->zeroOrMoreTimes()->andReturn([]); $appMock->shouldReceive('bound')->zeroOrMoreTimes()->andReturn(false, true); @@ -186,6 +189,8 @@ public function testUses() $appMock = $this->buildAppMock(); + $appMock->shouldReceive('getLoadedProviders')->zeroOrMoreTimes()->andReturn([]); + $appMock->shouldReceive('bound')->zeroOrMoreTimes()->andReturn(true, true); $appMock->shouldReceive('forceRegister')->twice()->andReturnUsing(function($service) use ($additionals)