From b8b152587a12eb2f38f53f17d24181008333d8f7 Mon Sep 17 00:00:00 2001 From: webimpress Date: Mon, 16 Apr 2018 09:44:00 +0100 Subject: [PATCH] Updated to use zend-container-config-test library All these tests implemented here previously for shared services are moved into separate library so it should be used instead. --- composer.json | 3 +- composer.lock | 57 ++++++++++++++++++++++++++- test/ContainerTest.php | 89 +++--------------------------------------- 3 files changed, 64 insertions(+), 85 deletions(-) diff --git a/composer.json b/composer.json index 1bfe3960..ee66c947 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "ocramius/proxy-manager": "^2.1.1", "phpbench/phpbench": "^0.13.0", "phpunit/phpunit": "^6.4.4", - "zendframework/zend-coding-standard": "~1.0.0" + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-container-config-test": "^0.2.1" }, "provide": { "psr/container-implementation": "^1.0" diff --git a/composer.lock b/composer.lock index 08b6fdc0..986b5688 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "bba5f6d05be1ae91bc424cd3510f5bbc", + "content-hash": "f280e96d0b05401d973f1fdd15dc0c90", "packages": [ { "name": "psr/container", @@ -2863,6 +2863,61 @@ ], "time": "2016-11-09T21:30:43+00:00" }, + { + "name": "zendframework/zend-container-config-test", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-container-config-test.git", + "reference": "ebc45b7b6b2a8e382fe8a4a4d6c74a196fe53554" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-container-config-test/zipball/ebc45b7b6b2a8e382fe8a4a4d6c74a196fe53554", + "reference": "ebc45b7b6b2a8e382fe8a4a4d6c74a196fe53554", + "shasum": "" + }, + "require": { + "php": "^7.1", + "psr/container": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.0.2", + "zendframework/zend-auradi-config": "^1.0.1", + "zendframework/zend-coding-standard": "~1.0.0", + "zendframework/zend-pimple-config": "^1.1", + "zendframework/zend-servicemanager": "^3.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "files": [ + "src/TestAsset/function-factory.php", + "src/TestAsset/function-factory-with-name.php" + ], + "psr-4": { + "Zend\\ContainerConfigTest\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Expressive PSR-11 container configuration tests", + "keywords": [ + "PSR-11", + "ZendFramework", + "container", + "expressive", + "test", + "zf" + ], + "time": "2018-04-12T18:58:34+00:00" + }, { "name": "zendframework/zend-eventmanager", "version": "3.2.0", diff --git a/test/ContainerTest.php b/test/ContainerTest.php index 4435498f..7091c518 100644 --- a/test/ContainerTest.php +++ b/test/ContainerTest.php @@ -7,93 +7,16 @@ namespace ZendTest\ServiceManager; -use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerInterface; +use Zend\ContainerConfigTest\AbstractExpressiveContainerConfigTest; +use Zend\ContainerConfigTest\SharedTestTrait; use Zend\ServiceManager\ServiceManager; -class ContainerTest extends TestCase +class ContainerTest extends AbstractExpressiveContainerConfigTest { - public function config() - { - yield 'factories' => [['factories' => ['service' => TestAsset\SampleFactory::class]]]; - yield 'invokables' => [['invokables' => ['service' => TestAsset\InvokableObject::class]]]; - yield 'aliases-invokables' => [ - [ - 'aliases' => ['service' => TestAsset\InvokableObject::class], - 'invokables' => [TestAsset\InvokableObject::class => TestAsset\InvokableObject::class], - ], - ]; - yield 'aliases-factories' => [ - [ - 'aliases' => ['service' => TestAsset\InvokableObject::class], - 'factories' => [TestAsset\InvokableObject::class => TestAsset\SampleFactory::class], - ], - ]; - } - - /** - * @dataProvider config - */ - public function testIsSharedByDefault(array $config) - { - $container = $this->createContainer($config); - - $service1 = $container->get('service'); - $service2 = $container->get('service'); - - $this->assertSame($service1, $service2); - } - - /** - * @dataProvider config - */ - public function testCanDisableSharedByDefault(array $config) - { - $container = $this->createContainer(array_merge($config, [ - 'shared_by_default' => false, - ])); - - $service1 = $container->get('service'); - $service2 = $container->get('service'); - - $this->assertNotSame($service1, $service2); - } - - /** - * @dataProvider config - */ - public function testCanDisableSharedForSingleService(array $config) - { - $container = $this->createContainer(array_merge($config, [ - 'shared' => [ - 'service' => false, - ], - ])); - - $service1 = $container->get('service'); - $service2 = $container->get('service'); - - $this->assertNotSame($service1, $service2); - } - - /** - * @dataProvider config - */ - public function testCanEnableSharedForSingleService(array $config) - { - $container = $this->createContainer(array_merge($config, [ - 'shared_by_default' => false, - 'shared' => [ - 'service' => true, - ], - ])); - - $service1 = $container->get('service'); - $service2 = $container->get('service'); - - $this->assertSame($service1, $service2); - } + use SharedTestTrait; - private function createContainer(array $config) + protected function createContainer(array $config) : ContainerInterface { return new ServiceManager($config); }