PHPackages                             rest-certain/hamcrest-phpunit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. rest-certain/hamcrest-phpunit

ActiveLibrary[Testing &amp; Quality](/categories/testing)

rest-certain/hamcrest-phpunit
=============================

Hamcrest matchers that work natively with PHPUnit

0.2.0(1y ago)1170[2 PRs](https://github.com/rest-certain/hamcrest-phpunit/pulls)1LGPL-3.0-or-laterPHPPHP ~8.3.0 || ~8.4.0CI passing

Since May 6Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/rest-certain/hamcrest-phpunit)[ Packagist](https://packagist.org/packages/rest-certain/hamcrest-phpunit)[ RSS](/packages/rest-certain-hamcrest-phpunit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (14)Versions (5)Used By (1)

rest-certain/hamcrest-phpunit
=============================

[](#rest-certainhamcrest-phpunit)

 **Hamcrest matchers that work natively with PHPUnit**

 [![Source Code](https://camo.githubusercontent.com/7861a610d88a70c2f086d3dac539cf1aca1c9a001aa8b43ea7d4732640658ddc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d726573742d2d6365727461696e2f68616d63726573742d2d706870756e69742d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/rest-certain/hamcrest-phpunit) [![Download Package](https://camo.githubusercontent.com/b3752603542f0c2159d18ca12a34df0761a554f50b55ab86c6a1734915cc9299/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726573742d6365727461696e2f68616d63726573742d706870756e69742e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/rest-certain/hamcrest-phpunit) [![PHP Programming Language](https://camo.githubusercontent.com/7c1d549642660a4d1ab15dc77d4fbd63607149f18ceb7bb1014c3968e9495963/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726573742d6365727461696e2f68616d63726573742d706870756e69742e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d253233383839324246)](https://php.net) [![Read License](https://camo.githubusercontent.com/fde4c2a48b7d93b2f3d0a6fc0e2ad1b3985744a54f7f7a6b8bc8a2e7ebbf2f0d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726573742d6365727461696e2f68616d63726573742d706870756e69742e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6461726b6379616e)](https://github.com/rest-certain/hamcrest-phpunit/blob/main/NOTICE) [![Build Status](https://camo.githubusercontent.com/75879ba990f608661226fbef3b1d8a099cb2970583df41185fb60617538bfb16/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726573742d6365727461696e2f68616d63726573742d706870756e69742f636f6e74696e756f75732d696e746567726174696f6e2e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/rest-certain/hamcrest-phpunit/actions/workflows/continuous-integration.yml) [![Codecov Code Coverage](https://camo.githubusercontent.com/559cdfd66b908b2312e20445ed1721623714b2877ccffc44cf2c5ed2d2192cbe/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f67682f726573742d6365727461696e2f68616d63726573742d706870756e69743f6c6162656c3d636f6465636f76266c6f676f3d636f6465636f76267374796c653d666c61742d737175617265)](https://codecov.io/gh/rest-certain/hamcrest-phpunit)

About
-----

[](#about)

This library provides [Hamcrest](https://hamcrest.org) matchers that return [PHPUnit](https://phpunit.de) `Constraint` instances, allowing the matchers to be used anywhere a PHPUnit constraint is allowed.

This is not an official Hamcrest project and has no affiliation with [hamcrest.org](https://hamcrest.org). The *matchers* this library provides are not true Hamcrest matchers in that they do not return Hamcrest `Matcher` instances, as [defined by the Hamcrest project](https://hamcrest.org/JavaHamcrest/tutorial#writing-custom-matchers). Instead, the functions in this library return `Constraint` instances, for use with PHPUnit.

This project adheres to a [code of conduct](CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code.

Tip

Check out the **official** PHP port of Hamcrest Matchers: [hamcrest/hamcrest-php](https://packagist.org/packages/hamcrest/hamcrest-php)!

Installation
------------

[](#installation)

Install this package as a development dependency using [Composer](https://getcomposer.org).

```
composer require --dev rest-certain/hamcrest-phpunit
```

Usage
-----

[](#usage)

This library provides all Hamcrest matchers as static methods on the `RestCertain\Hamcrest\Matchers` class and also as functions in the `RestCertain\Hamcrest` namespace. These methods and functions may be used within the context of PHPUnit tests.

```
use PHPUnit\Framework\TestCase;

use function RestCertain\Hamcrest\assertThat;
use function RestCertain\Hamcrest\both;
use function RestCertain\Hamcrest\containsStringIgnoringCase;
use function RestCertain\Hamcrest\isA;
use function RestCertain\Hamcrest\startsWithIgnoringCase;

class ExampleTest extends TestCase
{
    public function testExample(): void
    {
        assertThat(
            'The quick brown fox jumps over the lazy dog',
            both(isA('string'))
                ->and(startsWithIgnoringCase('the'))
                ->and(containsStringIgnoringCase('FOX')),
        );
    }
}
```

Contributing
------------

[](#contributing)

Contributions are welcome! To contribute, please familiarize yourself with [CONTRIBUTING.md](CONTRIBUTING.md).

Coordinated Disclosure
----------------------

[](#coordinated-disclosure)

Keeping user information safe and secure is a top priority, and we welcome the contribution of external security researchers. If you believe you've found a security issue in software that is maintained in this repository, please read [SECURITY.md](SECURITY.md) for instructions on submitting a vulnerability report.

Copyright and License
---------------------

[](#copyright-and-license)

rest-certain/hamcrest-phpunit is copyright © [REST Certain Contributors](https://rest-certain.dev)and licensed for use under the terms of the GNU Lesser General Public License (LGPL-3.0-or-later) as published by the Free Software Foundation. Please see [COPYING.LESSER](COPYING.LESSER), [COPYING](COPYING), and [NOTICE](NOTICE) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance66

Regular maintenance activity

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

2

Last Release

374d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f514481fa9cfdfd5dbcaccb3e5b480f18ea05ebf331cddf9b1c5a2a96a78fef5?d=identicon)[ramsey](/maintainers/ramsey)

---

Top Contributors

[![ramsey](https://avatars.githubusercontent.com/u/42941?v=4)](https://github.com/ramsey "ramsey (12 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

hamcresthamcrest-matchersphpphpunittestingphptestingphpunithamcrest

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rest-certain-hamcrest-phpunit/health.svg)

```
[![Health](https://phpackages.com/badges/rest-certain-hamcrest-phpunit/health.svg)](https://phpackages.com/packages/rest-certain-hamcrest-phpunit)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[blastcloud/guzzler

Supercharge your app or SDK with a testing library specifically for Guzzle.

272419.3k35](/packages/blastcloud-guzzler)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)[juampi92/test-seo

Easy way to test your SEO

26341.0k](/packages/juampi92-test-seo)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
