diff --git a/src/Illuminate/Testing/PendingCommand.php b/src/Illuminate/Testing/PendingCommand.php index d1ed6f3382b..900d70a36f5 100644 --- a/src/Illuminate/Testing/PendingCommand.php +++ b/src/Illuminate/Testing/PendingCommand.php @@ -8,9 +8,13 @@ use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Support\Arr; +use Illuminate\Support\Collection; use Illuminate\Support\Traits\Conditionable; use Illuminate\Support\Traits\Macroable; use Illuminate\Support\Traits\Tappable; +use Laravel\Prompts\Note as PromptsNote; +use Laravel\Prompts\Prompt as BasePrompt; +use Laravel\Prompts\Table as PromptsTable; use Mockery; use Mockery\Exception\NoMatchingExpectationException; use PHPUnit\Framework\TestCase as PHPUnitTestCase; @@ -247,6 +251,108 @@ public function expectsTable($headers, $rows, $tableStyle = 'default', array $co return $this; } + /** + * Specify that the given Prompts info message should be contained in the command output. + * + * @return $this + */ + public function expectsPromptsInfo(string $message) + { + $this->expectOutputToContainPrompt( + new PromptsNote($message, 'info') + ); + + return $this; + } + + /** + * Specify that the given Prompts warning message should be contained in the command output. + * + * @return $this + */ + public function expectsPromptsWarning(string $message) + { + $this->expectOutputToContainPrompt( + new PromptsNote($message, 'warning') + ); + + return $this; + } + + /** + * Specify that the given Prompts error message should be contained in the command output. + * + * @return $this + */ + public function expectsPromptsError(string $message) + { + $this->expectOutputToContainPrompt( + new PromptsNote($message, 'error') + ); + + return $this; + } + + /** + * Specify that the given Prompts alert message should be contained in the command output. + * + * @return $this + */ + public function expectsPromptsAlert(string $message) + { + $this->expectOutputToContainPrompt( + new PromptsNote($message, 'alert') + ); + + return $this; + } + + /** + * Specify that the given Prompts intro message should be contained in the command output. + * + * @return $this + */ + public function expectsPromptsIntro(string $message) + { + $this->expectOutputToContainPrompt( + new PromptsNote($message, 'intro') + ); + + return $this; + } + + /** + * Specify that the given Prompts outro message should be contained in the command output. + * + * @return $this + */ + public function expectsPromptsOutro(string $message) + { + $this->expectOutputToContainPrompt( + new PromptsNote($message, 'outro') + ); + + return $this; + } + + /** + * Specify a Prompts table that should be printed when the command runs. + * + * @param array>|Collection> $headers + * @param array>|Collection>|null $rows + * @return $this + * + * @phpstan-param ($rows is null ? list>|Collection> : list>|Collection>) $headers + */ + public function expectsPromptsTable(array|Collection $headers, array|Collection|null $rows) + { + $this->expectOutputToContainPrompt( + new PromptsTable($headers, $rows) + ); + + return $this; + } + /** * Assert that the command has the given exit code. * @@ -519,6 +625,20 @@ protected function flushExpectations() $this->test->expectedChoices = []; } + /** + * Render specific prompt to new output to add to expectation. + * + * @return void + */ + protected function expectOutputToContainPrompt(BasePrompt $prompt) + { + $prompt->setOutput($output = new BufferedOutput); + + $prompt->display(); + + $this->expectsOutputToContain(trim($output->fetch())); + } + /** * Handle the object's destruction. *