{"id":13828103,"url":"https://github.com/hamcrest/hamcrest-php","last_synced_at":"2025-09-09T20:42:56.627Z","repository":{"id":12866737,"uuid":"15543026","full_name":"hamcrest/hamcrest-php","owner":"hamcrest","description":"PHP Hamcrest implementation [Official]","archived":false,"fork":false,"pushed_at":"2025-08-03T12:52:31.000Z","size":432,"stargazers_count":6990,"open_issues_count":15,"forks_count":46,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-09-05T09:51:12.357Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hamcrest.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-12-31T04:35:35.000Z","updated_at":"2025-09-04T02:16:44.000Z","dependencies_parsed_at":"2024-06-18T10:38:03.966Z","dependency_job_id":"ab289f74-0841-481f-9148-d50fcce4d09e","html_url":"https://github.com/hamcrest/hamcrest-php","commit_stats":{"total_commits":102,"total_committers":26,"mean_commits":3.923076923076923,"dds":0.7941176470588236,"last_synced_commit":"ea3c21ca78e9696dbd7d8f16e1141ca7be241e6a"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/hamcrest/hamcrest-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamcrest%2Fhamcrest-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamcrest%2Fhamcrest-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamcrest%2Fhamcrest-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamcrest%2Fhamcrest-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hamcrest","download_url":"https://codeload.github.com/hamcrest/hamcrest-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamcrest%2Fhamcrest-php/sbom","scorecard":{"id":453767,"data":{"date":"2025-08-11","repo":{"name":"github.com/hamcrest/hamcrest-php","commit":"410bee0090283e0a05fa53345ff9dc53365774aa"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.2,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":7,"reason":"Found 14/20 approved changesets -- score normalized to 7","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":10,"reason":"13 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 25 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T08:58:18.352Z","repository_id":12866737,"created_at":"2025-08-19T08:58:18.352Z","updated_at":"2025-08-19T08:58:18.352Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274358736,"owners_count":25270681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T09:02:32.431Z","updated_at":"2025-09-09T20:42:56.617Z","avatar_url":"https://github.com/hamcrest.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"This is the PHP port of Hamcrest Matchers\n=========================================\n\n[![tests](https://github.com/hamcrest/hamcrest-php/actions/workflows/ci.yml/badge.svg)](https://github.com/hamcrest/hamcrest-php/actions/workflows/ci.yml)\n\nHamcrest is a matching library originally written for Java, but\nsubsequently ported to many other languages.  hamcrest-php is the\nofficial PHP port of Hamcrest and essentially follows a literal\ntranslation of the original Java API for Hamcrest, with a few\nExceptions, mostly down to PHP language barriers:\n\n  1. `instanceOf($theClass)` is actually `anInstanceOf($theClass)`\n\n  2. `both(containsString('a'))-\u003eand(containsString('b'))`\n     is actually `both(containsString('a'))-\u003eandAlso(containsString('b'))`\n\n  3. `either(containsString('a'))-\u003eor(containsString('b'))`\n     is actually `either(containsString('a'))-\u003eorElse(containsString('b'))`\n\n  4. Unless it would be non-semantic for a matcher to do so, hamcrest-php\n     allows dynamic typing for it's input, in \"the PHP way\". Exception are\n     where semantics surrounding the type itself would suggest otherwise,\n     such as stringContains() and greaterThan().\n\n  5. Several official matchers have not been ported because they don't\n     make sense or don't apply in PHP:\n\n       - `typeCompatibleWith($theClass)`\n       - `eventFrom($source)`\n       - `hasProperty($name)` **\n       - `samePropertyValuesAs($obj)` **\n\n  6. When most of the collections matchers are finally ported, PHP-specific\n     aliases will probably be created due to a difference in naming\n     conventions between Java's Arrays, Collections, Sets and Maps compared\n     with PHP's Arrays.\n\n---\n** [Unless we consider POPO's (Plain Old PHP Objects) akin to JavaBeans]\n     - The POPO thing is a joke.  Java devs coin the term POJO's (Plain Old\n       Java Objects).\n\n\nUsage\n-----\n\nHamcrest matchers are easy to use as:\n\n```php\n\\Hamcrest\\MatcherAssert::assertThat('a', \\Hamcrest\\Matchers::equalToIgnoringCase('A'));\n```\n\nAlternatively, you can use the global proxy-functions:\n\n```php\n$result = true;\n// with an identifier\nassertThat(\"result should be true\", $result, equalTo(true));\n\n// without an identifier\nassertThat($result, equalTo(true));\n\n// evaluate a boolean expression\nassertThat($result === true);\n\n// with syntactic sugar is()\nassertThat(true, is(true));\n```\n\n\u003e [!NOTE]\n\u003e To prevent tests from being marked as Risky (the `This test did not perform any assertions` message)\n\u003e add this code to your test case `tearDown` method:\n\u003e\n\u003e ```php\n\u003e $this-\u003eaddToAssertionCount(\\Hamcrest\\MatcherAssert::getCount());\n\u003e \\Hamcrest\\MatcherAssert::resetCount();\n\u003e ```\n\n\u003e [!WARNING]\n\u003e the global proxy-functions aren't autoloaded by default, so you will need to load them first:\n\u003e\n\u003e ```php\n\u003e \\Hamcrest\\Util::registerGlobalFunctions();\n\u003e ```\n\nFor brevity, all of the examples below use the proxy-functions.\n\n\nDocumentation\n-------------\nA tutorial can be found on the [Hamcrest site](https://code.google.com/archive/p/hamcrest/wikis/TutorialPHP.wiki).\n\n\nAvailable Matchers\n------------------\n* [Array](../master/README.md#array)\n* [Collection](../master/README.md#collection)\n* [Object](../master/README.md#object)\n* [Numbers](../master/README.md#numbers)\n* [Type checking](../master/README.md#type-checking)\n* [XML](../master/README.md#xml)\n\n\n### Array\n\n* `anArray` - evaluates an array\n```php\nassertThat([], anArray());\n```\n\n* `hasItemInArray` - check if item exists in array\n```php\n$list = range(2, 7, 2);\n$item = 4;\nassertThat($list, hasItemInArray($item));\n```\n\n* `hasValue` - alias of hasItemInArray\n\n* `arrayContainingInAnyOrder` - check if array contains elements in any order\n```php\nassertThat([2, 4, 6], arrayContainingInAnyOrder([6, 4, 2]));\nassertThat([2, 4, 6], arrayContainingInAnyOrder([4, 2, 6]));\n```\n\n* `containsInAnyOrder` - alias of arrayContainingInAnyOrder\n\n* `arrayContaining` - An array with elements that match the given matchers in the same order.\n```php\nassertThat([2, 4, 6], arrayContaining([2, 4, 6]));\nassertthat([2, 4, 6], not(arrayContaining([6, 4, 2])));\n```\n\n* `contains` - check array in same order\n```php\nassertThat([2, 4, 6], contains([2, 4, 6]));\n```\n\n* `hasKeyInArray` - check if array has given key\n```php\nassertThat(['name'=\u003e 'foobar'], hasKeyInArray('name'));\n```\n\n* `hasKey` - alias of hasKeyInArray\n\n* `hasKeyValuePair` - check if array has given key, value pair\n```php\nassertThat(['name'=\u003e 'foobar'], hasKeyValuePair('name', 'foobar'));\n```\n* `hasEntry` - same as hasKeyValuePair\n\n* `arrayWithSize` - check array has given size\n```php\nassertthat([2, 4, 6], arrayWithSize(3));\n```\n* `emptyArray` - check if array is empty\n```php\nassertThat([], emptyArray());\n```\n\n* `nonEmptyArray`\n```php\nassertThat([1], nonEmptyArray());\n```\n\n### Collection\n\n* `emptyTraversable` - check if traversable is empty\n```php\n$empty_it = new EmptyIterator;\nassertThat($empty_it, emptyTraversable());\n```\n\n* `nonEmptyTraversable` - check if traversable isn't empty\n```php\n$non_empty_it = new ArrayIterator(range(1, 10));\nassertThat($non_empty_it, nonEmptyTraversable());\na\n```\n\n* `traversableWithSize`\n```php\n$non_empty_it = new ArrayIterator(range(1, 10));\nassertThat($non_empty_it, traversableWithSize(count(range(1, 10))));\n`\n```\n\n### Core\n\n* `allOf` - Evaluates to true only if ALL of the passed in matchers evaluate to true.\n```php\nassertThat([2,4,6], allOf(hasValue(2), arrayWithSize(3)));\n```\n\n* `anyOf` - Evaluates to true if ANY of the passed in matchers evaluate to true.\n```php\nassertThat([2, 4, 6], anyOf(hasValue(8), hasValue(2)));\n```\n\n* `noneOf` - Evaluates to false if ANY of the passed in matchers evaluate to true.\n```php\nassertThat([2, 4, 6], noneOf(hasValue(1), hasValue(3)));\n```\n\n* `both` + `andAlso` - This is useful for fluently combining matchers that must both pass.\n```php\nassertThat([2, 4, 6], both(hasValue(2))-\u003eandAlso(hasValue(4)));\n```\n\n* `either` + `orElse` - This is useful for fluently combining matchers where either may pass,\n```php\nassertThat([2, 4, 6], either(hasValue(2))-\u003eorElse(hasValue(4)));\n```\n\n* `describedAs` - Wraps an existing matcher and overrides the description when it fails.\n```php \n$expected = \"Dog\";\n$found = null;\n// this assertion would result error message as Expected: is not null but: was null\n//assertThat(\"Expected {$expected}, got {$found}\", $found, is(notNullValue()));\n// and this assertion would result error message as Expected: Dog but: was null\n//assertThat($found, describedAs($expected, notNullValue()));\n```\n\n* `everyItem` - A matcher to apply to every element in an array.\n```php\nassertThat([2, 4, 6], everyItem(notNullValue()));\n```\n\n* `hasItem` - check array has given item, it can take a matcher argument\n```php\nassertThat([2, 4, 6], hasItem(equalTo(2)));\n```\n\n* `hasItems` - check array has given items, it can take multiple matcher as arguments\n```php\nassertThat([1, 3, 5], hasItems(equalTo(1), equalTo(3)));\n```\n\n### Object\n\n* `hasToString` - check `__toString` or `toString` method\n```php\nclass Foo {\n    public $name = null;\n\n    public function __toString() {\n        return \"[Foo]Instance\";\n    }\n}\n$foo = new Foo;\nassertThat($foo, hasToString(equalTo(\"[Foo]Instance\")));\n```\n\n* `equalTo` - compares two instances using comparison operator '=='\n```php\n$foo = new Foo;\n$foo2 = new Foo;\nassertThat($foo, equalTo($foo2));\n```\n\n* `identicalTo` - compares two instances using identity operator '==='\n```php\nassertThat($foo, is(not(identicalTo($foo2))));\n```\n\n* `anInstanceOf` - check instance is an instance|sub-class of given class\n```php\nassertThat($foo, anInstanceOf(Foo::class));\n```\n\n* `any` - alias of `anInstanceOf`\n\n* `nullValue` check null\n```php\nassertThat(null, is(nullValue()));\n```\n\n* `notNullValue` check not null\n```php\nassertThat(\"\", notNullValue());\n```\n\n* `sameInstance` - check for same instance\n```php\nassertThat($foo, is(not(sameInstance($foo2))));\nassertThat($foo, is(sameInstance($foo)));\n```\n\n* `typeOf`- check type\n```php \nassertThat(1, typeOf(\"integer\"));\n```\n\n* `notSet` - check if instance property is not set\n```php\nassertThat($foo, notSet(\"name\"));\n```\n\n* `set` - check if instance property is set\n```php\n$foo-\u003ename = \"bar\";\nassertThat($foo, set(\"name\"));\n```\n\n### Numbers\n\n* `closeTo` - check value close to a range\n```php\nassertThat(3, closeTo(3, 0.5));\n```\n\n* `comparesEqualTo` - check with '=='\n```php\nassertThat(2, comparesEqualTo(2));\n```\n\n* `greaterThan` - check '\u003e'\n```\nassertThat(2, greaterThan(1));\n```\n\n* `greaterThanOrEqualTo`\n```php\nassertThat(2, greaterThanOrEqualTo(2));\n```\n\n* `atLeast` - The value is \u003e= given value\n```php\nassertThat(3, atLeast(2));\n```\n* `lessThan`\n```php\nassertThat(2, lessThan(3));\n```\n\n* `lessThanOrEqualTo`\n```php\nassertThat(2, lessThanOrEqualTo(3));\n```\n\n* `atMost` - The value is \u003c= given value\n```php\nassertThat(2, atMost(3));\n```\n\n### String\n\n* `emptyString` - check for empty string\n```php\nassertThat(\"\", emptyString());\n```\n\n* `isEmptyOrNullString`\n```php\nassertThat(null, isEmptyOrNullString());\n```\n\n* `nullOrEmptyString`\n```php\nassertThat(\"\", nullOrEmptyString());\n```\n\n* `isNonEmptyString`\n```php\nassertThat(\"foo\", isNonEmptyString());\n```\n\n* `nonEmptyString`\n```php\nassertThat(\"foo\", nonEmptyString());\n```\n\n* `equalToIgnoringCase`\n```php\nassertThat(\"Foo\", equalToIgnoringCase(\"foo\"));\n```\n* `equalToIgnoringWhiteSpace`\n```php\nassertThat(\" Foo \", equalToIgnoringWhiteSpace(\"Foo\"));\n```\n\n* `matchesPattern` - matches with regex pattern\n```php\nassertThat(\"foobarbaz\", matchesPattern('/(foo)(bar)(baz)/'));\n```\n\n* `containsString` - check for substring\n```php\nassertThat(\"foobar\", containsString(\"foo\"));\n```\n\n* `containsStringIgnoringCase`\n```php\nassertThat(\"fooBar\", containsStringIgnoringCase(\"bar\"));\n```\n\n* `stringContainsInOrder`\n```php\nassertThat(\"foo\", stringContainsInOrder(\"foo\"));\n```\n\n* `endsWith` - check string that ends with given value\n```php\nassertThat(\"foo\", endsWith(\"oo\"));\n```\n\n* `startsWith` - check string that starts with given value\n```php\nassertThat(\"bar\", startsWith(\"ba\"));\n```\n\n### Type-checking\n\n* `arrayValue` - check array type\n```php\nassertThat([], arrayValue());\n```\n\n* `booleanValue`\n```php\nassertThat(true, booleanValue());\n```\n* `boolValue` - alias of booleanValue\n\n* `callableValue` - check if value is callable\n```php\n$func = function () {};\nassertThat($func, callableValue());\n```\n* `doubleValue`\n```php\nassertThat(3.14, doubleValue());\n```\n\n* `floatValue`\n```php\nassertThat(3.14, floatValue());\n```\n\n* `integerValue`\n```php\nassertThat(1, integerValue());\n```\n\n* `intValue` - alias of `integerValue`\n\n* `numericValue` - check if value is numeric\n```php\nassertThat(\"123\", numericValue());\n```\n\n* `objectValue` - check for object\n```php\n$obj = new stdClass;\nassertThat($obj, objectValue());\n```\n* `anObject`\n```php\nassertThat($obj, anObject());\n```\n\n* `resourceValue` - check resource type\n```php\n$fp = fopen(\"/tmp/foo\", \"w+\");\nassertThat($fp, resourceValue());\n```\n\n* `scalarValue` - check for scalar value\n```php\nassertThat(1, scalarValue());\n```\n\n* `stringValue`\n```php\nassertThat(\"\", stringValue());\n```\n\n### XML\n\n* `hasXPath` - check xml with a xpath\n```php\n$xml = \u003c\u003c\u003cXML\n\u003cbooks\u003e\n  \u003cbook\u003e\n    \u003cisbn\u003e1\u003c/isbn\u003e   \n  \u003c/book\u003e\n  \u003cbook\u003e\n    \u003cisbn\u003e2\u003c/isbn\u003e   \n  \u003c/book\u003e\n\u003c/books\u003e\nXML;\n\n$doc = new DOMDocument;\n$doc-\u003eloadXML($xml);\nassertThat($doc, hasXPath(\"book\", 2));\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamcrest%2Fhamcrest-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhamcrest%2Fhamcrest-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamcrest%2Fhamcrest-php/lists"}