PHPackages                             karriere/phpspec-matchers - 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. karriere/phpspec-matchers

AbandonedArchivedPhpspec-extension[Testing &amp; Quality](/categories/testing)

karriere/phpspec-matchers
=========================

phpspec extension with a collection of additional matchers

v3.0.0(6y ago)3151.0k↑425%5[1 issues](https://github.com/karriereat/phpspec-matchers/issues)4Apache-2.0PHPPHP &gt;=7.1

Since Feb 7Pushed 6y ago12 watchersCompare

[ Source](https://github.com/karriereat/phpspec-matchers)[ Packagist](https://packagist.org/packages/karriere/phpspec-matchers)[ Docs](https://github.com/karriereat/phpspec-matchers)[ RSS](/packages/karriere-phpspec-matchers/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (4)

[![](https://camo.githubusercontent.com/b3def76d7951161a348c294046488dbdd16ee2729d7f9fca35774af3c1b57fec/687474703a2f2f7777772e6b617272696572652e61742f696d616765732f6c61796f75742f6b61746c6f676f2e737667)](https://www.karriere.at/) [![Build Status](https://camo.githubusercontent.com/75290c1c10cbc87767e3ce4be96023d1d907a937836832f5bff0ea88a506a5ed/68747470733a2f2f7472617669732d63692e6f72672f6b6172726965726561742f706870737065632d6d617463686572732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/karriereat/phpspec-matchers)[![codecov](https://camo.githubusercontent.com/ab7bc405a5d4da938307f9569615f87966ccba34cfbbffd234705c60bf8ff59b/68747470733a2f2f636f6465636f762e696f2f67682f6b6172726965726561742f706870737065632d6d617463686572732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/karriereat/phpspec-matchers)[![StyleCI](https://camo.githubusercontent.com/5955510ce9a231ac1823da2bee27f155b4270a236867dd4ee5e1606aa9bd3beb/68747470733a2f2f7374796c6563692e696f2f7265706f732f38313132313033392f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/81121039)

Collection of phpspec Matchers
==============================

[](#collection-of-phpspec-matchers)

This package contains a collection of additional phpspec matchers.

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

[](#installation)

You can install the package via composer

```
composer require karriere/phpspec-matchers

```

To be able to use the matchers you need to add the following definition to your `phpspec.yml`

```
extensions:
    Karriere\PhpSpecMatchers\Extension: ~
```

Matcher Usage
-------------

[](#matcher-usage)

All custom matchers in this package implement the positive and the negative case. For example you can use:

```
$this->method()->shouldBeAnyOf(1, 2, 3);
```

and also

```
$this->method()->shouldNotBeAnyOf(1, 2, 3);
```

Matchers
--------

[](#matchers)

**General Matchers**

- [beAnyOf](#beanyof)
- [beSomeOf](#besomeof)
- [rangeBetween](#rangebetween)
- [beEmpty](#beempty)
- [beNull](#benull)
- [beLessThan](#belessthan)
- [beGreaterThan](#begreaterthan)

**Json Matchers**

- [beJson](#bejson)
- [haveJsonKey](#havejsonkey)
- [haveJsonKeyWithValue](#havejsonkeywithvalue)

### General Matchers

[](#general-matchers)

#### beAnyOf

[](#beanyof)

This matcher allows to check the return value against a set of values. Assume you have some sort of random mechanism to get an integer between 2 and 4. The you can use the `shouldBeAnyOf` matcher:

```
$this->method()->shouldBeAnyOf(2, 3, 4);
```

#### beSomeOf

[](#besomeof)

This matcher allows to check if the returned array values are contained in a set of values.

```
// $this->method() may return [1, 2, 3]
$this->method()->shouldBeSomeOf(1, 2, 3, 4, 5);
```

#### rangeBetween

[](#rangebetween)

This matcher allows to check if the given return value is inside a numeric range.

```
$this->method()->shouldRangeBetween(2, 4);
$this->method()->shouldRangeBetween(0.1, 0.9);
```

#### beEmpty

[](#beempty)

This matcher allows to check if the given return value is empty. The implementation uses the [empty](http://php.net/manual/en/function.empty.php) implementation.

```
$this->method()->shouldBeEmpty();
```

#### beNull

[](#benull)

This matcher allows to check if the given return value is null. The implementation uses the [is\_null](http://php.net/manual/en/function.is-null.php) implementation.

```
$this->method()->shouldBeNull();
```

#### beLessThan

[](#belessthan)

This matcher allows to check if the given return value is less than a specified value.

```
$this->method()->shouldBeLessThan(10);
```

#### beGreaterThan

[](#begreaterthan)

This matcher allows to check if the given return value is greater than a specified value.

```
$this->method()->shouldBeGreaterThan(10);
```

### Json Matchers

[](#json-matchers)

#### beJson

[](#bejson)

This matcher checks if the return value is a valid json string

```
$this->method()->shouldBeJson();
```

#### haveJsonKey

[](#havejsonkey)

This matcher checks if the returned json string contains a json key.

```
$this->method()->shouldHaveJsonKey('key');
```

To match against subkey you can use the dot notation. For example let's assume the following json structure

```
{
  "key": {
    "subkey": "value"
  }
}
```

The key for this check is 'key.subkey'

```
$this->method()->shouldHaveJsonKey('key.subkey');
```

#### haveJsonKeyWithValue

[](#havejsonkeywithvalue)

This matcher checks if the returned json string contains the json key and the desired value. The dot syntax for subkeys can also be applied.

```
$this->method()->shouldHaveJsonKeyWithValue('key.subkey', 'value');
```

License
-------

[](#license)

Apache License 2.0 Please see [LICENSE](LICENSE) for more information.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 96.9% 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 ~253 days

Total

5

Last Release

2374d ago

Major Versions

v1.1.1 → v2.0.02017-12-15

v2.0.0 → v3.0.02019-11-18

PHP version history (3 changes)v1.0.0PHP &gt;=5.6

v2.0.0PHP &gt;=7.0

v3.0.0PHP &gt;=7.1

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/59ac000ca995a016e613c45c25d9b9c319853c5a783299aa5cc059f2c4477aab?d=identicon)[karriere-at-dev](/maintainers/karriere-at-dev)

---

Top Contributors

[![fetzi](https://avatars.githubusercontent.com/u/3509426?v=4)](https://github.com/fetzi "fetzi (31 commits)")[![jaylinski](https://avatars.githubusercontent.com/u/1668766?v=4)](https://github.com/jaylinski "jaylinski (1 commits)")

---

Tags

bddphpspecphpspec-matcherstddtdd-utilitiestestingjsonTDDphpspecmatchers

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/karriere-phpspec-matchers/health.svg)

```
[![Health](https://phpackages.com/badges/karriere-phpspec-matchers/health.svg)](https://phpackages.com/packages/karriere-phpspec-matchers)
```

###  Alternatives

[lchrusciel/api-test-case

Perfect PHPUnit TestCase for JSON/XML API TDD with Symfony.

4115.5M63](/packages/lchrusciel-api-test-case)[bossa/phpspec2-expect

Helper that decorates any SUS with a phpspec lazy object wrapper

741.8M87](/packages/bossa-phpspec2-expect)[benconstable/phpspec-laravel

Test your Laravel applications with PhpSpec

144347.1k15](/packages/benconstable-phpspec-laravel)[ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

3089.3k31](/packages/ciaranmcnulty-phpspec-typehintedmethods)[phpspec/nyan-formatters

PHPSpec Nyan Formatter Extension

77239.9k22](/packages/phpspec-nyan-formatters)[friends-of-phpspec/phpspec-code-coverage

Generate Code Coverage reports for PhpSpec tests

202.6M125](/packages/friends-of-phpspec-phpspec-code-coverage)

PHPackages © 2026

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