|
2 | 2 |
|
3 | 3 | namespace Tests\Cases\DI; |
4 | 4 |
|
| 5 | +use Contributte\Messenger\Exception\LogicalException; |
5 | 6 | use Contributte\Tester\Toolkit; |
6 | 7 | use Nette\DI\Compiler; |
7 | 8 | use Symfony\Component\Messenger\Transport\TransportInterface; |
@@ -36,3 +37,66 @@ Toolkit::test(function (): void { |
36 | 37 | Assert::count(1, $container->findByType(TransportInterface::class)); |
37 | 38 | Assert::count(1, $container->findByType(SimpleHandler::class)); |
38 | 39 | }); |
| 40 | + |
| 41 | +// Error: no invoke method |
| 42 | +Toolkit::test(function (): void { |
| 43 | + Assert::exception( |
| 44 | + static function (): void { |
| 45 | + Container::of() |
| 46 | + ->withDefaults() |
| 47 | + ->withCompiler(function (Compiler $compiler): void { |
| 48 | + $compiler->addConfig(Helpers::neon(<<<'NEON' |
| 49 | + messenger: |
| 50 | + services: |
| 51 | + - { factory: Tests\Mocks\Handler\NoMethodHandler, tags: [contributte.messenger.handler] } |
| 52 | + NEON |
| 53 | + )); |
| 54 | + }) |
| 55 | + ->build(); |
| 56 | + }, |
| 57 | + LogicalException::class, |
| 58 | + 'Handler must have "Tests\Mocks\Handler\NoMethodHandler::__invoke()" method.' |
| 59 | + ); |
| 60 | +}); |
| 61 | + |
| 62 | +// Error: multiple attributes |
| 63 | +Toolkit::test(function (): void { |
| 64 | + Assert::exception( |
| 65 | + static function (): void { |
| 66 | + Container::of() |
| 67 | + ->withDefaults() |
| 68 | + ->withCompiler(function (Compiler $compiler): void { |
| 69 | + $compiler->addConfig(Helpers::neon(<<<'NEON' |
| 70 | + messenger: |
| 71 | + services: |
| 72 | + - Tests\Mocks\Handler\MultipleAttributesHandler |
| 73 | + NEON |
| 74 | + )); |
| 75 | + }) |
| 76 | + ->build(); |
| 77 | + }, |
| 78 | + LogicalException::class, |
| 79 | + 'Only attribute #[AsMessageHandler] can be used on class "Tests\Mocks\Handler\MultipleAttributesHandler"' |
| 80 | + ); |
| 81 | +}); |
| 82 | + |
| 83 | +// Error: multiple parameters handler |
| 84 | +Toolkit::test(function (): void { |
| 85 | + Assert::exception( |
| 86 | + static function (): void { |
| 87 | + Container::of() |
| 88 | + ->withDefaults() |
| 89 | + ->withCompiler(function (Compiler $compiler): void { |
| 90 | + $compiler->addConfig(Helpers::neon(<<<'NEON' |
| 91 | + messenger: |
| 92 | + services: |
| 93 | + - Tests\Mocks\Handler\MultipleParametersHandler |
| 94 | + NEON |
| 95 | + )); |
| 96 | + }) |
| 97 | + ->build(); |
| 98 | + }, |
| 99 | + LogicalException::class, |
| 100 | + 'Only one parameter is allowed in "Tests\Mocks\Handler\MultipleParametersHandler::__invoke()."' |
| 101 | + ); |
| 102 | +}); |
0 commit comments