instanceOf(ContainerWrapper::class); verify($instance)->instanceOf(ContainerInterface::class); $instance = new ContainerWrapper(new ContainerBuilder(), new ContainerBuilder()); verify($instance)->instanceOf(ContainerWrapper::class); verify($instance)->instanceOf(ContainerInterface::class); } public function testItProvidesPremiumContainerIfAvailable() { $instance = new ContainerWrapper(new ContainerBuilder()); verify($instance->getPremiumContainer())->null(); $instance = new ContainerWrapper(new ContainerBuilder(), new ContainerBuilder()); verify($instance->getPremiumContainer())->instanceOf(ContainerBuilder::class); } public function testItProvidesFreePluginServices() { $freeContainerStub = Stub::make(Container::class, [ 'get' => function () { return new TestService(); }, ]); $instance = new ContainerWrapper($freeContainerStub); $service = $instance->get(TestService::class); $this->assertInstanceOf(TestService::class, $service); } public function testItThrowsFreePluginServices() { $freeContainerStub = Stub::make(Container::class, [ 'get' => function ($id) { throw new ServiceNotFoundException($id); }, ]); $instance = new ContainerWrapper($freeContainerStub); $exception = null; try { /* @phpstan-ignore-next-line - normally it is not allowed to pass an arbitrary string here, but we want to test this behaviour */ $instance->get('service'); } catch (ServiceNotFoundException $e) { $exception = $e; } verify($exception)->instanceOf(ServiceNotFoundException::class); } public function testItReturnServiceFromPremium() { $freeContainerStub = Stub::make(Container::class, [ 'get' => function ($id) { throw new ServiceNotFoundException($id); }, ]); $premiumContainerStub = Stub::make(Container::class, [ 'has' => function () { return true; }, 'get' => function () { return new TestService(); }, ]); $instance = new ContainerWrapper($freeContainerStub, $premiumContainerStub); $service = $instance->get(TestService::class); $this->assertInstanceOf(TestService::class, $service); } public function testItThrowsIfServiceNotFoundInBothContainers() { $containerStub = Stub::make(Container::class, [ 'get' => function ($id) { throw new ServiceNotFoundException($id); }, ]); $instance = new ContainerWrapper($containerStub, $containerStub); $exception = null; try { /* @phpstan-ignore-next-line - normally it is not allowed to pass an arbitrary string here, but we want to test this behaviour */ $instance->get('service'); } catch (ServiceNotFoundException $e) { $exception = $e; } verify($exception)->instanceOf(ServiceNotFoundException::class); } }