PHP code example of star / structure-assertion

1. Go to this page and download the library: Download star/structure-assertion 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/ */

    

star / structure-assertion example snippets


StructureAssertion::fromArray(
    [
        'data' => [
            'id' => 11,
            'array' => [
                1, 
                2,
                3,
            ],
        ],
    ]
)
    ->enterObjectNode('data') // Assert the node 'data' exists and is an object
    ->assertIsSame('id', 11) // Assert the object's property 'id' exists and match the exact value
    ->enterArrayNode('array') // Assert the node 'data' exists and is an array
    ->assertCount(3); // Assert the number of item is exactly 3

StructureAssertion::fromArray($data)
    ->assertCallback('property', function ($value): bool {
        // When it evaluates to false, the expectation will fail
        // return true | false
    });