Skip to content

Commit

Permalink
Support parameters name binding
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Feb 13, 2024
1 parent d6ab9e7 commit 309100b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/Support/ArgumentNameBinding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Di\Tests\Support;

final class ArgumentNameBinding
{
public function __construct(
public EngineInterface $markOne,
public EngineInterface $markTwo,
) {
}
}
17 changes: 16 additions & 1 deletion tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Yiisoft\Di\StateResetter;
use Yiisoft\Di\ServiceProviderInterface;
use Yiisoft\Di\Tests\Support\A;
use Yiisoft\Di\Tests\Support\ArgumentNameBinding;
use Yiisoft\Di\Tests\Support\B;
use Yiisoft\Di\Tests\Support\Car;
use Yiisoft\Di\Tests\Support\CarFactory;
Expand Down Expand Up @@ -145,7 +146,7 @@ public function dataHas(): array
/**
* @dataProvider dataHas
*/
public function testHas(bool $expected, $id): void
public function testHas(bool $expected, string $id): void
{
$config = ContainerConfig::create()
->withDefinitions([
Expand Down Expand Up @@ -1972,4 +1973,18 @@ public function testInvalidTags(string $message, array $tags): void
$this->expectExceptionMessageMatches($message);
new Container($config);
}

public function testArgumentNameBinding()
{
$config = ContainerConfig::create()
->withDefinitions([
EngineInterface::class . '$markOne' => EngineMarkOne::class,
EngineInterface::class . '$markTwo' => EngineMarkTwo::class,
]);
$container = new Container($config);

$class = $container->get(ArgumentNameBinding::class);
$this->assertInstanceOf(EngineMarkOne::class, $class->markOne);
$this->assertInstanceOf(EngineMarkTwo::class, $class->markTwo);
}
}

0 comments on commit 309100b

Please sign in to comment.