stephenjude / api-test-helper
A collection of helper methods for testing and debugging API endpoints
Installs: 3 272
Dependents: 0
Suggesters: 0
Security: 0
Stars: 50
Watchers: 4
Forks: 2
Open Issues: 0
pkg:composer/stephenjude/api-test-helper
Requires
- php: ^8.0
- illuminate/support: ^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2023-12-13 16:00:38 UTC
README
This is a collection of helper methods for testing and debugging API endpoints.
Installation
You can install the package via composer:
composer require stephenjude/api-test-helper --dev
Usage
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
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.