This is a collection of helper methods for testing and debugging API endpoints.
You can install the package via composer:
composer require stephenjude/api-test-helper --dev
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);
}
}
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. |
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.