Skip to content

Commit

Permalink
Merge branch 'master' into handle-deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva authored Jan 22, 2023
2 parents dc5aa8e + 5244994 commit 27371bb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/framework/src/Console/Concerns/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,21 @@ public function infoComment(string $info, string $comment, ?string $moreInfo = n
{
$this->line("<info>$info</info> [<comment>$comment</comment>]".($moreInfo ? " <info>$moreInfo</info>" : ''));
}

/** @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 "<fg=gray>$string</>";
}

public function indentedLine(int $indent, string $string): void
{
$this->line(str_repeat(' ', $indent).$string);
}
}
42 changes: 42 additions & 0 deletions packages/framework/tests/Feature/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '<fg=gray>foo</>';
});

$command->setMockedOutput($output);
$command->handle();
}

public function testInlineGray()
{
$command = new MockableTestCommand();
$command->closure = function (Command $command) {
$this->assertSame('<fg=gray>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
Expand Down

0 comments on commit 27371bb

Please sign in to comment.