Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve containers types to use iterable objects #299

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
xepozz committed Apr 19, 2022
commit 096dc0f35ca976b3de066521aef0677410fe60f7
28 changes: 26 additions & 2 deletions tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,30 @@ public function testTagsWithExternalDefinition(): void
$this->assertSame(EngineMarkTwo::class, get_class($engines[0]));
}

public function testTagsIterable(): void
{
$config = ContainerConfig::create()
->withDefinitions([
EngineMarkOne::class => [
'class' => EngineMarkOne::class,
'tags' => ['engine'],
],
EngineMarkTwo::class => [
'class' => EngineMarkTwo::class,
],
])
->withTags(['engine' => new ArrayIterator([EngineMarkTwo::class])])
->withValidate(true);
$container = new Container($config);

$engines = $container->get('tag@engine');

$this->assertIsArray($engines);
$this->assertCount(2, $engines);
$this->assertSame(EngineMarkOne::class, get_class($engines[1]));
$this->assertSame(EngineMarkTwo::class, get_class($engines[0]));
}

public function testTagsWithExternalDefinitionMerge(): void
{
$config = ContainerConfig::create()
Expand Down Expand Up @@ -1771,7 +1795,7 @@ public function testNonArrayTags(): void

$this->expectException(InvalidConfigException::class);
$this->expectExceptionMessage(
'Invalid definition: tags should be array of strings, integer given.'
'Invalid definition: tags should be iterable object or array of strings, integer given.'
);
new Container($config);
}
Expand All @@ -1784,7 +1808,7 @@ public function dataInvalidTags(): array
[42 => [EngineMarkTwo::class]],
],
[
'Invalid tags configuration: tag should contain array of service IDs, integer given.',
'Invalid tags configuration: tag should be iterable object or array of service IDs, integer given.',
['engine' => 42],
],
[
Expand Down