PHPackages                             jameshalsall/phpspec-array-contains-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. jameshalsall/phpspec-array-contains-matchers

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

jameshalsall/phpspec-array-contains-matchers
============================================

Provides additional contains matchers for PHPSpec

2.0.0(7y ago)898[1 issues](https://github.com/jameshalsall/phpspec-array-contains-matchers/issues)MITPHPPHP &gt;=7.1

Since Aug 26Pushed 7y ago1 watchersCompare

[ Source](https://github.com/jameshalsall/phpspec-array-contains-matchers)[ Packagist](https://packagist.org/packages/jameshalsall/phpspec-array-contains-matchers)[ RSS](/packages/jameshalsall-phpspec-array-contains-matchers/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (4)Used By (0)

PHPSpec Array Contains Matchers
===============================

[](#phpspec-array-contains-matchers)

[![Build Status](https://camo.githubusercontent.com/50a445cd5ebdb941c06981ecbe463519c62879a654ae83fd8828b28dae998e15/68747470733a2f2f7472617669732d63692e6f72672f6a616d657368616c73616c6c2f706870737065632d61727261792d636f6e7461696e732d6d617463686572732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jameshalsall/phpspec-array-contains-matchers)

Provides additional contains matchers for arrays in PHPSpec

Requirements
------------

[](#requirements)

The extensions has been built for PHPSpec 3.x and PHP 5.6 or later.

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

[](#installation)

Install the extension via composer:

```
$ composer require jameshalsall/phpspec-array-contains-matchers

```

You can then add the extension to your `phpspec.yml` as follows:

```
extensions:
  JamesHalsall\PhpSpecContainsMatchers\Extension: ~
```

Usage
-----

[](#usage)

The extension currently supports the following matchers:

- `containOnly`
- `containAnyOf`
- `containAllOf`

`containOnly` matcher
---------------------

[](#containonly-matcher)

The `containOnly` matcher is used when you want to ensure that an array value contains *only* the specified arguments. It was implemented to save you writing multiple calls to `shouldContain()`.

Consider that `->getArray()` returns `[1, 2, 3]`, the following code in your spec would pass:

```
$this->getArray()->shouldContainOnly(1, 2, 3);
```

If any anything else was in the array would it would cause the spec to fail.

Similarly this can be negated with `shouldNotContainOnly`. Staying with the same example above, the following code would fail because there aren't any additional values in the array:

```
$this->getArray()->shouldNotContainOnly(1, 2, 3);

```

However if `->getArray()` was to return `[1, 2, 3, 4]` then the above spec would pass.

`containAnyOf` matcher
----------------------

[](#containanyof-matcher)

The `containAnyOf` matcher is used when you want to ensure that an array contains **at least one** of the specified arguments.

Consider that `->getArray()` returns `[1, 2, 3]` as above, the following assertion would hold true:

```
$this->getArray()->shouldContainAnyOf(3, 4, 5);
```

However the following example would not:

```
$this->getArray()->shouldContainAnyOf(5, 6);

```

Similarly this can be negated with `shouldNotContainAnyOf`. Staying with the sample example, the following code would fail:

```
$this->getArray()->shouldNotContainAnyOf(3, 7);
```

This is because it contains the value 3, which is one of the values we have said it should *not* contain.

`containAllOf` matcher
----------------------

[](#containallof-matcher)

The `containAllOf` matcher will evaluate to true when the array contains all of the elements passed to the matcher.

If `->getArray()` returns `[1, 2, 3]` then the following assertion would hold true:

```
$this->getArray()->shouldContainAllOf(2, 3);
```

However the following example would not:

```
$this->getArray()->shouldContainAllOf(2, 3, 4);
```

Similarly this can be negated with `shouldNotContainAnyOf`. Staying with the same example, the following code would fail:

```
$this->getArray()->shouldNotContainAllOf(2, 3)
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~460 days

Total

3

Last Release

2675d ago

Major Versions

1.1.0 → 2.0.02019-03-04

PHP version history (2 changes)1.0.0PHP &gt;=5.6

2.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/463807?v=4)[jaitsu](/maintainers/jaitsu)[@Jaitsu](https://github.com/Jaitsu)

---

Top Contributors

[![jameshalsall](https://avatars.githubusercontent.com/u/499932?v=4)](https://github.com/jameshalsall "jameshalsall (3 commits)")

---

Tags

matcherphpspecphpspec-array

###  Code Quality

TestsBehat

### Embed Badge

![Health badge](/badges/jameshalsall-phpspec-array-contains-matchers/health.svg)

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

###  Alternatives

[bossa/phpspec2-expect

Helper that decorates any SUS with a phpspec lazy object wrapper

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

Test your Laravel applications with PhpSpec

144350.6k15](/packages/benconstable-phpspec-laravel)[phpspec/nyan-formatters

PHPSpec Nyan Formatter Extension

77240.3k23](/packages/phpspec-nyan-formatters)[friends-of-phpspec/phpspec-code-coverage

Generate Code Coverage reports for PhpSpec tests

202.6M129](/packages/friends-of-phpspec-phpspec-code-coverage)[akeneo/phpspec-skip-example-extension

Skip your PhpSpec examples through annotations

33986.7k11](/packages/akeneo-phpspec-skip-example-extension)[ciaranmcnulty/phpspec-typehintedmethods

Extension for phpspec to enhance generated methods

3089.7k31](/packages/ciaranmcnulty-phpspec-typehintedmethods)

PHPackages © 2026

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