PHPackages                             jpkleemans/phpunit-expect - 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. jpkleemans/phpunit-expect

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

jpkleemans/phpunit-expect
=========================

BDD-style assertions for PHPUnit

0.2.1(10y ago)137492MITPHP

Since Feb 6Pushed 7y ago2 watchersCompare

[ Source](https://github.com/jpkleemans/phpunit-expect)[ Packagist](https://packagist.org/packages/jpkleemans/phpunit-expect)[ Docs](https://github.com/jpkleemans/phpunit-expect)[ RSS](/packages/jpkleemans-phpunit-expect/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

PHPUnit Expect
==============

[](#phpunit-expect)

BDD-style assertions for PHPUnit

Usage
-----

[](#usage)

```
$number = 10;

// Simple expectation
expect($number)->toBe(10);

// Negative expectation
expect($number)->notToBeOfType('string');

// Chained expectations
expect($number)
    ->toBeOfType('int')
    ->toBeGreaterThan(5)
    ->toBeLessThan(20);
```

Install
-------

[](#install)

With Composer:

```
composer require jpkleemans/phpunit-expect --dev
```

Or if you've installed PHPUnit globally:

```
composer global require jpkleemans/phpunit-expect
```

Expectations
------------

[](#expectations)

### toBe

[](#tobe)

Expect that two variables have the same type and value. Used on objects, it asserts that two variables reference the same object.

### notToBe

[](#nottobe)

Expect that two variables do not have the same type and value. Used on objects, it asserts that two variables do not reference the same object.

### toEqual

[](#toequal)

Expect that two variables are equal.

### notToEqual

[](#nottoequal)

Expect that two variables are not equal.

### toHaveKey

[](#tohavekey)

Expect that an array has a specified key.

### notToHaveKey

[](#nottohavekey)

Expect that an array does not have a specified key.

### toHaveSubset

[](#tohavesubset)

Expect that an array has a specified subset.

### toContain

[](#tocontain)

Expect that a haystack contains a needle.

### notToContain

[](#nottocontain)

Expect that a haystack does not contain a needle.

### toContainOnly

[](#tocontainonly)

Expect that a haystack contains only values of a given type.

### notToContainOnly

[](#nottocontainonly)

Expect that a haystack does not contain only values of a given type.

### toContainOnlyInstancesOf

[](#tocontainonlyinstancesof)

Expect that a haystack contains only instances of a given classname

### toHaveCount

[](#tohavecount)

Expect the number of elements of an array, Countable or Traversable.

### notToHaveCount

[](#nottohavecount)

Expect the number of elements of an array, Countable or Traversable.

### toBeEmpty

[](#tobeempty)

Expect that a variable is empty.

### notToBeEmpty

[](#nottobeempty)

Expect that a variable is not empty.

### toBeGreaterThan

[](#tobegreaterthan)

Expect that a value is greater than another value.

### toBeGreaterThanOrEqualTo

[](#tobegreaterthanorequalto)

Expect that a value is greater than or equal to another value.

### toBeLessThan

[](#tobelessthan)

Expect that a value is smaller than another value.

### toBeLessThanOrEqualTo

[](#tobelessthanorequalto)

Expect that a value is smaller than or equal to another value.

### toEqualFile

[](#toequalfile)

Expect that the contents of one file or a string is equal to the contents of another file.

### notToEqualFile

[](#nottoequalfile)

Expect that the contents of one file or a string is not equal to the contents of another file.

### toExist

[](#toexist)

Expect that a file exists.

### notToExist

[](#nottoexist)

Expect that a file does not exist.

### toBeTrue

[](#tobetrue)

Expect that a condition is true.

### notToBeTrue

[](#nottobetrue)

Expect that a condition is not true.

### toBeFalse

[](#tobefalse)

Expect that a condition is false.

### notToBeFalse

[](#nottobefalse)

Expect that a condition is not false.

### toBeNull

[](#tobenull)

Expect that a variable is null.

### notToBeNull

[](#nottobenull)

Expect that a variable is not null.

### toBeFinite

[](#tobefinite)

Expect that a variable is finite.

### toBeInfinite

[](#tobeinfinite)

Expect that a variable is infinite.

### toBeNan

[](#tobenan)

Expect that a variable is nan.

### toHaveAttribute

[](#tohaveattribute)

Expect that a class or an object has a specified attribute.

### notToHaveAttribute

[](#nottohaveattribute)

Expect that a class or an object does not have a specified attribute.

### toHaveStaticAttribute

[](#tohavestaticattribute)

Expect that a class has a specified static attribute.

### notToHaveStaticAttribute

[](#nottohavestaticattribute)

Expect that a class does not have a specified static attribute.

### toBeInstanceOf

[](#tobeinstanceof)

Expect that a variable is of a given type.

### notToBeInstanceOf

[](#nottobeinstanceof)

Expect that a variable is not of a given type.

### toBeOfType

[](#tobeoftype)

Expect that a variable is of a given type.

### notToBeOfType

[](#nottobeoftype)

Expect that a variable is not of a given type.

### toMatchRegExp

[](#tomatchregexp)

Expect that a string matches a given regular expression.

### notToMatchRegExp

[](#nottomatchregexp)

Expect that a string does not match a given regular expression.

### toHaveSameSizeAs

[](#tohavesamesizeas)

Assert that the size of two arrays (or `Countable` or `Traversable` objects) is the same.

### notToHaveSameSizeAs

[](#nottohavesamesizeas)

Assert that the size of two arrays (or `Countable` or `Traversable` objects) is not the same.

### toMatchFormat

[](#tomatchformat)

Expect that a string matches a given format string.

### notToMatchFormat

[](#nottomatchformat)

Expect that a string does not match a given format string.

### toMatchFormatFile

[](#tomatchformatfile)

Expect that a string matches a given format file.

### notToMatchFormatFile

[](#nottomatchformatfile)

Expect that a string does not match a given format string.

### toStartWith

[](#tostartwith)

Expect that a string starts with a given prefix.

### notToStartWith

[](#nottostartwith)

Expect that a string starts not with a given prefix.

### toEndWith

[](#toendwith)

Expect that a string ends with a given suffix.

### notToEndWith

[](#nottoendwith)

Expect that a string ends not with a given suffix.

### toEqualXmlFile

[](#toequalxmlfile)

Expect that two XML files or documents are equal.

### notToEqualXmlFile

[](#nottoequalxmlfile)

Expect that two XML files or documents are not equal.

### toEqualXml

[](#toequalxml)

Expect that two XML documents are equal.

### notToEqualXml

[](#nottoequalxml)

Expect that two XML documents are not equal.

### toHaveSameXMLStructureAs

[](#tohavesamexmlstructureas)

Expect that a hierarchy of DOMElements matches.

### toBeJson

[](#tobejson)

Expect that a string is a valid JSON string.

### toEqualJson

[](#toequaljson)

Expect that two given JSON encoded objects or arrays are equal.

### notToEqualJson

[](#nottoequaljson)

Expect that two given JSON encoded objects or arrays are not equal.

### toEqualJsonFile

[](#toequaljsonfile)

Expect that the generated JSON encoded object and the content of the given file or JSON string are equal.

### notToEqualJsonFile

[](#nottoequaljsonfile)

Expect that the generated JSON encoded object and the content of the given file or JSON string are not equal.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.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 ~4 days

Total

4

Last Release

3786d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5700014?v=4)[Jan-Paul Kleemans](/maintainers/jpkleemans)[@jpkleemans](https://github.com/jpkleemans)

---

Top Contributors

[![jpkleemans](https://avatars.githubusercontent.com/u/5700014?v=4)](https://github.com/jpkleemans "jpkleemans (24 commits)")[![kierenevans](https://avatars.githubusercontent.com/u/1554709?v=4)](https://github.com/kierenevans "kierenevans (2 commits)")[![technodelight](https://avatars.githubusercontent.com/u/1817035?v=4)](https://github.com/technodelight "technodelight (1 commits)")

---

Tags

bddexpectphpunit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jpkleemans-phpunit-expect/health.svg)

```
[![Health](https://phpackages.com/badges/jpkleemans-phpunit-expect/health.svg)](https://phpackages.com/packages/jpkleemans-phpunit-expect)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M352](/packages/dms-phpunit-arraysubset-asserts)[phpbenchmark/phpbenchmark

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

8011.5k2](/packages/phpbenchmark-phpbenchmark)

PHPackages © 2026

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