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

Commit 5070778

Browse files
author
fhein
committed
Adds delegator scenario.
1 parent 3a6d8cf commit 5070778

File tree

2 files changed

+55
-20
lines changed

2 files changed

+55
-20
lines changed

test/CommonServiceLocatorBehaviorsTrait.php

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use function set_error_handler;
3232
use ZendTest\ServiceManager\TestAsset\SampleFactory;
3333
use ZendTest\ServiceManager\TestAsset\AbstractFactoryFoo;
34+
use ZendTest\ServiceManager\TestAsset\PassthroughDelegatorFactory;
3435

3536
trait CommonServiceLocatorBehaviorsTrait
3637
{
@@ -910,7 +911,9 @@ public function testConsistencyOverInternalStates($smTemplate, $name, $test)
910911
// objects in $object['get'] or $object['build']
911912
// respectively
912913
foreach ($test as $method) {
913-
$object[$method][] = $sm->$method($name);
914+
$obj = $sm->$method($name);
915+
$object[$method][] = $obj;
916+
$this->assertNotNull($obj);
914917
$this->assertTrue($sm->has($name));
915918
}
916919

@@ -943,27 +946,35 @@ public function provideConsistencyOverInternalStatesTests()
943946
{
944947
$config = [
945948
'factories' => [
946-
'factory' => SampleFactory::class,
949+
// to allow build('service')
947950
'service' => function ($container, $requestedName, array $options = null) {
948951
return new stdClass();
949952
},
953+
'factory' => SampleFactory::class,
954+
'delegator' => SampleFactory::class,
955+
],
956+
'delegators' => [
957+
'delegator' => [
958+
PassthroughDelegatorFactory::class
950959
],
951-
'invokables' => [
952-
'invokable' => InvokableObject::class,
953-
],
954-
'services' => [
955-
'service' => new stdClass(),
956-
],
957-
'aliases' => [
958-
'serviceAlias' => 'service',
959-
'invokableAlias' => 'invokable',
960-
'factoryAlias' => 'factory',
961-
'abstractFactoryAlias' => 'foo'
962-
],
963-
'abstract_factories' => [
964-
AbstractFactoryFoo::class
965-
]
966-
];
960+
],
961+
'invokables' => [
962+
'invokable' => InvokableObject::class,
963+
],
964+
'services' => [
965+
'service' => new stdClass(),
966+
],
967+
'aliases' => [
968+
'serviceAlias' => 'service',
969+
'invokableAlias' => 'invokable',
970+
'factoryAlias' => 'factory',
971+
'abstractFactoryAlias' => 'foo',
972+
'delegatorAlias' => 'delegator',
973+
],
974+
'abstract_factories' => [
975+
AbstractFactoryFoo::class
976+
]
977+
];
967978

968979
$smTemplate = $this->createContainer($config);
969980

@@ -983,8 +994,9 @@ public function provideConsistencyOverInternalStatesTests()
983994
$config['factories'],
984995
$config['invokables'],
985996
$config['services'],
986-
$config['aliases']
987-
));
997+
$config['aliases'],
998+
$config['delegators']
999+
));
9881000
$names[] = 'foo';
9891001

9901002
foreach ($names as $name) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* @link https://github.com/zendframework/zend-servicemanager for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace ZendTest\ServiceManager\TestAsset;
9+
10+
use Interop\Container\ContainerInterface;
11+
use Zend\ServiceManager\Factory\DelegatorFactoryInterface;
12+
13+
class PassthroughDelegatorFactory implements DelegatorFactoryInterface
14+
{
15+
/**
16+
* {@inheritDoc}
17+
* @see \Zend\ServiceManager\Factory\DelegatorFactoryInterface::__invoke()
18+
*/
19+
public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
20+
{
21+
return call_user_func($callback);
22+
}
23+
}

0 commit comments

Comments
 (0)