diff --git a/benchmarks/BenchAsset/AbstractFactoryFoo.php b/benchmarks/BenchAsset/AbstractFactoryFoo.php index c6c26366..42cee972 100644 --- a/benchmarks/BenchAsset/AbstractFactoryFoo.php +++ b/benchmarks/BenchAsset/AbstractFactoryFoo.php @@ -4,8 +4,8 @@ namespace LaminasBench\ServiceManager\BenchAsset; -use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; +use Psr\Container\ContainerInterface; class AbstractFactoryFoo implements AbstractFactoryInterface { diff --git a/benchmarks/BenchAsset/FactoryFoo.php b/benchmarks/BenchAsset/FactoryFoo.php index 64d93564..7afc5263 100644 --- a/benchmarks/BenchAsset/FactoryFoo.php +++ b/benchmarks/BenchAsset/FactoryFoo.php @@ -4,8 +4,8 @@ namespace LaminasBench\ServiceManager\BenchAsset; -use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; class FactoryFoo implements FactoryInterface { diff --git a/composer.json b/composer.json index f2e637be..de942a8b 100644 --- a/composer.json +++ b/composer.json @@ -51,13 +51,13 @@ "vimeo/psalm": "^4.8" }, "provide": { - "container-interop/container-interop-implementation": "^1.2", "psr/container-implementation": "^1.0" }, "conflict": { + "container-interop/container-interop": "<1.2.0", + "laminas/laminas-code": "<3.3.1", "zendframework/zend-code": "<3.3.1", - "zendframework/zend-servicemanager": "*", - "laminas/laminas-code": "<3.3.1" + "zendframework/zend-servicemanager": "*" }, "suggest": { "ocramius/proxy-manager": "ProxyManager ^2.1.1 to handle lazy initialization of services" @@ -65,7 +65,8 @@ "autoload": { "psr-4": { "Laminas\\ServiceManager\\": "src/" - } + }, + "files": ["src/autoload.php"] }, "autoload-dev": { "files": [ @@ -91,5 +92,8 @@ "test": "phpunit --colors=always", "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", "static-analysis" : "psalm --shepherd --stats" + }, + "replace": { + "container-interop/container-interop": "^1.2.0" } } diff --git a/composer.lock b/composer.lock index d0269276..146719e1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,44 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0bbcf4fcb5f33eae8ebd29d4d8686df0", + "content-hash": "cbbcc3eeb089bbae147ad532381d5002", "packages": [ - { - "name": "container-interop/container-interop", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/container-interop/container-interop.git", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8", - "shasum": "" - }, - "require": { - "psr/container": "^1.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Interop\\Container\\": "src/Interop/Container/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", - "homepage": "https://github.com/container-interop/container-interop", - "support": { - "issues": "https://github.com/container-interop/container-interop/issues", - "source": "https://github.com/container-interop/container-interop/tree/master" - }, - "abandoned": "psr/container", - "time": "2017-02-14T19:40:03+00:00" - }, { "name": "laminas/laminas-stdlib", "version": "3.7.1", @@ -5467,5 +5431,5 @@ "platform-overrides": { "php": "7.4.99" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 76c0c413..3567d9d1 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + new $requestedName(...$arguments) @@ -53,9 +53,6 @@ - - gettype($configInstanceOrParentLocator) - setService @@ -304,21 +301,6 @@ assertInstanceOf assertInstanceOf - - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - $this->container->reveal() - array @@ -327,9 +309,6 @@ setServiceLocator - - getContainer - $callback @@ -549,46 +528,10 @@ $initializer - - method - method - willReturnCallback - - - $container - $container - - - $container - $this->proxyFactory - $this->proxyFactory - ContainerInterface|MockObject - LazyLoadingValueHolderFactory|MockObject - - - expects - expects - $wrappedInstance - - - new PsrContainerDecorator($psrContainer) - new PsrContainerDecorator($psrContainer) - new PsrContainerDecorator($psrContainer) - - - get - getContainer - has - has - new PsrContainerDecorator($psrContainer) - new PsrContainerDecorator($psrContainer) - new PsrContainerDecorator($psrContainer) - - $context diff --git a/psalm.xml.dist b/psalm.xml.dist index 07c8f69e..d71e2eec 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -17,6 +17,22 @@ + + + + + + + + + + + + + + + + diff --git a/src/AbstractFactory/ConfigAbstractFactory.php b/src/AbstractFactory/ConfigAbstractFactory.php index d6cb39e4..b51dfdf0 100644 --- a/src/AbstractFactory/ConfigAbstractFactory.php +++ b/src/AbstractFactory/ConfigAbstractFactory.php @@ -5,9 +5,9 @@ namespace Laminas\ServiceManager\AbstractFactory; use ArrayObject; -use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; +use Psr\Container\ContainerInterface; use function array_key_exists; use function array_map; diff --git a/src/AbstractFactory/ReflectionBasedAbstractFactory.php b/src/AbstractFactory/ReflectionBasedAbstractFactory.php index 99a76968..9d6bdc4a 100644 --- a/src/AbstractFactory/ReflectionBasedAbstractFactory.php +++ b/src/AbstractFactory/ReflectionBasedAbstractFactory.php @@ -4,9 +4,9 @@ namespace Laminas\ServiceManager\AbstractFactory; -use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; +use Psr\Container\ContainerInterface; use ReflectionClass; use ReflectionNamedType; use ReflectionParameter; diff --git a/src/AbstractFactoryInterface.php b/src/AbstractFactoryInterface.php index 9ea2976e..2a8ff71b 100644 --- a/src/AbstractFactoryInterface.php +++ b/src/AbstractFactoryInterface.php @@ -13,11 +13,11 @@ * * - rename the method `canCreateServiceWithName()` to `canCreate()`, and: * - rename the `$serviceLocator` argument to `$container`, and change the - * typehint to `Interop\Container\ContainerInterface` + * typehint to `Psr\Container\ContainerInterface` * - merge the `$name` and `$requestedName` arguments * - rename the method `createServiceWithName()` to `__invoke()`, and: * - rename the `$serviceLocator` argument to `$container`, and change the - * typehint to `Interop\Container\ContainerInterface` + * typehint to `Psr\Container\ContainerInterface` * - merge the `$name` and `$requestedName` arguments * - add the optional `array $options = null` argument. * - create a `canCreateServiceWithName()` method as defined in this interface, and have it diff --git a/src/AbstractPluginManager.php b/src/AbstractPluginManager.php index c67a9d69..21128a98 100644 --- a/src/AbstractPluginManager.php +++ b/src/AbstractPluginManager.php @@ -4,10 +4,9 @@ namespace Laminas\ServiceManager; -use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Exception\ContainerModificationsNotAllowedException; use Laminas\ServiceManager\Exception\InvalidServiceException; -use Psr\Container\ContainerInterface as PsrContainerInterface; +use Psr\Container\ContainerInterface; use function class_exists; use function get_class; @@ -58,23 +57,13 @@ abstract class AbstractPluginManager extends ServiceManager implements PluginMan * factories; for $config, {@see \Laminas\ServiceManager\ServiceManager::configure()} * for details on its accepted structure. * - * @param null|ConfigInterface|ContainerInterface|PsrContainerInterface $configInstanceOrParentLocator + * @param null|ConfigInterface|ContainerInterface $configInstanceOrParentLocator * @param array $config * @psalm-param ServiceManagerConfiguration $config */ public function __construct($configInstanceOrParentLocator = null, array $config = []) { - if ( - $configInstanceOrParentLocator instanceof PsrContainerInterface - && ! $configInstanceOrParentLocator instanceof ContainerInterface - ) { - /** - * {@see \Laminas\ServiceManager\Factory\FactoryInterface} typehints - * against interop container and as such cannot accept non-interop - * psr container. Decorate it as interop. - */ - $configInstanceOrParentLocator = new PsrContainerDecorator($configInstanceOrParentLocator); - } + /** @psalm-suppress DocblockTypeContradiction */ if ( null !== $configInstanceOrParentLocator && ! $configInstanceOrParentLocator instanceof ConfigInterface diff --git a/src/ConfigInterface.php b/src/ConfigInterface.php index 4120a1cf..a9c8fc59 100644 --- a/src/ConfigInterface.php +++ b/src/ConfigInterface.php @@ -5,7 +5,7 @@ namespace Laminas\ServiceManager; use ArrayAccess; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; /** * @see ContainerInterface diff --git a/src/DelegatorFactoryInterface.php b/src/DelegatorFactoryInterface.php index 3a5a8659..1b30ecf6 100644 --- a/src/DelegatorFactoryInterface.php +++ b/src/DelegatorFactoryInterface.php @@ -13,7 +13,7 @@ * * - rename the method `createDelegatorWithName()` to `__invoke()`, and: * - rename the `$serviceLocator` argument to `$container`, and change the - * typehint to `Interop\Container\ContainerInterface` + * typehint to `Psr\Container\ContainerInterface` * - merge the `$name` and `$requestedName` arguments * - add the `callable` typehint to the `$callback` argument * - add the optional `array $options = null` argument as a final argument diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index b8a18f7b..cccc42df 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -4,11 +4,11 @@ namespace Laminas\ServiceManager\Exception; -use Interop\Container\Exception\ContainerException; +use Psr\Container\ContainerExceptionInterface; /** * Base exception for all Laminas\ServiceManager exceptions. */ -interface ExceptionInterface extends ContainerException +interface ExceptionInterface extends ContainerExceptionInterface { } diff --git a/src/Exception/ServiceNotCreatedException.php b/src/Exception/ServiceNotCreatedException.php index dcb9de0d..3b9a4563 100644 --- a/src/Exception/ServiceNotCreatedException.php +++ b/src/Exception/ServiceNotCreatedException.php @@ -4,7 +4,6 @@ namespace Laminas\ServiceManager\Exception; -use Interop\Container\Exception\ContainerException; use RuntimeException as SplRuntimeException; /** @@ -12,7 +11,6 @@ * the service (factory that has an error...) */ class ServiceNotCreatedException extends SplRuntimeException implements - ContainerException, ExceptionInterface { } diff --git a/src/Exception/ServiceNotFoundException.php b/src/Exception/ServiceNotFoundException.php index 17287337..186f33cf 100644 --- a/src/Exception/ServiceNotFoundException.php +++ b/src/Exception/ServiceNotFoundException.php @@ -4,8 +4,8 @@ namespace Laminas\ServiceManager\Exception; -use Interop\Container\Exception\NotFoundException; use InvalidArgumentException as SplInvalidArgumentException; +use Psr\Container\NotFoundExceptionInterface; /** * This exception is thrown when the service locator do not manage to find a @@ -13,6 +13,6 @@ */ class ServiceNotFoundException extends SplInvalidArgumentException implements ExceptionInterface, - NotFoundException + NotFoundExceptionInterface { } diff --git a/src/Factory/AbstractFactoryInterface.php b/src/Factory/AbstractFactoryInterface.php index 4b4a952d..f73af4f7 100644 --- a/src/Factory/AbstractFactoryInterface.php +++ b/src/Factory/AbstractFactoryInterface.php @@ -4,7 +4,7 @@ namespace Laminas\ServiceManager\Factory; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; /** * Interface for an abstract factory. diff --git a/src/Factory/DelegatorFactoryInterface.php b/src/Factory/DelegatorFactoryInterface.php index 6fb0ce04..5e2702d9 100644 --- a/src/Factory/DelegatorFactoryInterface.php +++ b/src/Factory/DelegatorFactoryInterface.php @@ -4,10 +4,10 @@ namespace Laminas\ServiceManager\Factory; -use Interop\Container\ContainerInterface; -use Interop\Container\Exception\ContainerException; use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Laminas\ServiceManager\Exception\ServiceNotFoundException; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; /** * Delegator factory interface. @@ -28,7 +28,7 @@ interface DelegatorFactoryInterface * @return object * @throws ServiceNotFoundException If unable to resolve the service. * @throws ServiceNotCreatedException If an exception is raised when creating a service. - * @throws ContainerException If any other error occurs. + * @throws ContainerExceptionInterface If any other error occurs. */ public function __invoke(ContainerInterface $container, $name, callable $callback, ?array $options = null); } diff --git a/src/Factory/FactoryInterface.php b/src/Factory/FactoryInterface.php index a12cddea..68e61671 100644 --- a/src/Factory/FactoryInterface.php +++ b/src/Factory/FactoryInterface.php @@ -4,10 +4,10 @@ namespace Laminas\ServiceManager\Factory; -use Interop\Container\ContainerInterface; -use Interop\Container\Exception\ContainerException; use Laminas\ServiceManager\Exception\ServiceNotCreatedException; use Laminas\ServiceManager\Exception\ServiceNotFoundException; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; /** * Interface for a factory @@ -27,7 +27,7 @@ interface FactoryInterface * @return object * @throws ServiceNotFoundException If unable to resolve the service. * @throws ServiceNotCreatedException If an exception is raised when creating a service. - * @throws ContainerException If any other error occurs. + * @throws ContainerExceptionInterface If any other error occurs. */ public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null); } diff --git a/src/Factory/InvokableFactory.php b/src/Factory/InvokableFactory.php index cd6a3ad7..ab09e38e 100644 --- a/src/Factory/InvokableFactory.php +++ b/src/Factory/InvokableFactory.php @@ -4,7 +4,7 @@ namespace Laminas\ServiceManager\Factory; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; /** * Factory for instantiating classes with no dependencies or which accept a single array. diff --git a/src/FactoryInterface.php b/src/FactoryInterface.php index 2143905f..f22069ee 100644 --- a/src/FactoryInterface.php +++ b/src/FactoryInterface.php @@ -13,7 +13,7 @@ * * - rename the method `createService()` to `__invoke()`, and: * - rename the `$serviceLocator` argument to `$container`, and change the - * typehint to `Interop\Container\ContainerInterface` + * typehint to `Psr\Container\ContainerInterface` * - add the `$requestedName` as a second argument * - add the optional `array $options = null` argument as a final argument * - create a `createService()` method as defined in this interface, and have it diff --git a/src/Initializer/InitializerInterface.php b/src/Initializer/InitializerInterface.php index 95a88b7d..794f1dc5 100644 --- a/src/Initializer/InitializerInterface.php +++ b/src/Initializer/InitializerInterface.php @@ -4,7 +4,7 @@ namespace Laminas\ServiceManager\Initializer; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; /** * Interface for an initializer diff --git a/src/InitializerInterface.php b/src/InitializerInterface.php index 0c2d662e..f092e763 100644 --- a/src/InitializerInterface.php +++ b/src/InitializerInterface.php @@ -13,7 +13,7 @@ * * - rename the method `initialize()` to `__invoke()`, and: * - rename the `$serviceLocator` argument to `$container`, and change the - * typehint to `Interop\Container\ContainerInterface` + * typehint to `Psr\Container\ContainerInterface` * - swap the order of the arguments (so that `$instance` comes second) * - create an `initialize()` method as defined in this interface, and have it * proxy to `__invoke()`, passing the arguments in the new order. diff --git a/src/PluginManagerInterface.php b/src/PluginManagerInterface.php index 5ef0015e..1daa4665 100644 --- a/src/PluginManagerInterface.php +++ b/src/PluginManagerInterface.php @@ -4,8 +4,8 @@ namespace Laminas\ServiceManager; -use Interop\Container\Exception\ContainerException; use Laminas\ServiceManager\Exception\InvalidServiceException; +use Psr\Container\ContainerExceptionInterface; /** * Interface for a plugin manager @@ -21,7 +21,7 @@ interface PluginManagerInterface extends ServiceLocatorInterface * @return void * @throws InvalidServiceException If created instance does not respect the * constraint on type imposed by the plugin manager. - * @throws ContainerException If any other error occurs. + * @throws ContainerExceptionInterface If any other error occurs. */ public function validate($instance); } diff --git a/src/Proxy/LazyServiceFactory.php b/src/Proxy/LazyServiceFactory.php index e4b47d25..a873e8c7 100644 --- a/src/Proxy/LazyServiceFactory.php +++ b/src/Proxy/LazyServiceFactory.php @@ -4,12 +4,12 @@ namespace Laminas\ServiceManager\Proxy; -use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Exception; use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; use ProxyManager\Factory\LazyLoadingValueHolderFactory; use ProxyManager\Proxy\LazyLoadingInterface; use ProxyManager\Proxy\VirtualProxyInterface; +use Psr\Container\ContainerInterface; use function sprintf; diff --git a/src/PsrContainerDecorator.php b/src/PsrContainerDecorator.php deleted file mode 100644 index 40f40aad..00000000 --- a/src/PsrContainerDecorator.php +++ /dev/null @@ -1,45 +0,0 @@ -container = $container; - } - - /** - * {@inheritdoc} - */ - public function get($id) - { - return $this->container->get($id); - } - - /** - * {@inheritdoc} - */ - public function has($id) - { - return $this->container->has($id); - } - - /** - * @return PsrContainerInterface - */ - public function getContainer() - { - return $this->container; - } -} diff --git a/src/ServiceLocatorInterface.php b/src/ServiceLocatorInterface.php index 93cc81a2..44272f3e 100644 --- a/src/ServiceLocatorInterface.php +++ b/src/ServiceLocatorInterface.php @@ -4,16 +4,13 @@ namespace Laminas\ServiceManager; -use Interop\Container\ContainerInterface as InteropContainerInterface; use Psr\Container\ContainerExceptionInterface; -use Psr\Container\ContainerInterface as PsrContainerInterface; +use Psr\Container\ContainerInterface; /** * Interface for service locator */ -interface ServiceLocatorInterface extends - PsrContainerInterface, - InteropContainerInterface +interface ServiceLocatorInterface extends ContainerInterface { /** * Build a service by its name, using optional options (such services are NEVER cached). diff --git a/src/ServiceManager.php b/src/ServiceManager.php index 9e2626a5..6c228fc3 100644 --- a/src/ServiceManager.php +++ b/src/ServiceManager.php @@ -5,8 +5,6 @@ namespace Laminas\ServiceManager; use Exception; -use Interop\Container\ContainerInterface; -use Interop\Container\Exception\ContainerException; use Laminas\ServiceManager\Exception\ContainerModificationsNotAllowedException; use Laminas\ServiceManager\Exception\CyclicAliasException; use Laminas\ServiceManager\Exception\InvalidArgumentException; @@ -19,6 +17,8 @@ use ProxyManager\FileLocator\FileLocator; use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; use ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; use function array_intersect; use function array_key_exists; @@ -601,7 +601,7 @@ private function createDelegatorFromName(string $name, ?array $options = null) * @return object * @throws ServiceNotFoundException If unable to resolve the service. * @throws ServiceNotCreatedException If an exception is raised when creating a service. - * @throws ContainerException If any other error occurs. + * @throws ContainerExceptionInterface If any other error occurs. */ private function doCreate(string $resolvedName, ?array $options = null) { @@ -613,7 +613,7 @@ private function doCreate(string $resolvedName, ?array $options = null) } else { $object = $this->createDelegatorFromName($resolvedName, $options); } - } catch (ContainerException $exception) { + } catch (ContainerExceptionInterface $exception) { throw $exception; } catch (Exception $exception) { throw new ServiceNotCreatedException(sprintf( diff --git a/src/Tool/ConfigDumper.php b/src/Tool/ConfigDumper.php index 8f359914..c9e6b875 100644 --- a/src/Tool/ConfigDumper.php +++ b/src/Tool/ConfigDumper.php @@ -4,9 +4,9 @@ namespace Laminas\ServiceManager\Tool; -use Interop\Container\ContainerInterface; use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Laminas\ServiceManager\Exception\InvalidArgumentException; +use Psr\Container\ContainerInterface; use ReflectionClass; use ReflectionParameter; use Traversable; diff --git a/src/Tool/FactoryCreator.php b/src/Tool/FactoryCreator.php index 7ef8d3f8..2e8325e1 100644 --- a/src/Tool/FactoryCreator.php +++ b/src/Tool/FactoryCreator.php @@ -4,9 +4,9 @@ namespace Laminas\ServiceManager\Tool; -use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Exception\InvalidArgumentException; use Laminas\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; use ReflectionClass; use ReflectionParameter; diff --git a/src/autoload.php b/src/autoload.php new file mode 100644 index 00000000..8b0a678c --- /dev/null +++ b/src/autoload.php @@ -0,0 +1,15 @@ + */ private ObjectProphecy $container; public function setUp(): void diff --git a/test/AbstractPluginManagerTest.php b/test/AbstractPluginManagerTest.php index fc22bd3f..15801d83 100644 --- a/test/AbstractPluginManagerTest.php +++ b/test/AbstractPluginManagerTest.php @@ -5,8 +5,6 @@ namespace LaminasTest\ServiceManager; -use Interop\Container\ContainerInterface; -use Laminas\ServiceManager\AbstractPluginManager; use Laminas\ServiceManager\ConfigInterface; use Laminas\ServiceManager\Exception\InvalidArgumentException; use Laminas\ServiceManager\Exception\InvalidServiceException; @@ -14,14 +12,13 @@ use Laminas\ServiceManager\Factory\AbstractFactoryInterface; use Laminas\ServiceManager\Factory\FactoryInterface; use Laminas\ServiceManager\Factory\InvokableFactory; -use Laminas\ServiceManager\PsrContainerDecorator; use Laminas\ServiceManager\ServiceManager; use LaminasTest\ServiceManager\TestAsset\InvokableObject; use LaminasTest\ServiceManager\TestAsset\SimplePluginManager; use LaminasTest\ServiceManager\TestAsset\V2v3PluginManager; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; -use Psr\Container\ContainerInterface as PsrContainerInterface; +use Psr\Container\ContainerInterface; use stdClass; use function get_class; @@ -69,32 +66,6 @@ public function testInjectCreationContextInFactories(): void $this->assertInstanceOf(InvokableObject::class, $object); } - public function testTransparentlyDecoratesNonInteropPsrContainerAsInteropContainer(): void - { - $invokableFactory = $this->getMockBuilder(FactoryInterface::class) - ->getMock(); - $invokableFactory->method('__invoke') - ->will($this->returnArgument(0)); - - $config = [ - 'factories' => [ - 'creation context container' => $invokableFactory, - ], - ]; - - $container = $this->getMockBuilder(PsrContainerInterface::class) - ->getMock(); - $pluginManager = $this->getMockForAbstractClass( - AbstractPluginManager::class, - [$container, $config] - ); - - $object = $pluginManager->get('creation context container'); - - $this->assertInstanceOf(PsrContainerDecorator::class, $object); - $this->assertSame($container, $object->getContainer()); - } - public function testValidateInstance(): void { $config = [ diff --git a/test/CommonServiceLocatorBehaviorsTrait.php b/test/CommonServiceLocatorBehaviorsTrait.php index c9fed81c..85dc7624 100644 --- a/test/CommonServiceLocatorBehaviorsTrait.php +++ b/test/CommonServiceLocatorBehaviorsTrait.php @@ -5,8 +5,6 @@ namespace LaminasTest\ServiceManager; use DateTime; -use Interop\Container\ContainerInterface; -use Interop\Container\Exception\ContainerException; use Laminas\ServiceManager\ConfigInterface; use Laminas\ServiceManager\Exception\ContainerModificationsNotAllowedException; use Laminas\ServiceManager\Exception\CyclicAliasException; @@ -27,6 +25,8 @@ use LaminasTest\ServiceManager\TestAsset\SampleFactory; use LaminasTest\ServiceManager\TestAsset\SimpleAbstractFactory; use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; use ReflectionProperty; use stdClass; @@ -630,7 +630,7 @@ public function testPassingInvalidInitializerTypeViaConfigurationRaisesException public function testGetRaisesExceptionWhenNoFactoryIsResolved(): void { $serviceManager = $this->createContainer(); - $this->expectException(ContainerException::class); + $this->expectException(ContainerExceptionInterface::class); $this->expectExceptionMessage('Unable to resolve'); $serviceManager->get('Some\Unknown\Service'); } diff --git a/test/Factory/InvokableFactoryTest.php b/test/Factory/InvokableFactoryTest.php index 8b867937..43c8a4fa 100644 --- a/test/Factory/InvokableFactoryTest.php +++ b/test/Factory/InvokableFactoryTest.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\Factory; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\InvokableFactory; use LaminasTest\ServiceManager\TestAsset\InvokableObject; use PHPUnit\Framework\TestCase; @@ -16,7 +16,7 @@ class InvokableFactoryTest extends TestCase { public function testCanCreateObject(): void { - $container = $this->getMockBuilder(ContainerInterface::class) + $container = $this->getMockBuilder(containerinterface::class) ->getMock(); $factory = new InvokableFactory(); diff --git a/test/Proxy/LazyServiceFactoryTest.php b/test/Proxy/LazyServiceFactoryTest.php index 70e1916d..00c88f6f 100644 --- a/test/Proxy/LazyServiceFactoryTest.php +++ b/test/Proxy/LazyServiceFactoryTest.php @@ -4,15 +4,15 @@ namespace LaminasTest\ServiceManager\Proxy; -use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; use Laminas\ServiceManager\Proxy\LazyServiceFactory; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject as MockObject; use ProxyManager\Factory\LazyLoadingValueHolderFactory; use ProxyManager\Proxy\LazyLoadingInterface; use ProxyManager\Proxy\VirtualProxyInterface; +use Psr\Container\ContainerInterface; /** * @covers \Laminas\ServiceManager\Proxy\LazyServiceFactory @@ -21,7 +21,7 @@ class LazyServiceFactoryTest extends TestCase { private LazyServiceFactory $factory; - /** @var LazyLoadingValueHolderFactory|MockObject */ + /** @var LazyLoadingValueHolderFactory&MockObject */ private $proxyFactory; /** @@ -99,14 +99,10 @@ function ($className, $initializer) use ($expectedService) { } /** - * @return ContainerInterface|MockObject + * @return ContainerInterface&MockObject */ - private function createContainerMock() + private function createContainerMock(): ContainerInterface { - /** @var ContainerInterface|MockObject $container */ - $container = $this->getMockBuilder(ContainerInterface::class) - ->getMock(); - - return $container; + return $this->createMock(ContainerInterface::class); } } diff --git a/test/PsrContainerDecoratorTest.php b/test/PsrContainerDecoratorTest.php deleted file mode 100644 index ae4f4cb5..00000000 --- a/test/PsrContainerDecoratorTest.php +++ /dev/null @@ -1,50 +0,0 @@ -getMockBuilder(ContainerInterface::class) - ->getMock(); - $psrContainer->expects($this->exactly(2)) - ->method('has') - ->with('string key') - ->willReturnOnConsecutiveCalls(true, false); - $decorator = new PsrContainerDecorator($psrContainer); - $this->assertTrue($decorator->has('string key')); - $this->assertFalse($decorator->has('string key')); - } - - public function testProxiesGetToDecoratedContainer(): void - { - $service = new stdClass(); - $psrContainer = $this->getMockBuilder(ContainerInterface::class) - ->getMock(); - $psrContainer->expects($this->once()) - ->method('get') - ->with('string key') - ->willReturn($service); - $decorator = new PsrContainerDecorator($psrContainer); - $this->assertSame($service, $decorator->get('string key')); - } - - public function testGetterReturnsDecoratedContainer(): void - { - $psrContainer = $this->getMockBuilder(ContainerInterface::class) - ->getMock(); - $decorator = new PsrContainerDecorator($psrContainer); - $this->assertSame($psrContainer, $decorator->getContainer()); - } -} diff --git a/test/ServiceManagerContainerInteropIntegrationTest.php b/test/ServiceManagerContainerInteropIntegrationTest.php new file mode 100644 index 00000000..b8d7ce0a --- /dev/null +++ b/test/ServiceManagerContainerInteropIntegrationTest.php @@ -0,0 +1,76 @@ +container = new ServiceManager([]); + } + + /** + * NOTE: using try-catch here is to avoid phpunits exception comparison. + * PHPUnit is not directly catching specific exceptions when using {@see TestCase::expectException()} + * but catches {@see Throwable} and does an "instanceof" comparison. + */ + public function testUpstreamCanCatchNotFoundException(): void + { + try { + $this->container->get('unexisting service'); + $this->fail('No exception was thrown.'); + } catch (NotFoundException $exception) { + self::assertStringContainsString( + 'Unable to resolve service "unexisting service" to a factory', + $exception->getMessage() + ); + } + } + + /** + * NOTE: using try-catch here is to avoid phpunits exception comparison. + * PHPUnit is not directly catching specific exceptions when using {@see TestCase::expectException()} + * but catches {@see Throwable} and does an "instanceof" comparison. + */ + public function testUpstreamCanCatchContainerException(): void + { + try { + $this->container->get('unexisting service'); + $this->fail('No exception was thrown.'); + } catch (ContainerException $exception) { + self::assertStringContainsString( + 'Unable to resolve service "unexisting service" to a factory', + $exception->getMessage() + ); + } + } + + public function testUpstreamCanUseInteropContainerForMethodSignature(): void + { + $factory = new class implements FactoryInterface { + /** @param string $requestedName */ + public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): stdClass + { + return new stdClass(); + } + }; + + $instance = $factory($this->container, stdClass::class); + self::assertInstanceOf(stdClass::class, $instance); + } +} diff --git a/test/ServiceManagerTest.php b/test/ServiceManagerTest.php index 5f668042..9dd0ad14 100644 --- a/test/ServiceManagerTest.php +++ b/test/ServiceManagerTest.php @@ -5,7 +5,6 @@ namespace LaminasTest\ServiceManager; use DateTime; -use Interop\Container\ContainerInterface as InteropContainerInterface; use Laminas\ServiceManager\ConfigInterface; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; use Laminas\ServiceManager\Factory\FactoryInterface; @@ -97,7 +96,7 @@ public function testCanWrapCreationInDelegators(): void 'delegators' => [ stdClass::class => [ TestAsset\PreDelegator::class, - function (InteropContainerInterface $container, string $name, callable $callback): object { + function (ContainerInterface $container, string $name, callable $callback): object { $instance = $callback(); self::assertInstanceOf(stdClass::class, $instance); $instance->foo = 'bar'; @@ -594,7 +593,7 @@ public function aliasedServices(): array /** * @param string $requestedName */ - public function canCreate(InteropContainerInterface $container, $requestedName): bool + public function canCreate(ContainerInterface $container, $requestedName): bool { return $requestedName === stdClass::class; } @@ -603,7 +602,7 @@ public function canCreate(InteropContainerInterface $container, $requestedName): * @param string $requestedName */ public function __invoke( - InteropContainerInterface $container, + ContainerInterface $container, $requestedName, ?array $options = null ): object { diff --git a/test/TestAsset/AbstractFactoryFoo.php b/test/TestAsset/AbstractFactoryFoo.php index 965b9e94..f3b69b3d 100644 --- a/test/TestAsset/AbstractFactoryFoo.php +++ b/test/TestAsset/AbstractFactoryFoo.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; class AbstractFactoryFoo implements AbstractFactoryInterface @@ -14,7 +14,7 @@ class AbstractFactoryFoo implements AbstractFactoryInterface * @param array|null $options * @return Foo|false */ - public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null) + public function __invoke(containerinterface $container, $requestedName, ?array $options = null) { if ($requestedName === 'foo') { return new Foo($options); @@ -25,7 +25,7 @@ public function __invoke(ContainerInterface $container, $requestedName, ?array $ /** * @param string $requestedName */ - public function canCreate(ContainerInterface $container, $requestedName): bool + public function canCreate(containerinterface $container, $requestedName): bool { return $requestedName === 'foo'; } diff --git a/test/TestAsset/CallTimesAbstractFactory.php b/test/TestAsset/CallTimesAbstractFactory.php index df4e3396..c001cd2e 100644 --- a/test/TestAsset/CallTimesAbstractFactory.php +++ b/test/TestAsset/CallTimesAbstractFactory.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; class CallTimesAbstractFactory implements AbstractFactoryInterface @@ -15,7 +15,7 @@ class CallTimesAbstractFactory implements AbstractFactoryInterface /** * {@inheritDoc} */ - public function canCreate(ContainerInterface $container, $name) + public function canCreate(containerinterface $container, $name) { self::$callTimes++; @@ -25,7 +25,7 @@ public function canCreate(ContainerInterface $container, $name) /** * {@inheritDoc} */ - public function __invoke(ContainerInterface $container, $className, ?array $options = null) + public function __invoke(containerinterface $container, $className, ?array $options = null) { } diff --git a/test/TestAsset/FailingAbstractFactory.php b/test/TestAsset/FailingAbstractFactory.php index 5cc264ef..8db4f3df 100644 --- a/test/TestAsset/FailingAbstractFactory.php +++ b/test/TestAsset/FailingAbstractFactory.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; class FailingAbstractFactory implements AbstractFactoryInterface @@ -12,7 +12,7 @@ class FailingAbstractFactory implements AbstractFactoryInterface /** * {@inheritDoc} */ - public function canCreate(ContainerInterface $container, $name) + public function canCreate(containerinterface $container, $name) { return false; } @@ -20,7 +20,7 @@ public function canCreate(ContainerInterface $container, $name) /** * {@inheritDoc} */ - public function __invoke(ContainerInterface $container, $className, ?array $options = null) + public function __invoke(containerinterface $container, $className, ?array $options = null) { } } diff --git a/test/TestAsset/FailingExceptionWithStringAsCodeFactory.php b/test/TestAsset/FailingExceptionWithStringAsCodeFactory.php index 72d5f4b0..5cfb5e4c 100644 --- a/test/TestAsset/FailingExceptionWithStringAsCodeFactory.php +++ b/test/TestAsset/FailingExceptionWithStringAsCodeFactory.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\FactoryInterface; class FailingExceptionWithStringAsCodeFactory implements FactoryInterface @@ -12,7 +12,7 @@ class FailingExceptionWithStringAsCodeFactory implements FactoryInterface /** * {@inheritDoc} */ - public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null) + public function __invoke(containerinterface $container, $requestedName, ?array $options = null) { throw new ExceptionWithStringAsCodeException('There is an error'); } diff --git a/test/TestAsset/FailingFactory.php b/test/TestAsset/FailingFactory.php index da431b84..cb860739 100644 --- a/test/TestAsset/FailingFactory.php +++ b/test/TestAsset/FailingFactory.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\FactoryInterface; use RuntimeException; @@ -13,7 +13,7 @@ class FailingFactory implements FactoryInterface /** * {@inheritDoc} */ - public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null) + public function __invoke(containerinterface $container, $requestedName, ?array $options = null) { throw new RuntimeException('There is an error'); } diff --git a/test/TestAsset/PassthroughDelegatorFactory.php b/test/TestAsset/PassthroughDelegatorFactory.php index 002e5b75..7256de4c 100644 --- a/test/TestAsset/PassthroughDelegatorFactory.php +++ b/test/TestAsset/PassthroughDelegatorFactory.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; class PassthroughDelegatorFactory implements DelegatorFactoryInterface @@ -14,7 +14,7 @@ class PassthroughDelegatorFactory implements DelegatorFactoryInterface * * @see \Laminas\ServiceManager\Factory\DelegatorFactoryInterface::__invoke() */ - public function __invoke(ContainerInterface $container, $name, callable $callback, ?array $options = null) + public function __invoke(containerinterface $container, $name, callable $callback, ?array $options = null) { return $callback(); } diff --git a/test/TestAsset/PreDelegator.php b/test/TestAsset/PreDelegator.php index 1b67800c..73a62156 100644 --- a/test/TestAsset/PreDelegator.php +++ b/test/TestAsset/PreDelegator.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; class PreDelegator implements DelegatorFactoryInterface @@ -12,7 +12,7 @@ class PreDelegator implements DelegatorFactoryInterface /** * {@inheritDoc} */ - public function __invoke(ContainerInterface $container, $name, callable $callback, ?array $options = null) + public function __invoke(containerinterface $container, $name, callable $callback, ?array $options = null) { if (! $container->has('config')) { return $callback(); diff --git a/test/TestAsset/SampleFactory.php b/test/TestAsset/SampleFactory.php index ca42c712..33b2d768 100644 --- a/test/TestAsset/SampleFactory.php +++ b/test/TestAsset/SampleFactory.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\FactoryInterface; class SampleFactory implements FactoryInterface @@ -13,7 +13,7 @@ class SampleFactory implements FactoryInterface * @param string $requestedName * @param array|null $options */ - public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): InvokableObject + public function __invoke(containerinterface $container, $requestedName, ?array $options = null): InvokableObject { return new InvokableObject(); } diff --git a/test/TestAsset/SimpleAbstractFactory.php b/test/TestAsset/SimpleAbstractFactory.php index 54363bdd..35e776b1 100644 --- a/test/TestAsset/SimpleAbstractFactory.php +++ b/test/TestAsset/SimpleAbstractFactory.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; class SimpleAbstractFactory implements AbstractFactoryInterface @@ -12,7 +12,7 @@ class SimpleAbstractFactory implements AbstractFactoryInterface /** * {@inheritDoc} */ - public function canCreate(ContainerInterface $container, $name) + public function canCreate(containerinterface $container, $name) { return true; } @@ -20,7 +20,7 @@ public function canCreate(ContainerInterface $container, $name) /** * {@inheritDoc} */ - public function __invoke(ContainerInterface $container, $className, ?array $options = null) + public function __invoke(containerinterface $container, $className, ?array $options = null) { if (empty($options)) { return new $className(); diff --git a/test/TestAsset/SimpleInitializer.php b/test/TestAsset/SimpleInitializer.php index ee4a72ce..e2d75872 100644 --- a/test/TestAsset/SimpleInitializer.php +++ b/test/TestAsset/SimpleInitializer.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\Initializer\InitializerInterface; use stdClass; @@ -13,7 +13,7 @@ class SimpleInitializer implements InitializerInterface /** * {@inheritDoc} */ - public function __invoke(ContainerInterface $container, $instance) + public function __invoke(containerinterface $container, $instance) { if (! $instance instanceof stdClass) { return; diff --git a/test/TestAsset/factories/ComplexDependencyObject.php b/test/TestAsset/factories/ComplexDependencyObject.php index 74fa012b..f80a8e31 100644 --- a/test/TestAsset/factories/ComplexDependencyObject.php +++ b/test/TestAsset/factories/ComplexDependencyObject.php @@ -4,9 +4,9 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; use LaminasTest\ServiceManager\TestAsset\ComplexDependencyObject; use Laminas\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; class ComplexDependencyObjectFactory implements FactoryInterface { diff --git a/test/TestAsset/factories/InvokableObject.php b/test/TestAsset/factories/InvokableObject.php index 21e06f03..c5a96f64 100644 --- a/test/TestAsset/factories/InvokableObject.php +++ b/test/TestAsset/factories/InvokableObject.php @@ -4,9 +4,9 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; use LaminasTest\ServiceManager\TestAsset\InvokableObject; use Laminas\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; class InvokableObjectFactory implements FactoryInterface { diff --git a/test/TestAsset/factories/SimpleDependencyObject.php b/test/TestAsset/factories/SimpleDependencyObject.php index 410719ad..26ed1fca 100644 --- a/test/TestAsset/factories/SimpleDependencyObject.php +++ b/test/TestAsset/factories/SimpleDependencyObject.php @@ -4,9 +4,9 @@ namespace LaminasTest\ServiceManager\TestAsset; -use Interop\Container\ContainerInterface; use LaminasTest\ServiceManager\TestAsset\SimpleDependencyObject; use Laminas\ServiceManager\Factory\FactoryInterface; +use Psr\Container\ContainerInterface; class SimpleDependencyObjectFactory implements FactoryInterface { diff --git a/test/Tool/ConfigDumperTest.php b/test/Tool/ConfigDumperTest.php index 504cd1f8..b90178ce 100644 --- a/test/Tool/ConfigDumperTest.php +++ b/test/Tool/ConfigDumperTest.php @@ -4,7 +4,7 @@ namespace LaminasTest\ServiceManager\Tool; -use Interop\Container\ContainerInterface; +use interop\container\containerinterface; use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; use Laminas\ServiceManager\Exception\InvalidArgumentException; use Laminas\ServiceManager\Factory\FactoryInterface; @@ -115,7 +115,7 @@ public function testCreateDependencyConfigWithContainerAndNoServiceWithoutTypeHi 'Cannot create config for constructor argument "aName", ' . 'it has no type hint, or non-class/interface type hint' ); - $container = $this->prophesize(ContainerInterface::class); + $container = $this->prophesize(containerinterface::class); $container->has(ObjectWithScalarDependency::class) ->shouldBeCalled() ->willReturn(false); @@ -130,7 +130,7 @@ public function testCreateDependencyConfigWithContainerAndNoServiceWithoutTypeHi public function testCreateDependencyConfigWithContainerWithoutTypeHintedParameter(): void { - $container = $this->prophesize(ContainerInterface::class); + $container = $this->prophesize(containerinterface::class); $container->has(ObjectWithScalarDependency::class) ->shouldBeCalled() ->willReturn(true);