|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use Nette\DI; |
| 6 | +use Nette\DI\Statement; |
| 7 | +use Tester\Assert; |
| 8 | + |
| 9 | + |
| 10 | +require __DIR__ . '/../bootstrap.php'; |
| 11 | + |
| 12 | + |
| 13 | +class Service |
| 14 | +{ |
| 15 | + public $arg; |
| 16 | + |
| 17 | + function __construct($arg) |
| 18 | + { |
| 19 | + $this->arg = $arg; |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +test(function () { |
| 24 | + $compiler = new DI\Compiler; |
| 25 | + $compiler->selectDynamicParameters(['dynamic']); |
| 26 | + $container = createContainer($compiler, ' |
| 27 | + services: |
| 28 | + one: Service(%dynamic%) |
| 29 | + ', ['dynamic' => 123]); |
| 30 | + Assert::same(123, $container->getService('one')->arg); |
| 31 | +}); |
| 32 | + |
| 33 | + |
| 34 | +test(function () { |
| 35 | + $compiler = new DI\Compiler; |
| 36 | + $compiler->selectDynamicParameters(['dynamic']); |
| 37 | + $container = createContainer($compiler, ' |
| 38 | + parameters: |
| 39 | + dynamic: default |
| 40 | +
|
| 41 | + services: |
| 42 | + one: Service(%dynamic%) |
| 43 | + '); |
| 44 | + Assert::same('default', $container->getService('one')->arg); |
| 45 | +}); |
| 46 | + |
| 47 | + |
| 48 | +test(function () { |
| 49 | + $compiler = new DI\Compiler; |
| 50 | + $compiler->selectDynamicParameters(['dynamic']); |
| 51 | + $container = createContainer($compiler, ' |
| 52 | + parameters: |
| 53 | + dynamic: default |
| 54 | +
|
| 55 | + services: |
| 56 | + one: Service(%dynamic%) |
| 57 | + ', ['dynamic' => 'overwritten']); |
| 58 | + Assert::same('overwritten', $container->getService('one')->arg); |
| 59 | +}); |
| 60 | + |
| 61 | + |
| 62 | +test(function () { |
| 63 | + $compiler = new DI\Compiler; |
| 64 | + $compiler->selectDynamicParameters(['dynamic']); |
| 65 | + $container = createContainer($compiler, ' |
| 66 | + parameters: |
| 67 | + expand: hello%dynamic% |
| 68 | + ', ['dynamic' => 123]); |
| 69 | + Assert::same(['dynamic' => 123, 'expand' => 'hello123'], $container->parameters); |
| 70 | +}); |
0 commit comments