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

Commit 7793351

Browse files
author
fhein
committed
Added support for iteration over several sm configs. Added support for
scenarios with sharedByDefault === false. Test unreveals possible bug in delegator handling.
1 parent 5070778 commit 7793351

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

test/CommonServiceLocatorBehaviorsTrait.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -900,19 +900,18 @@ public function testCoverageDepthFirstTaggingOnRecursiveAliasDefinitions()
900900
* @param string $name
901901
* @param array[] string $test
902902
*/
903-
public function testConsistencyOverInternalStates($smTemplate, $name, $test)
903+
public function testConsistencyOverInternalStates($smTemplate, $name, $test, $sharedByDefault)
904904
{
905905
$sm = clone $smTemplate;
906906
$object['get'] = [];
907907
$object['build'] = [];
908908

909-
910909
// call get()/build() and store the retrieved
911910
// objects in $object['get'] or $object['build']
912911
// respectively
913912
foreach ($test as $method) {
914913
$obj = $sm->$method($name);
915-
$object[$method][] = $obj;
914+
$object[$sharedByDefault ? $method : 'build'][] = $obj;
916915
$this->assertNotNull($obj);
917916
$this->assertTrue($sm->has($name));
918917
}
@@ -944,7 +943,7 @@ public function testConsistencyOverInternalStates($smTemplate, $name, $test)
944943
*/
945944
public function provideConsistencyOverInternalStatesTests()
946945
{
947-
$config = [
946+
$config1 = [
948947
'factories' => [
949948
// to allow build('service')
950949
'service' => function ($container, $requestedName, array $options = null) {
@@ -953,30 +952,36 @@ public function provideConsistencyOverInternalStatesTests()
953952
'factory' => SampleFactory::class,
954953
'delegator' => SampleFactory::class,
955954
],
956-
'delegators' => [
957-
'delegator' => [
958-
PassthroughDelegatorFactory::class
959-
],
960-
],
955+
'delegators' => [
956+
'delegator' => [
957+
PassthroughDelegatorFactory::class
958+
],
959+
],
961960
'invokables' => [
962961
'invokable' => InvokableObject::class,
963962
],
964963
'services' => [
965964
'service' => new stdClass(),
966965
],
967-
'aliases' => [
966+
'aliases' => [
968967
'serviceAlias' => 'service',
969968
'invokableAlias' => 'invokable',
970969
'factoryAlias' => 'factory',
971970
'abstractFactoryAlias' => 'foo',
972971
'delegatorAlias' => 'delegator',
973-
],
972+
],
974973
'abstract_factories' => [
975974
AbstractFactoryFoo::class
976975
]
977976
];
977+
$config2 = $config1;
978+
$config2['shared_by_default'] = false;
978979

979-
$smTemplate = $this->createContainer($config);
980+
$configs = [ $config1, $config2 ];
981+
982+
foreach ($configs as $config) {
983+
$smTemplates[] = $this->createContainer($config);
984+
}
980985

981986
// produce all 3-tuples of 'build' and 'get'
982987
$methods = ['get', 'build'];
@@ -996,13 +1001,16 @@ public function provideConsistencyOverInternalStatesTests()
9961001
$config['services'],
9971002
$config['aliases'],
9981003
$config['delegators']
999-
));
1004+
));
10001005
$names[] = 'foo';
10011006

1002-
foreach ($names as $name) {
1003-
foreach ($callSequences as $callSequence) {
1004-
$sm = clone $smTemplate;
1005-
$tests[] = [$smTemplate, $name, $callSequence];
1007+
foreach ($configs as $config) {
1008+
$smTemplate = $this->createContainer($config);
1009+
foreach ($names as $name) {
1010+
foreach ($callSequences as $callSequence) {
1011+
$sm = clone $smTemplate;
1012+
$tests[] = [$smTemplate, $name, $callSequence, $config['shared_by_default'] ?? true];
1013+
}
10061014
}
10071015
}
10081016
return $tests;

0 commit comments

Comments
 (0)