2017 © Pedro Peláez
 

library hamcrest-matchers

A set of custom Hamcrest matchers

image

garethellis/hamcrest-matchers

A set of custom Hamcrest matchers

  • Monday, October 3, 2016
  • by Garethellis
  • Repository
  • 1 Watchers
  • 2 Stars
  • 571 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 12 Versions
  • 11 % Grown

The README.md

A simple collection of custom Hamcrest matchers for use with hamcrest/hamcrest-php., (*1)

Code Climate, (*2)

Installation

Install with composer:, (*3)

composer require --dev garethellis/hamcrest-matchers, (*4)

Matchers

UUID matcher

Matches a valid UUID. Example usage:, (*5)

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

To match an array of UUIDs:, (*6)

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

This matcher uses the callback matcher (see below) from Nils Luxton., (*7)

HTML matcher

Matches a string containing HTML. Example usage;, (*8)

<?php
/** ... **/
assertThat($html, containsHTML());

Valid JSON matcher

Matches a valid JSON string. Example usage:, (*9)

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

Array values matcher

Match the values of an array or Traversable instance. Note - ignores keys., (*10)

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

Callback Matcher

Callback matching is achieved thanks to Nils Luxton and his callback matcher lib (included as a composer dependency in this library). Example usage:, (*11)

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

Creating new custom callback matchers

You can create your own custom matchers with the callback matcher by using describedAs() to provide a better description for the expectation., (*12)

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

```, (*13)

The Versions

15/03 2016

0.1

0.1.0.0

A set of custom Hamcrest matchers

  Sources   Download

MIT

The Requires

 

The Development Requires