PHP code example of garethellis / hamcrest-matchers

1. Go to this page and download the library: Download garethellis/hamcrest-matchers 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/ */

    

garethellis / hamcrest-matchers example snippets



/** ... **/
assertThat($uuid, is(aUUID()));


/** ... **/
assertThat([$uuid1, $uuid2, $uuid3], is(anArrayOfUUIDs()));


/** ... **/
assertThat($html, containsHTML());


/** .. **/
assertThat($json, is(validJSON()));

assertThat($aTraversableInstance, hasEqualValuesTo($anArray));

assertThat("hello", matchesUsing(function($value) { return $value === "hello"; }));

function isSomething()
{
    return describedAs('a custom value', new CallbackMatcher(
        function($value) {
            return $value === 'my custom value';
        }
    )
}
assertThat($foo, isSomething());