PHP code example of sophie-spec / ensure

1. Go to this page and download the library: Download sophie-spec/ensure 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/ */

    

sophie-spec / ensure example snippets


use function Sophie\Ensure\ensure;

$add = function ($a, $b) {
    return $a + $b;
};

ensure($add(1, 2), 3);

ensure($add(1, 2), 10);
/*
    Both values are not equal.

    Provided value:
        3

    Expected value:
        10
*/

ensure(
    [
        'strawberry',
        'orange',
        'lime',
    ],
    [
        'orange',
        'lime',
        'strawberry',
    ],
);

/*
    Both values are not equal.

    Provided value:
        array:3 [
            0 => (10) "strawberry"
            1 => (6) "orange"
            2 => (4) "lime"
        ]

    Expected value:
        array:3 [
            0 => (6) "orange"
            1 => (4) "lime"
            2 => (10) "strawberry"
        ]
*/