|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: DIExtension parameters exporting |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +use Nette\DI; |
| 10 | +use Nette\DI\Extensions\DIExtension; |
| 11 | +use Tester\Assert; |
| 12 | + |
| 13 | + |
| 14 | +require __DIR__ . '/../bootstrap.php'; |
| 15 | + |
| 16 | + |
| 17 | +test(function () { |
| 18 | + $compiler = new DI\Compiler; |
| 19 | + $compiler->addExtension('di', new DIExtension); |
| 20 | + $container = createContainer($compiler, ' |
| 21 | + parameters: |
| 22 | + key: val |
| 23 | +
|
| 24 | + di: |
| 25 | + export: |
| 26 | + parameters: true |
| 27 | + '); |
| 28 | + |
| 29 | + Assert::same(['key' => 'val'], $container->parameters); |
| 30 | +}); |
| 31 | + |
| 32 | + |
| 33 | +test(function () { |
| 34 | + $compiler = new DI\Compiler; |
| 35 | + $compiler->addExtension('di', new DIExtension); |
| 36 | + $container = createContainer($compiler, ' |
| 37 | + parameters: |
| 38 | + key: val |
| 39 | +
|
| 40 | + di: |
| 41 | + export: |
| 42 | + parameters: false |
| 43 | + '); |
| 44 | + |
| 45 | + Assert::same([], $container->parameters); |
| 46 | +}); |
| 47 | + |
| 48 | + |
| 49 | +test(function () { |
| 50 | + $compiler = new DI\Compiler; |
| 51 | + $compiler->setDynamicParameterNames(['dynamic']); |
| 52 | + $compiler->addExtension('di', new DIExtension); |
| 53 | + $container = createContainer($compiler, ' |
| 54 | + parameters: |
| 55 | + key: %dynamic% |
| 56 | +
|
| 57 | + di: |
| 58 | + export: |
| 59 | + parameters: true |
| 60 | + ', ['dynamic' => 123]); |
| 61 | + |
| 62 | + Assert::same(['dynamic' => 123, 'key' => 123], $container->parameters); |
| 63 | +}); |
| 64 | + |
| 65 | + |
| 66 | +test(function () { |
| 67 | + $compiler = new DI\Compiler; |
| 68 | + $compiler->setDynamicParameterNames(['dynamic']); |
| 69 | + $compiler->addExtension('di', new DIExtension); |
| 70 | + $container = createContainer($compiler, ' |
| 71 | + parameters: |
| 72 | + key: %dynamic% |
| 73 | +
|
| 74 | + di: |
| 75 | + export: |
| 76 | + parameters: false |
| 77 | + ', ['dynamic' => 123]); |
| 78 | + |
| 79 | + Assert::same(['dynamic' => 123], $container->parameters); |
| 80 | +}); |
0 commit comments