7.0k sao GitHub và vẫn tăng — hamcrest/hamcrest-php là dự án PHP mà TopGit đang theo dõi trên nền tảng. PHP Hamcrest implementation [Official]
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/hamcrest/hamcrest-php là nguồn chính thức.
hamcrest/hamcrest-php có bao nhiêu sao?
hamcrest/hamcrest-php có 7.0k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/hamcrest/hamcrest-php. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
hamcrest/hamcrest-php có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho hamcrest/hamcrest-php. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
hamcrest/hamcrest-php còn đang phát triển không?
Commit gần nhất trên hamcrest/hamcrest-php là 2 tháng trước (theo timestamp GitHub). Repo có 47 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
hamcrest/hamcrest-php là gì?
hamcrest/hamcrest-php (hamcrest/hamcrest-php) là dự án PHP trên GitHub. Theo mô tả gốc: PHP Hamcrest implementation [Official]
Đọc đầy đủ README ở tab phía trên.
Chưa chắc hamcrest-php có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về hamcrest-php.