From 3a77b494b7a58543765b9df0128209d163f7e8b2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 Jan 2023 14:22:46 +0100 Subject: [PATCH 1/6] Create helper to write a gray text line --- packages/framework/src/Console/Concerns/Command.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Console/Concerns/Command.php b/packages/framework/src/Console/Concerns/Command.php index f9bd83c659b..fcc33469aee 100644 --- a/packages/framework/src/Console/Concerns/Command.php +++ b/packages/framework/src/Console/Concerns/Command.php @@ -27,4 +27,9 @@ public function infoComment(string $info, string $comment, ?string $moreInfo = n { $this->line("$info [$comment]".($moreInfo ? " $moreInfo" : '')); } + + public function gray(string $string): void + { + $this->line("$string"); + } } From 73971f68ec410166e9fe57c883fb7ffdffba8d1d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 Jan 2023 14:23:23 +0100 Subject: [PATCH 2/6] Extract helper to write gray text inline --- packages/framework/src/Console/Concerns/Command.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Concerns/Command.php b/packages/framework/src/Console/Concerns/Command.php index fcc33469aee..1070c814f3f 100644 --- a/packages/framework/src/Console/Concerns/Command.php +++ b/packages/framework/src/Console/Concerns/Command.php @@ -30,6 +30,11 @@ public function infoComment(string $info, string $comment, ?string $moreInfo = n public function gray(string $string): void { - $this->line("$string"); + $this->line($this->inlineGray($string)); + } + + public function inlineGray(string $string): string + { + return "$string"; } } From f0750166f204b7cc309bce88e8c1e5072ebd8fc4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 Jan 2023 14:23:56 +0100 Subject: [PATCH 3/6] Mark added methods as experimental --- packages/framework/src/Console/Concerns/Command.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Console/Concerns/Command.php b/packages/framework/src/Console/Concerns/Command.php index 1070c814f3f..362f0026bc3 100644 --- a/packages/framework/src/Console/Concerns/Command.php +++ b/packages/framework/src/Console/Concerns/Command.php @@ -28,11 +28,13 @@ public function infoComment(string $info, string $comment, ?string $moreInfo = n $this->line("$info [$comment]".($moreInfo ? " $moreInfo" : '')); } + /** @experimental This method may change (or be removed) before the 1.0.0 release */ public function gray(string $string): void { $this->line($this->inlineGray($string)); } + /** @experimental This method may change (or be removed) before the 1.0.0 release */ public function inlineGray(string $string): string { return "$string"; From 00fe03f344e2fc05866cc48c64b4e6d6dc14c879 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 Jan 2023 14:24:36 +0100 Subject: [PATCH 4/6] Create helper to write an indented line --- packages/framework/src/Console/Concerns/Command.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Console/Concerns/Command.php b/packages/framework/src/Console/Concerns/Command.php index 362f0026bc3..41ead322299 100644 --- a/packages/framework/src/Console/Concerns/Command.php +++ b/packages/framework/src/Console/Concerns/Command.php @@ -39,4 +39,9 @@ public function inlineGray(string $string): string { return "$string"; } + + public function indentedLine(int $indent, string $string): void + { + $this->line(str_repeat(' ', $indent).$string); + } } From ca2fd3f352b4b6cde577fcf5be90f250e053831d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 22 Jan 2023 14:27:29 +0100 Subject: [PATCH 5/6] Add tests for added methods --- .../framework/tests/Feature/CommandTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/framework/tests/Feature/CommandTest.php b/packages/framework/tests/Feature/CommandTest.php index b1cb12ad40f..7e417737f5d 100644 --- a/packages/framework/tests/Feature/CommandTest.php +++ b/packages/framework/tests/Feature/CommandTest.php @@ -64,6 +64,48 @@ public function testInfoCommentWithExtraInfo() $command->setMockedOutput($output); $command->handle(); } + + public function testGray() + { + $command = new MockableTestCommand(); + $command->closure = function (Command $command) { + $command->gray('foo'); + }; + + $output = $this->mock(OutputStyle::class); + $output->shouldReceive('writeln')->once()->withArgs(function (string $message): bool { + return $message === "foo"; + }); + + $command->setMockedOutput($output); + $command->handle(); + } + + public function testInlineGray() + { + $command = new MockableTestCommand(); + $command->closure = function (Command $command) { + $this->assertSame('foo', $command->inlineGray('foo')); + }; + + $command->handle(); + } + + public function testIndentedLine() + { + $command = new MockableTestCommand(); + $command->closure = function (Command $command) { + $command->indentedLine(2, 'foo'); + }; + + $output = $this->mock(OutputStyle::class); + $output->shouldReceive('writeln')->once()->withArgs(function (string $message): bool { + return $message === ' foo'; + }); + + $command->setMockedOutput($output); + $command->handle(); + } } class MockableTestCommand extends Command From bcd81ca5372ec2e48bf985ec18da4a98bc2cd363 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 22 Jan 2023 13:27:44 +0000 Subject: [PATCH 6/6] Apply fixes from StyleCI --- packages/framework/tests/Feature/CommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/CommandTest.php b/packages/framework/tests/Feature/CommandTest.php index 7e417737f5d..c66773d239d 100644 --- a/packages/framework/tests/Feature/CommandTest.php +++ b/packages/framework/tests/Feature/CommandTest.php @@ -74,7 +74,7 @@ public function testGray() $output = $this->mock(OutputStyle::class); $output->shouldReceive('writeln')->once()->withArgs(function (string $message): bool { - return $message === "foo"; + return $message === 'foo'; }); $command->setMockedOutput($output);