|
23 | 23 | */ |
24 | 24 | final class RenderConsoleCommandTest extends FrameworkIntegrationTestCase |
25 | 25 | { |
26 | | - public function test_render(): void |
27 | | - { |
28 | | - $handler = new MethodReflector(new ReflectionMethod(new MyConsole(), 'handle')); |
| 26 | + private GenericConsole $testConsole; |
29 | 27 |
|
30 | | - $consoleCommand = $handler->getAttributes(ConsoleCommand::class)[0]; |
| 28 | + private MemoryOutputBuffer $consoleOutput; |
31 | 29 |
|
32 | | - $consoleCommand->setHandler($handler); |
| 30 | + protected function setUp(): void |
| 31 | + { |
| 32 | + parent::setUp(); |
33 | 33 |
|
34 | | - $output = new MemoryOutputBuffer(); |
| 34 | + $this->consoleOutput = new MemoryOutputBuffer(); |
35 | 35 |
|
36 | 36 | $highlighter = new Highlighter(new TextTerminalTheme()); |
37 | 37 |
|
38 | | - $console = new GenericConsole( |
39 | | - output: $output, |
| 38 | + $this->testConsole = new GenericConsole( |
| 39 | + output: $this->consoleOutput, |
40 | 40 | input: new UnsupportedInputBuffer(), |
41 | 41 | highlighter: $highlighter, |
42 | 42 | executeConsoleCommand: $this->container->get(ExecuteConsoleCommand::class), |
43 | 43 | argumentBag: $this->container->get(ConsoleArgumentBag::class), |
44 | 44 | ); |
| 45 | + } |
| 46 | + |
| 47 | + public function test_render(): void |
| 48 | + { |
| 49 | + $handler = new MethodReflector(new ReflectionMethod(new MyConsole(), 'handle')); |
| 50 | + |
| 51 | + $consoleCommand = $handler->getAttributes(ConsoleCommand::class)[0]; |
| 52 | + |
| 53 | + $consoleCommand->setHandler($handler); |
45 | 54 |
|
46 | | - (new RenderConsoleCommand($console))($consoleCommand); |
| 55 | + (new RenderConsoleCommand($this->testConsole))($consoleCommand); |
47 | 56 |
|
48 | 57 | $this->assertSame( |
49 | 58 | 'test description', |
50 | | - trim($output->getBufferWithoutFormatting()[0]), |
| 59 | + trim($this->consoleOutput->getBufferWithoutFormatting()[0]), |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + public function test_render_arguments(): void |
| 64 | + { |
| 65 | + $handler = new MethodReflector(new ReflectionMethod(new MyConsole(), 'handle')); |
| 66 | + |
| 67 | + $consoleCommand = $handler->getAttributes(ConsoleCommand::class)[0]; |
| 68 | + |
| 69 | + $consoleCommand->setHandler($handler); |
| 70 | + |
| 71 | + $renderConsoleCommand = new RenderConsoleCommand( |
| 72 | + console: $this->testConsole, |
| 73 | + renderArguments: true, |
| 74 | + ); |
| 75 | + |
| 76 | + $renderConsoleCommand($consoleCommand); |
| 77 | + |
| 78 | + $this->assertSame( |
| 79 | + 'test <path> <type {a|b|c}> [fallback=a {a|b|c}] [nullable-enum=null {a|b|c}] [times=1] [--force=false] [optional=null] description', |
| 80 | + trim($this->consoleOutput->getBufferWithoutFormatting()[0]), |
51 | 81 | ); |
52 | 82 | } |
53 | 83 | } |
0 commit comments