From aa534c4f6d36d2761933cab4e126438621170634 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Mon, 21 Feb 2022 09:09:23 +0100 Subject: [PATCH] wip --- README.md | 103 +++++++++++++++++++++++++++++++++- src/Commands/VisitCommand.php | 10 ++-- 2 files changed, 106 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 450e8bf..add004f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,22 @@ [![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/spatie/laravel-visit/Check%20&%20fix%20styling?label=code%20style)](https://github.com/spatie/laravel-visit/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-visit.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-visit) -This package contains an artisan command `visit` that allows you to visit any route of your Laravel app +This package contains an artisan command `visit` that allows you to visit any route of your Laravel app. + +```bash +php artisan /my-page +``` + +The command display the colorized version of the HTML... + +![screenshot](TODO: add screenshot) + +... followed by a results block. + +![screenshot](TODO: add screenshot) + +The command can also colorize JSON output. It also has support for some Laravel niceties such as logging in users before making a request, using a route name instead of and URL, and much more. + ## Support us [](https://spatie.be/github-ad-click/laravel-visit) @@ -26,12 +41,96 @@ composer require spatie/laravel-visit ## Usage -More detailed instructions coming soon. +To visit a certain page, execute `php artisan` followed by a URL. ```bash php artisan visit /your-page ``` +![screenshot](TODO: add screenshot) + +Instead of passing an URL, you can pass a route name to the `route` option. Here's an example where we will visit the route named "contact". + +```bash +php artisan visit --route=contact +``` + +### Using a different method + +By default, the `visit` command will make GET request. To use a different HTTP verb, you can pass it to the `method` option. + +```bash +php artisan visit /users/1 --method=delete +``` + +### Passing a payload + +You can pass a payload to non-GET request by using the payload. The payload should be formatted as JSON. + +```bash +php artisan visit /users --method=post --payload="{name: 'John Doe'}" +``` + +### Logging in a user + +To log in a user before making a request, add the `--user` and pass it a user id. + +```php +php artisan visit /api/user/me --user=1 +``` + +Alternatively, you can also pass an email address to the `user` option. + +```php +php artisan visit /api/user/me --user=john@example.com +``` + +### Showing the headers of the response + +By default, the `visit` command will not show any headers. To display them, add the `--show-headers` option + +```bash +php artisan visit /my-page --show-headers +``` + +![screenshot](TODO: add screenshot) + +### Showing exception pages + +When your application responds with an exception, the `visit` command will show that exception message and not the HTML of your error page. + +To let the `visit` command display the HTML of an error page when an exception occurs, use the `--handle-exceptions` option. + +```bash +php artisan visit /page-with-exception --handle-exceptions +``` + +### Only displaying the response + +If you want the `visit` command to only display the response, omitting the response result block at the end, pass the `--only-response` option. + +```bash +php artisan visit / --only-response +``` + +### Only displaying the response properties block + +To avoid displaying the response, and only display the response result block, use the `--only-response-properties` option + +```bash +php artisan visit / --only-response-properties +``` + +### Avoid colorizing the response + +The `visit` command will automatically colorize any HTML and JSON output. To avoid the output being colorized, use the `--no-color` option. + +```bash +php artisan visit / --no-color +``` + + + ## Testing ```bash diff --git a/src/Commands/VisitCommand.php b/src/Commands/VisitCommand.php index d322d03..3124e1e 100644 --- a/src/Commands/VisitCommand.php +++ b/src/Commands/VisitCommand.php @@ -20,13 +20,13 @@ class VisitCommand extends Command visit {url?} {--route=} {--method=get} - {--show-headers} {--payload=} {--user=} + {--handle-exceptions} + {--show-headers} {--no-color} {--only-response} - {--hide-response} - {--show-exceptions} + {--only-response-properties} '; // add refreshing @@ -112,7 +112,7 @@ protected function makeRequest(): TestResponse $client = Client::make(); - if ($this->option('show-exceptions')) { + if (! $this->option('handle-exceptions')) { $client->withoutExceptionHandling(); } @@ -123,7 +123,7 @@ protected function makeRequest(): TestResponse protected function renderResponse(TestResponse $response): self { - if (! $this->option('hide-response')) { + if (! $this->option('only-response-properties')) { $this->renderContent($response); }