https://github.com/vs0uz4/bypassforphp-snippets
VS-Code Snippets for Bypass in Pest Tests
https://github.com/vs0uz4/bypassforphp-snippets
api-tests bypass pest php tests
Last synced: 3 months ago
JSON representation
VS-Code Snippets for Bypass in Pest Tests
- Host: GitHub
- URL: https://github.com/vs0uz4/bypassforphp-snippets
- Owner: vs0uz4
- License: mit
- Created: 2021-08-20T21:45:00.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-20T22:03:12.000Z (over 4 years ago)
- Last Synced: 2025-01-07T21:42:58.336Z (about 1 year ago)
- Topics: api-tests, bypass, pest, php, tests
- Homepage:
- Size: 163 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Bypass for PHP Snippets
Code snippets for writing tests for PHP using [Bypass for PHP](https://bypassforphp.com/) in Visual Studio Code.

## Usage
### Writing Tests
To write a test, you first need to open the Bypass Server.
#### Opening Server
Bypass provides two fuctions for opening server `open()` and `serve()`.
Type `:bopen` + [TAB] for:
```php
Bypass::open();
```
Type `:bserv` + [TAB] for:
```php
Bypass::serve(
//Route::
);
```
#### Get Base URL and/or Port
Type `:bburl` + [TAB] for:
```php
->getBaseUrl();
```
Type `:bport` + [TAB] for:
```php
->getPort();
```
#### Stop and Shut down
Type `:bstop` + [TAB] for:
```php
->stop();
```
Type `:bdown` + [TAB] for:
```php
->down();
```
#### Adding Routes (Standard and File)
Bypass Server provides two types of routes: `Standard Routes` and `File Routes`.
For standard routes the bypass provides the `addRoute()` method. This method has an alias, called `expect()`.
Type `:baro` + [TAB] for:
```php
->addRoute(method: '', uri: '', status: , body: );
```
Type `:bexp` + [TAB] for:
```php
->expect(method: '', uri: '', status: , body: );
```
For File routes:
Type `:bafr` + [TAB] for:
```php
->addFileRoute(method: '', uri: '', status: , file: );
```
#### Asserting Routes
Type `:bass` + [TAB] for:
```php
->assertRoutes();
```
### Route Helpers
When we use the `serve()` method to open a bypass server, it expects us to pass it routes. And for this, Bypass offers us the route helpers.
After opening the Bypass server by typing `:bserv`, finish adding the desired route.
Example: Type `:brok` + [TAB] produces:
```php
Bypass::serve(
Route::ok(method: '', uri: '', body: '', times: )
..
);
```
Available `Route::` methods:
| Trigger | Snippet |
| --------------- | ---------------- |
| :brok | Route::ok(method: '', uri: '', body: '', times: ) |
| :brbadrequest | Route::badRequest(method: '', uri: '', body: '', times: ) |
| :brunauthorized | Route::unauthorized(method: '', uri: '', body: '$', times: ) |
| :brforbidden | Route::forbidden(method: '', uri: '', body: '', times: ) |
| :brcreated | Route::created(uri: '', body: '', times: ) |
| :brnotfound | Route::notFound(method: '', uri: '', body: '', times: ) |
| :brnotallowed | Route::notAllowed(method: '', uri: '', body: '', times: ) |
| :brtoomany | Route::tooMany(method: '', uri: '', body: '', times: ) |
| :brservererror | Route::serverError(method: '', uri: '', body: '', times: ) |
| :brvalidationfailed | Route::validationFailed(method: '', uri: '', body: '', times: ) |
| :brfile | Route::file(method: '', uri: '', file: '', status: , times: ) |
| :brget | Route::get(uri: '', body: '', status: , times: ) |
| :brgetfile | Route::getFile(uri: '', file: '', status: , times: ) |
| :brpost | Route::post(uri: '', body: '', status: , times: ) |
| :brput | Route::put(uri: '', body: '', status: , times: ) |
| :brdelete | Route::delete(uri: '', body: '', status: , times: ) |
| :brpatch | Route::patch(uri: '', body: '', status: , times: ) |