Skip to content
Permalink
Browse files

Autowiring: bug fix & tests

  • Loading branch information...
dg committed May 29, 2019
1 parent ade9bb5 commit 4927bc085e7a883e365e0cc472c1a56d693ce610
Showing with 27 additions and 1 deletion.
  1. +1 −1 src/DI/Autowiring.php
  2. +26 −0 tests/DI/ContainerBuilder.autowiring.types.phpt
@@ -133,7 +133,7 @@ public function rebuild(): void
foreach ($autowired as $autowiredType) {
if (is_a($parent, $autowiredType, true)) {
if (empty($preferred[$parent]) && isset($this->highPriority[$parent])) {
$this->lowPriority[$parent] = array_merge($this->lowPriority[$parent], $this->highPriority[$parent]);
$this->lowPriority[$parent] = array_merge($this->lowPriority[$parent] ?? [], $this->highPriority[$parent]);
$this->highPriority[$parent] = [];
}
$preferred[$parent] = $priority = true;
@@ -43,6 +43,19 @@ test(function () {
});
test(function () {
$builder = new DI\ContainerBuilder;
$builder->addDefinition('bar')
->setType('Bar')
->setAutowired('self');
Assert::same('bar', $builder->getByType('Bar'));
Assert::same(null, $builder->getByType('IBar'));
Assert::same(null, $builder->getByType('Foo'));
Assert::same(null, $builder->getByType('IFoo'));
});
test(function () {
$builder = new DI\ContainerBuilder;
$builder->addDefinition('bar')
@@ -151,6 +164,19 @@ test(function () {
});
test(function () {
$builder = new DI\ContainerBuilder;
$builder->addDefinition('one')
->setType('stdClass');
$builder->addDefinition('two')
->setType('stdClass')
->setAutowired('stdClass');
Assert::same('two', $builder->getByType('stdClass'));
});
test(function () {
$builder = new DI\ContainerBuilder;
$builder->addDefinition('bar')

0 comments on commit 4927bc0

Please sign in to comment.
You can’t perform that action at this time.