PHP code example of wheesnoza / assertable-json-enhancer

1. Go to this page and download the library: Download wheesnoza/assertable-json-enhancer 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/ */

    

wheesnoza / assertable-json-enhancer example snippets


$response->assertJson(fn (AssertableJson $json) =>
    $json->whereStringContains('data.name', 'John')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereLessThan('data.age', 18)
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereLessThanOrEqual('data.age', 18)
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereGreaterThan('data.age', 18)
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereGreaterThanOrEqual('data.age', 18)
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereIsArray('data.items')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereArrayHasAtLeast('data.items', 3)
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereArrayHasSize('data.items', 3)
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereStringStartsWith('data.title', 'Laravel')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereStringEndsWith('data.title', 'Framework')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereExactLength('data.code', 10)
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereMatchesPattern('data.email', '/^[\w\-\.]+@([\w\-]+\.)+[\w\-]{2,4}$/')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereIsString('data.name')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereIsInteger('data.age')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereIsBoolean('data.active')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereIsFloat('data.price')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereIsEmpty('data.name')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereIsNotEmpty('data.name')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereStringEquals('data.status', 'active')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereStringNotEquals('data.status', 'inactive')
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereResultsAreOrderedBy('data.items', 'id', 'asc')


);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereResultsContain('data.items', 2)
);

$response->assertJson(fn (AssertableJson $json) =>
    $json->whereResultsMatchCriteria('data.items', ['name' => 'Laravel'], true)
);