|
21 | 21 | use Symfony\Component\Console\Exception\InvalidOptionException;
|
22 | 22 | use Symfony\Component\Console\Exception\LogicException;
|
23 | 23 | use Symfony\Component\Console\Input\ArrayInput;
|
| 24 | +use Symfony\Component\Console\Input\InputInterface; |
24 | 25 | use Symfony\Component\Console\Output\NullOutput;
|
| 26 | +use Symfony\Component\Console\Output\OutputInterface; |
25 | 27 |
|
26 | 28 | class InvokableCommandTest extends TestCase
|
27 | 29 | {
|
@@ -142,6 +144,45 @@ public function testInvalidOptionType()
|
142 | 144 | $command->getDefinition();
|
143 | 145 | }
|
144 | 146 |
|
| 147 | + public function testExecuteHasPriorityOverInvokeMethod() |
| 148 | + { |
| 149 | + $command = new class extends Command { |
| 150 | + public string $called; |
| 151 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 152 | + { |
| 153 | + $this->called = __FUNCTION__; |
| 154 | + |
| 155 | + return 0; |
| 156 | + } |
| 157 | + |
| 158 | + public function __invoke(): int |
| 159 | + { |
| 160 | + $this->called = __FUNCTION__; |
| 161 | + |
| 162 | + return 0; |
| 163 | + } |
| 164 | + }; |
| 165 | + |
| 166 | + $command->run(new ArrayInput([]), new NullOutput()); |
| 167 | + $this->assertSame('execute', $command->called); |
| 168 | + } |
| 169 | + |
| 170 | + public function testCallInvokeMethodWhenExtendingCommandClass() |
| 171 | + { |
| 172 | + $command = new class extends Command { |
| 173 | + public string $called; |
| 174 | + public function __invoke(): int |
| 175 | + { |
| 176 | + $this->called = __FUNCTION__; |
| 177 | + |
| 178 | + return 0; |
| 179 | + } |
| 180 | + }; |
| 181 | + |
| 182 | + $command->run(new ArrayInput([]), new NullOutput()); |
| 183 | + $this->assertSame('__invoke', $command->called); |
| 184 | + } |
| 185 | + |
145 | 186 | public function testInvalidReturnType()
|
146 | 187 | {
|
147 | 188 | $command = new Command('foo');
|
|
0 commit comments