PHP code example of vgirol / jsonapi-assert
1. Go to this page and download the library: Download vgirol/jsonapi-assert library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vgirol / jsonapi-assert example snippets
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);
}
}