|
8 | 8 | use Illuminate\Contracts\Container\Container;
|
9 | 9 | use Illuminate\Contracts\Support\Arrayable;
|
10 | 10 | use Illuminate\Support\Arr;
|
| 11 | +use Illuminate\Support\Collection; |
11 | 12 | use Illuminate\Support\Traits\Conditionable;
|
12 | 13 | use Illuminate\Support\Traits\Macroable;
|
13 | 14 | use Illuminate\Support\Traits\Tappable;
|
| 15 | +use Laravel\Prompts\Note as PromptsNote; |
| 16 | +use Laravel\Prompts\Prompt as BasePrompt; |
| 17 | +use Laravel\Prompts\Table as PromptsTable; |
14 | 18 | use Mockery;
|
15 | 19 | use Mockery\Exception\NoMatchingExpectationException;
|
16 | 20 | use PHPUnit\Framework\TestCase as PHPUnitTestCase;
|
@@ -247,6 +251,122 @@ public function expectsTable($headers, $rows, $tableStyle = 'default', array $co
|
247 | 251 | return $this;
|
248 | 252 | }
|
249 | 253 |
|
| 254 | + /** |
| 255 | + * Specify that the given Prompts info message should be contained in the command output. |
| 256 | + * |
| 257 | + * @return $this |
| 258 | + */ |
| 259 | + public function expectsPromptsInfo(string $message) |
| 260 | + { |
| 261 | + $this->expectOutputToContainPrompt( |
| 262 | + new PromptsNote($message, 'info') |
| 263 | + ); |
| 264 | + |
| 265 | + return $this; |
| 266 | + } |
| 267 | + |
| 268 | + /** |
| 269 | + * Specify that the given Prompts warning message should be contained in the command output. |
| 270 | + * |
| 271 | + * @return $this |
| 272 | + */ |
| 273 | + public function expectsPromptsWarning(string $message) |
| 274 | + { |
| 275 | + $this->expectOutputToContainPrompt( |
| 276 | + new PromptsNote($message, 'warning') |
| 277 | + ); |
| 278 | + |
| 279 | + return $this; |
| 280 | + } |
| 281 | + |
| 282 | + /** |
| 283 | + * Specify that the given Prompts error message should be contained in the command output. |
| 284 | + * |
| 285 | + * @return $this |
| 286 | + */ |
| 287 | + public function expectsPromptsError(string $message) |
| 288 | + { |
| 289 | + $this->expectOutputToContainPrompt( |
| 290 | + new PromptsNote($message, 'error') |
| 291 | + ); |
| 292 | + |
| 293 | + return $this; |
| 294 | + } |
| 295 | + |
| 296 | + /** |
| 297 | + * Specify that the given Prompts alert message should be contained in the command output. |
| 298 | + * |
| 299 | + * @return $this |
| 300 | + */ |
| 301 | + public function expectsPromptsAlert(string $message) |
| 302 | + { |
| 303 | + $this->expectOutputToContainPrompt( |
| 304 | + new PromptsNote($message, 'alert') |
| 305 | + ); |
| 306 | + |
| 307 | + return $this; |
| 308 | + } |
| 309 | + |
| 310 | + /** |
| 311 | + * Specify that the given Prompts intro message should be contained in the command output. |
| 312 | + * |
| 313 | + * @return $this |
| 314 | + */ |
| 315 | + public function expectsPromptsIntro(string $message) |
| 316 | + { |
| 317 | + $this->expectOutputToContainPrompt( |
| 318 | + new PromptsNote($message, 'intro') |
| 319 | + ); |
| 320 | + |
| 321 | + return $this; |
| 322 | + } |
| 323 | + |
| 324 | + /** |
| 325 | + * Specify that the given Prompts outro message should be contained in the command output. |
| 326 | + * |
| 327 | + * @return $this |
| 328 | + */ |
| 329 | + public function expectsPromptsOutro(string $message) |
| 330 | + { |
| 331 | + $this->expectOutputToContainPrompt( |
| 332 | + new PromptsNote($message, 'outro') |
| 333 | + ); |
| 334 | + |
| 335 | + return $this; |
| 336 | + } |
| 337 | + |
| 338 | + /** |
| 339 | + * Specify a Prompts table that should be printed when the command runs. |
| 340 | + * |
| 341 | + * @param array<int, string|array<int, string>>|Collection<int, string|array<int, string>> $headers |
| 342 | + * @param array<int, array<int, string>>|Collection<int, array<int, string>>|null $rows |
| 343 | + * @return $this |
| 344 | + * |
| 345 | + * @phpstan-param ($rows is null ? list<list<string>>|Collection<int, list<string>> : list<string|list<string>>|Collection<int, string|list<string>>) $headers |
| 346 | + */ |
| 347 | + public function expectsPromptsTable(array|Collection $headers, array|Collection|null $rows) |
| 348 | + { |
| 349 | + $this->expectOutputToContainPrompt( |
| 350 | + new PromptsTable($headers, $rows) |
| 351 | + ); |
| 352 | + |
| 353 | + return $this; |
| 354 | + } |
| 355 | + |
| 356 | + /** |
| 357 | + * Render the given prompt and add the output to the expectations. |
| 358 | + * |
| 359 | + * @return void |
| 360 | + */ |
| 361 | + protected function expectOutputToContainPrompt(BasePrompt $prompt) |
| 362 | + { |
| 363 | + $prompt->setOutput($output = new BufferedOutput); |
| 364 | + |
| 365 | + $prompt->display(); |
| 366 | + |
| 367 | + $this->expectsOutputToContain(trim($output->fetch())); |
| 368 | + } |
| 369 | + |
250 | 370 | /**
|
251 | 371 | * Assert that the command has the given exit code.
|
252 | 372 | *
|
|
0 commit comments