Skip to content

Commit ff89d01

Browse files
authored
Fix the bug that $this->input is given null (#6598)
1 parent 8727481 commit ff89d01

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public function run(InputInterface $input, OutputInterface $output): int
101101
{
102102
$this->output = new SymfonyStyle($input, $output);
103103

104-
$this->setUpTraits();
104+
$this->setUpTraits($this->input = $input, $this->output);
105105

106-
return parent::run($this->input = $input, $this->output);
106+
return parent::run($this->input, $this->output);
107107
}
108108

109109
/**
@@ -211,13 +211,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
211211
/**
212212
* Setup traits of command.
213213
*/
214-
protected function setUpTraits(): array
214+
protected function setUpTraits(InputInterface $input, OutputInterface $output): array
215215
{
216216
$uses = array_flip(class_uses_recursive(static::class));
217217

218218
foreach ($uses as $trait) {
219219
if (method_exists($this, $method = 'setUp' . class_basename($trait))) {
220-
$this->{$method}($this->input, $this->output);
220+
$this->{$method}($input, $output);
221221
}
222222
}
223223

tests/CommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testExitCodeWhenThrowException()
7575
$this->assertSame(0, $exitCode);
7676

7777
$command = new FooTraitCommand();
78-
$this->assertArrayHasKey(\HyperfTest\Command\Command\Traits\Foo::class, (fn () => $this->setUpTraits())->call($command));
78+
$this->assertArrayHasKey(\HyperfTest\Command\Command\Traits\Foo::class, (fn () => $this->setUpTraits($input, $output))->call($command));
7979
$this->assertSame('foo', (fn () => $this->propertyFoo)->call($command));
8080
}
8181

0 commit comments

Comments
 (0)