From f09bf1171550ca2e5dec4a31c3dc966d0bdbf45f Mon Sep 17 00:00:00 2001 From: Kathryn Reeve <67553+BinaryKitten@users.noreply.github.com> Date: Thu, 10 Jul 2025 17:19:56 +0100 Subject: [PATCH 1/2] add prompts based expectations to PendingCommand --- src/Illuminate/Testing/PendingCommand.php | 118 ++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/src/Illuminate/Testing/PendingCommand.php b/src/Illuminate/Testing/PendingCommand.php index d1ed6f3382bd..6216b1900e15 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,106 @@ 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 string[]|Collection $headers + * @param string[]|Collection|null $rows + * @return $this + */ + 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 +623,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. * From c468b233573ad2f33a86776710b731d844c1beaa Mon Sep 17 00:00:00 2001 From: Kathryn Reeve <67553+BinaryKitten@users.noreply.github.com> Date: Thu, 10 Jul 2025 17:27:48 +0100 Subject: [PATCH 2/2] copy type definitions from Laravel\Prompts\Table to the expectation --- src/Illuminate/Testing/PendingCommand.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Testing/PendingCommand.php b/src/Illuminate/Testing/PendingCommand.php index 6216b1900e15..900d70a36f52 100644 --- a/src/Illuminate/Testing/PendingCommand.php +++ b/src/Illuminate/Testing/PendingCommand.php @@ -338,9 +338,11 @@ public function expectsPromptsOutro(string $message) /** * Specify a Prompts table that should be printed when the command runs. * - * @param string[]|Collection $headers - * @param string[]|Collection|null $rows + * @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) {