This repository has been archived by the owner on Feb 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more test for shared services (aliases, factories, invokables)
- Loading branch information
1 parent
f9b2a18
commit e80999b
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/** | ||
* @see https://github.com/zendframework/zend-servicemanager for the canonical source repository | ||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
* @license https://github.com/zendframework/zend-servicemanager/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace ZendTest\ServiceManager; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Zend\ServiceManager\ServiceManager; | ||
|
||
class ContainerTest extends TestCase | ||
{ | ||
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); | ||
} | ||
|
||
private function createContainer(array $config) | ||
{ | ||
return new ServiceManager($config); | ||
} | ||
} |