TopGit tracks hamcrest/hamcrest-php on GitHub. The project has 7.0k stars. PHP Hamcrest implementation [Official]
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Hamcrest is a matching library originally written for Java, but
subsequently ported to many other languages. hamcrest-php is the
official PHP port of Hamcrest and essentially follows a literal
translation of the original Java API for Hamcrest, with a few
Exceptions, mostly down to PHP language barriers:
instanceOf($theClass) is actually anInstanceOf($theClass)
both(containsString('a'))->and(containsString('b'))
is actually both(containsString('a'))->andAlso(containsString('b'))
either(containsString('a'))->or(containsString('b'))
is actually either(containsString('a'))->orElse(containsString('b'))
Unless it would be non-semantic for a matcher to do so, hamcrest-php
allows dynamic typing for it's input, in "the PHP way". Exception are
where semantics surrounding the type itself would suggest otherwise,
such as stringContains() and greaterThan().
Several official matchers have not been ported because they don't
make sense or don't apply in PHP:
typeCompatibleWith($theClass)
eventFrom($source)
hasProperty($name) **
samePropertyValuesAs($obj) **
When most of the collections matchers are finally ported, PHP-specific
aliases will probably be created due to a difference in naming
conventions between Java's Arrays, Collections, Sets and Maps compared
with PHP's Arrays.
** [Unless we consider POPO's (Plain Old PHP Objects) akin to JavaBeans]
- The POPO thing is a joke. Java devs coin the term POJO's (Plain Old
Java Objects).
Alternatively, you can use the global proxy-functions:
$result = true;
// with an identifier
assertThat("result should be true", $result, equalTo(true));
// without an identifier
assertThat($result, equalTo(true));
// evaluate a boolean expression
assertThat($result === true);
// with syntactic sugar is()
assertThat(true, is(true));
[!NOTE]
To prevent tests from being marked as Risky (the This test did not perform any assertions message)
add this code to your test case tearDown method:
describedAs - Wraps an existing matcher and overrides the description when it fails.
$expected = "Dog";
$found = null;
// this assertion would result error message as Expected: is not null but: was null
//assertThat("Expected {$expected}, got {$found}", $found, is(notNullValue()));
// and this assertion would result error message as Expected: Dog but: was null
//assertThat($found, describedAs($expected, notNullValue()));
everyItem - A matcher to apply to every element in an array.
assertThat([2, 4, 6], everyItem(notNullValue()));
hasItem - check array has given item, it can take a matcher argument
assertThat([2, 4, 6], hasItem(equalTo(2)));
hasItems - check array has given items, it can take multiple matcher as arguments
class Foo {
public $name = null;
public function __toString() {
return "[Foo]Instance";
}
}
$foo = new Foo;
assertThat($foo, hasToString(equalTo("[Foo]Instance")));
equalTo - compares two instances using comparison operator '=='
$foo = new Foo;
$foo2 = new Foo;
assertThat($foo, equalTo($foo2));
identicalTo - compares two instances using identity operator '==='
assertThat($foo, is(not(identicalTo($foo2))));
anInstanceOf - check instance is an instance|sub-class of given class
How active is development on hamcrest/hamcrest-php?
The most recent commit recorded on hamcrest/hamcrest-php was 2 months ago, based on the GitHub push timestamp. The repository has 47 forks — one of the better signals of community interest.
How many stars does hamcrest/hamcrest-php have?
hamcrest/hamcrest-php has 7.0k GitHub stars — refresh the page for the live number, or check github.com/hamcrest/hamcrest-php. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is hamcrest/hamcrest-php open source?
TopGit's metadata for hamcrest/hamcrest-php does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
What is hamcrest/hamcrest-php?
hamcrest/hamcrest-php (hamcrest/hamcrest-php) is a PHP project on GitHub. From the project's own README: PHP Hamcrest implementation [Official]
Where do I read more about hamcrest/hamcrest-php?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/hamcrest/hamcrest-php is the definitive source.
Read full README in the tab above.
Curious whether hamcrest-php is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about hamcrest-php.