Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Commit

Permalink
Updated to use zend-container-config-test library
Browse files Browse the repository at this point in the history
All these tests implemented  here previously for shared services are moved
into separate library so it should be used instead.
  • Loading branch information
michalbundyra committed Apr 16, 2018
1 parent e80999b commit b8b1525
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 85 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
57 changes: 56 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 6 additions & 83 deletions test/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b8b1525

Please sign in to comment.