From d0e3f0028624387e7ef0bfedeff9506c0a77e11f Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 14 Jan 2022 10:18:37 +0000 Subject: [PATCH] Fixes `Command::setHidden()` --- src/Illuminate/Console/Command.php | 10 ++++++++ tests/Console/CommandTest.php | 40 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index 0f211946942c..6d9ae8c89381 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -171,6 +171,16 @@ public function isHidden(): bool return $this->hidden; } + /** + * {@inheritdoc} + */ + public function setHidden(bool $hidden = true): static + { + parent::setHidden($this->hidden = $hidden); + + return $this; + } + /** * Get the Laravel application instance. * diff --git a/tests/Console/CommandTest.php b/tests/Console/CommandTest.php index 8b43ade1f786..887f98a6b8c7 100644 --- a/tests/Console/CommandTest.php +++ b/tests/Console/CommandTest.php @@ -120,6 +120,46 @@ public function testTheOutputSetterOverwrite() $command->info('foo'); } + public function testSetHidden() + { + $command = new class extends Command + { + public function parentIsHidden() + { + return parent::isHidden(); + } + }; + + $this->assertFalse($command->isHidden()); + $this->assertFalse($command->parentIsHidden()); + + $command->setHidden(true); + + $this->assertTrue($command->isHidden()); + $this->assertTrue($command->parentIsHidden()); + } + + public function testHiddenProperty() + { + $command = new class extends Command + { + protected $hidden = true; + + public function parentIsHidden() + { + return parent::isHidden(); + } + }; + + $this->assertTrue($command->isHidden()); + $this->assertTrue($command->parentIsHidden()); + + $command->setHidden(false); + + $this->assertFalse($command->isHidden()); + $this->assertFalse($command->parentIsHidden()); + } + public function testChoiceIsSingleSelectByDefault() { $output = m::mock(OutputStyle::class);