PHP code example of innmind / black-box

1. Go to this page and download the library: Download innmind/black-box 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/ */

    

innmind / black-box example snippets


use Innmind\BlackBox\{
    Application,
    Set,
    Runner\Assert,
    Prove,
};

Application::new([])
    ->tryToProve(static function(Prove $prove) {
        yield $prove
            ->proof('add is commutative')
            ->given(
                Set::integers(),
                Set::integers(),
            )
            ->test(static fn(Assert $assert, int $a, int $b) => $assert->same(
                add($a, $b),
                add($b, $a),
            ));

        yield $prove
            ->proof('add is associative')
            ->given(
                Set::integers(),
                Set::integers(),
                Set::integers(),
            )
            ->test(static fn(Assert $assert, int $a, int $b, int $c) => $assert->same(
                add(add($a, $b), $c),
                add($a, add($b, $c)),
            ));

        yield $prove
            ->proof('add is an identity function')
            ->given(Set::integers())
            ->test(static fn(Assert $assert, int $a) => $assert->same(
                $a,
                add($a, 0),
            ));
    })
    ->exit();