|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace OldSound\RabbitMqBundle\Tests\Command; |
4 | | - |
5 | 3 | use OldSound\RabbitMqBundle\Command\MultipleConsumerCommand; |
| 4 | +use Symfony\Component\Console\Application; |
| 5 | +use Symfony\Component\Console\Helper\HelperSet; |
| 6 | +use Symfony\Component\Console\Input\InputDefinition; |
6 | 7 | use Symfony\Component\Console\Input\InputOption; |
7 | 8 |
|
8 | | -class MultipleConsumerCommandTest extends BaseCommandTest |
9 | | -{ |
10 | | - protected function setUp(): void |
11 | | - { |
12 | | - parent::setUp(); |
13 | | - $this->definition->expects($this->any()) |
14 | | - ->method('getOptions') |
15 | | - ->will($this->returnValue([ |
16 | | - new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'), |
17 | | - new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'), |
18 | | - new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'), |
19 | | - ])); |
20 | | - $this->application->expects($this->once()) |
21 | | - ->method('getHelperSet') |
22 | | - ->will($this->returnValue($this->helperSet)); |
23 | | - |
24 | | - $this->command = new MultipleConsumerCommand(); |
25 | | - $this->command->setApplication($this->application); |
26 | | - } |
27 | | - |
28 | | - /** |
29 | | - * testInputsDefinitionCommand |
30 | | - */ |
31 | | - public function testInputsDefinitionCommand() |
32 | | - { |
33 | | - // check argument |
34 | | - $definition = $this->command->getDefinition(); |
35 | | - $this->assertTrue($definition->hasArgument('name')); |
36 | | - $this->assertTrue($definition->getArgument('name')->isRequired()); // Name is required to find the service |
37 | | - |
38 | | - $this->assertTrue($definition->hasArgument('context')); |
39 | | - $this->assertFalse($definition->getArgument('context')->isRequired()); // Context is required for the queue options provider |
40 | | - |
41 | | - //check options |
42 | | - $this->assertTrue($definition->hasOption('messages')); |
43 | | - $this->assertTrue($definition->getOption('messages')->isValueOptional()); // It should accept value |
44 | | - |
45 | | - $this->assertTrue($definition->hasOption('route')); |
46 | | - $this->assertTrue($definition->getOption('route')->isValueOptional()); // It should accept value |
47 | | - |
48 | | - $this->assertTrue($definition->hasOption('without-signals')); |
49 | | - $this->assertFalse($definition->getOption('without-signals')->acceptValue()); // It shouldn't accept value because it is a true/false input |
50 | | - |
51 | | - $this->assertTrue($definition->hasOption('debug')); |
52 | | - $this->assertFalse($definition->getOption('debug')->acceptValue()); // It shouldn't accept value because it is a true/false input |
53 | | - } |
54 | | -} |
| 9 | +beforeEach(function () { |
| 10 | + $this->application = $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock(); |
| 11 | + $this->definition = $this->getMockBuilder(InputDefinition::class)->disableOriginalConstructor()->getMock(); |
| 12 | + $this->helperSet = $this->getMockBuilder(HelperSet::class)->getMock(); |
| 13 | + |
| 14 | + $this->application->method('getDefinition')->willReturn($this->definition); |
| 15 | + $this->definition->method('getArguments')->willReturn([]); |
| 16 | + $this->definition->method('getOptions')->willReturn([ |
| 17 | + new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'), |
| 18 | + new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'), |
| 19 | + new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'), |
| 20 | + ]); |
| 21 | + |
| 22 | + $this->application->expects($this->once())->method('getHelperSet')->willReturn($this->helperSet); |
| 23 | + |
| 24 | + $this->command = new MultipleConsumerCommand(); |
| 25 | + $this->command->setApplication($this->application); |
| 26 | +}); |
| 27 | + |
| 28 | +test('multiple consumer command has the correct input definition', function () { |
| 29 | + $definition = $this->command->getDefinition(); |
| 30 | + |
| 31 | + expect($definition->hasArgument('name'))->toBeTrue(); |
| 32 | + expect($definition->getArgument('name')->isRequired())->toBeTrue(); |
| 33 | + |
| 34 | + expect($definition->hasArgument('context'))->toBeTrue(); |
| 35 | + expect($definition->getArgument('context')->isRequired())->toBeFalse(); |
| 36 | + |
| 37 | + expect($definition->hasOption('messages'))->toBeTrue(); |
| 38 | + expect($definition->getOption('messages')->isValueOptional())->toBeTrue(); |
| 39 | + |
| 40 | + expect($definition->hasOption('route'))->toBeTrue(); |
| 41 | + expect($definition->getOption('route')->isValueOptional())->toBeTrue(); |
| 42 | + |
| 43 | + expect($definition->hasOption('without-signals'))->toBeTrue(); |
| 44 | + expect($definition->getOption('without-signals')->acceptValue())->toBeFalse(); |
| 45 | + |
| 46 | + expect($definition->hasOption('debug'))->toBeTrue(); |
| 47 | + expect($definition->getOption('debug')->acceptValue())->toBeFalse(); |
| 48 | +}); |
0 commit comments