|
26 | 26 | use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\BarOptionalArgumentNotNull;
|
27 | 27 | use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo;
|
28 | 28 | use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\FooObject;
|
| 29 | +use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\UnionConstructor; |
29 | 30 | use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo;
|
30 | 31 | use Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Wobble;
|
31 | 32 | use Symfony\Component\ExpressionLanguage\Expression;
|
@@ -803,4 +804,72 @@ public function testProcessResolveParameters()
|
803 | 804 |
|
804 | 805 | putenv('ARRAY=');
|
805 | 806 | }
|
| 807 | + |
| 808 | + /** |
| 809 | + * @requires PHP 8 |
| 810 | + */ |
| 811 | + public function testUnionTypePassesWithReference() |
| 812 | + { |
| 813 | + $container = new ContainerBuilder(); |
| 814 | + |
| 815 | + $container->register('foo', Foo::class); |
| 816 | + $container->register('union', UnionConstructor::class) |
| 817 | + ->setArguments([new Reference('foo')]); |
| 818 | + |
| 819 | + (new CheckTypeDeclarationsPass(true))->process($container); |
| 820 | + |
| 821 | + $this->addToAssertionCount(1); |
| 822 | + } |
| 823 | + |
| 824 | + /** |
| 825 | + * @requires PHP 8 |
| 826 | + */ |
| 827 | + public function testUnionTypePassesWithBuiltin() |
| 828 | + { |
| 829 | + $container = new ContainerBuilder(); |
| 830 | + |
| 831 | + $container->register('union', UnionConstructor::class) |
| 832 | + ->setArguments([42]); |
| 833 | + |
| 834 | + (new CheckTypeDeclarationsPass(true))->process($container); |
| 835 | + |
| 836 | + $this->addToAssertionCount(1); |
| 837 | + } |
| 838 | + |
| 839 | + /** |
| 840 | + * @requires PHP 8 |
| 841 | + */ |
| 842 | + public function testUnionTypeFailsWithReference() |
| 843 | + { |
| 844 | + $container = new ContainerBuilder(); |
| 845 | + |
| 846 | + $container->register('waldo', Waldo::class); |
| 847 | + $container->register('union', UnionConstructor::class) |
| 848 | + ->setArguments([new Reference('waldo')]); |
| 849 | + |
| 850 | + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); |
| 851 | + $this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Waldo" passed.'); |
| 852 | + |
| 853 | + (new CheckTypeDeclarationsPass(true))->process($container); |
| 854 | + |
| 855 | + $this->addToAssertionCount(1); |
| 856 | + } |
| 857 | + |
| 858 | + /** |
| 859 | + * @requires PHP 8 |
| 860 | + */ |
| 861 | + public function testUnionTypeFailsWithBuiltin() |
| 862 | + { |
| 863 | + $container = new ContainerBuilder(); |
| 864 | + |
| 865 | + $container->register('union', UnionConstructor::class) |
| 866 | + ->setArguments([[1, 2, 3]]); |
| 867 | + |
| 868 | + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); |
| 869 | + $this->expectExceptionMessage('Invalid definition for service "union": argument 1 of "Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CheckTypeDeclarationsPass\\UnionConstructor::__construct" accepts "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeDeclarationsPass\Foo|int", "array" passed.'); |
| 870 | + |
| 871 | + (new CheckTypeDeclarationsPass(true))->process($container); |
| 872 | + |
| 873 | + $this->addToAssertionCount(1); |
| 874 | + } |
806 | 875 | }
|
0 commit comments