Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Latest commit

 

History

History
142 lines (105 loc) · 4.02 KB

README.md

File metadata and controls

142 lines (105 loc) · 4.02 KB

JsonApi-Assert

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Infection MSI Total Downloads

This package provides a set of assertions to test documents using the JSON:API specification.

Technologies

  • PHP 7.3+
  • PHPUnit 9.0+

Installation

To install through composer, simply put the following in your composer.json file:

{
    "require-dev": {
        "vgirol/jsonapi-assert": "dev-master"
    }
}

And then run composer install from the terminal.

Quick Installation

Above installation can also be simplified by using the following command:

composer require vgirol/jsonapi-assert

Usage

You can use these assertions in your classes directly as a static call.

use VGirol\JsonApiAssert\Assert as JsonApiAssert;

class MyTest extends TestCase
{
    /**
     * @test
     */
    public function my_first_test()
    {
        $json = [
            'meta' => [
                'key' => 'value'
            ],
            'jsonapi' => [
                'version' => '1.0'
            ]
        ];

        JsonApiAssert::assertHasValidStructure($json);
    }
}
use VGirol\JsonApiAssert\Assert as JsonApiAssert;
use VGirol\JsonApiAssert\SetExceptionsTrait;
use VGirol\JsonApiStructure\Messages;

class MyTest extends TestCase
{
    use SetExceptionsTrait;

    /**
     * @test
     */
    public function how_to_assert_that_a_test_failed()
    {
        $json = [
            'errors' => [
                'error' => 'not an array of error objects'
            ]
        ];
        $failureMessage = Messages::ERRORS_OBJECT_MUST_BE_ARRAY;

        $this->setAssertionFailure($failureMessage);

        JsonApiAssert::assertHasValidStructure($json);
    }
}

Documentation

The API documentation is available in XHTML format at the url http://jsonapi-assert.girol.fr/docs/ref/index.html.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT 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.