Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Feb 21, 2022
1 parent 48c5257 commit aa534c4
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 7 deletions.
103 changes: 101 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-visit.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-visit)
Expand All @@ -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 [email protected]
```

### 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
Expand Down
10 changes: 5 additions & 5 deletions src/Commands/VisitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -112,7 +112,7 @@ protected function makeRequest(): TestResponse

$client = Client::make();

if ($this->option('show-exceptions')) {
if (! $this->option('handle-exceptions')) {
$client->withoutExceptionHandling();
}

Expand All @@ -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);
}

Expand Down

0 comments on commit aa534c4

Please sign in to comment.