Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stephenjude/api-test-helper
A collection of helper methods for testing and debugging API endpoints.
https://github.com/stephenjude/api-test-helper
api api-testing helpers laravel laravel-framework testing
Last synced: 3 months ago
JSON representation
A collection of helper methods for testing and debugging API endpoints.
- Host: GitHub
- URL: https://github.com/stephenjude/api-test-helper
- Owner: stephenjude
- License: mit
- Created: 2020-11-15T18:08:42.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-14T11:21:57.000Z (over 1 year ago)
- Last Synced: 2024-04-13T20:52:03.828Z (10 months ago)
- Topics: api, api-testing, helpers, laravel, laravel-framework, testing
- Language: PHP
- Homepage:
- Size: 36.1 KB
- Stars: 48
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel API Test Helpers
[![Latest Version on Packagist](https://img.shields.io/packagist/v/stephenjude/api-test-helper.svg?style=flat-square)](https://packagist.org/packages/stephenjude/api-test-helper)
[![Build Status](https://img.shields.io/travis/stephenjude/api-test-helper/master.svg?style=flat-square)](https://travis-ci.org/stephenjude/api-test-helper)
[![Total Downloads](https://img.shields.io/packagist/dt/stephenjude/api-test-helper.svg?style=flat-square)](https://packagist.org/packages/stephenjude/api-test-helper)This is a collection of helper methods for testing and debugging API endpoints.
## Installation
You can install the package via composer:
```bash
composer require stephenjude/api-test-helper --dev
```## Usage
``` php
namespace Tests\Apis;
use App\Models\User;
use Tests\TestCase;
use Stephenjude\ApiTestHelper\WithApiHelper;class UserApiTest extends TestCase
{
use WithApiHelper;/*
* @test
*/
public function testGetAllUsers()
{
$actualUsers = User::all();$this->response = $this->getJson('/users');
// Assert response is 200
$this->response->assertOk();// Dump api data to the console
$this->dumpApiData();// Write api data to the log file
$this->logApiData();// Return a decoded api response data
$responseData = $this->decodeApiResponse();// Assert API data is a collection
$this->assertApiResponseCollection($actualUsers);
}
}
```## Available Helper Methods
Method | Description
---------|----------
`decodeApiResponse()` | Returns a decoded api response data.
`dumpApiData()` | Dump api response data to the console.
`logApiData()` | Write api response data to the log file.
`assertApiSuccess()` | Assert api response data is successful: [success => true].
`assertApiResponse($actualData)` | Assert api response data is same actual data item.
`assertApiResponseCollection($actualData)` | Assert api response data is same actual collection items.### Testing
``` bash
composer test
```### Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Stephen Jude](https://github.com/stephenjude)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.