stephenjude/api-test-helper

This package is abandoned and no longer maintained. No replacement package was suggested.

A collection of helper methods for testing and debugging API endpoints

3.0.0 2023-07-27 06:36 UTC

README

Latest Version on Packagist Build Status Total Downloads

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 stephenjudesuccess@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.