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

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

expect/expect
=============

Expectation library for unit testing

2.0.0(9y ago)08.7k3MITPHPPHP &gt;=5.6.0

Since Mar 23Pushed 9y agoCompare

[ Source](https://github.com/expectation-php/expect)[ Packagist](https://packagist.org/packages/expect/expect)[ RSS](/packages/expect-expect/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (11)Versions (21)Used By (3)

Expect
======

[](#expect)

[![Build Status](https://camo.githubusercontent.com/f1d291e4597900154cc1b6e103d596df4c4e648f76db59c7daec6c888e585eba/68747470733a2f2f7472617669732d63692e6f72672f6578706563746174696f6e2d7068702f6578706563742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/expectation-php/expect)[![HHVM Status](https://camo.githubusercontent.com/58edb2a1ac0986750fcbc62aef122e0a7852fdcbedfdffc9bd0c17486982ed1f/687474703a2f2f6868766d2e683463632e64652f62616467652f6578706563742f6578706563742e737667)](http://hhvm.h4cc.de/package/expect/expect)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/648a0f42000bee45913695741faed05f38972e076e713e339b5ef4f88e30fb41/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6578706563746174696f6e2d7068702f6578706563742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/expectation-php/expect/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/0ea82b41673a38e7c5cde9ade87a8eebf8965df7697fa1b6783f4182aec701fa/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6578706563746174696f6e2d7068702f6578706563742f62616467652e737667)](https://coveralls.io/r/expectation-php/expect)[![Dependency Status](https://camo.githubusercontent.com/f7803f54d9d921927b89d40e603ba53556c99d60da082067e6bba3e7038573d6/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3535306636613864613463326437353237303030303130632f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/550f6a8da4c2d7527000010c)
[![Stories in Ready](https://camo.githubusercontent.com/1b209a345ac822d16b832e89bb3eea46a9b975bd0158b10953aa6892bf3a55bf/68747470733a2f2f62616467652e776166666c652e696f2f6578706563746174696f6e2d7068702f6578706563742e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/expectation-php/expect)[![Latest Stable Version](https://camo.githubusercontent.com/c6d095cc4112d4d182a4a84f3f606abe2e103e3335b9e8504a073ebb82bf0d14/68747470733a2f2f706f7365722e707567782e6f72672f6578706563742f6578706563742f762f737461626c652e737667)](https://packagist.org/packages/expect/expect)[![License](https://camo.githubusercontent.com/be203433653d8d53078d9c7667a1ff31562b9bf2ff10533926af42212743501b/68747470733a2f2f706f7365722e707567782e6f72672f6578706563742f6578706563742f6c6963656e73652e737667)](https://packagist.org/packages/expect/expect)

Basic usage
-----------

[](#basic-usage)

```
use expect\Expect;
use expect\configurator\FileConfigurator;

$configurator = new FileConfigurator(__DIR__ . '/.expect.toml');
Expect::configure($configurator);

Expect::that(true)->toEqual(true); //pass
Expect::that(false)->toEqual(true); //failed
```

Configuration file
------------------

[](#configuration-file)

You can specify the **matcher package** and a **reporter** to be used in the configuration file.
Configuration file in toml format, examples are as follows.

```
packages = [
  "\\expect\\fixture\\package\\CustomPackageRegistrar"
]

reporter = "\\expect\\reporter\\ExceptionReporter"
```

Learn detailed document
-----------------------

[](#learn-detailed-document)

- API Document -
- Matcher packages
    - [expect-filesystem](https://github.com/expectation-php/expect-filesystem)

Other recommended library
-------------------------

[](#other-recommended-library)

If you did not like this library, please try the following library.

- [Leo](http://peridot-php.github.io/leo/) - Assertions and matcher library, in peridot and affinity is good.
- [Assert](https://github.com/beberlei/assert) - Simple assertion library, Assertion api is easy to use with simple.

All of matcher
--------------

[](#all-of-matcher)

### toEqual

[](#toequal)

```
Expect::that(true)->toEqual(true); //pass
Expect::that(false)->toEqual(true); //failed
```

### toBeTrue

[](#tobetrue)

```
Expect::that(true)->toBeTrue(); //pass
Expect::that(false)->toBeTrue(); //failed
```

### toBeFalse

[](#tobefalse)

```
Expect::that(false)->toBeFalse(); //pass
Expect::that(true)->toBeFalse(); //failed
```

### toBeNull

[](#tobenull)

```
Expect::that(null)->toBeNull(); //pass
Expect::that(100)->toBeNull(); //failed
```

### toBeAnInstanceOf

[](#tobeaninstanceof)

```
Expect::that(new ToEqual(true))->toBeAnInstanceOf('expect\Mathcer'); //pass
Expect::that(new stdClass)->toBeAnInstanceOf('expect\Mathcer'); //failed
```

### toBeAn / toBeA

[](#tobean--tobea)

```
Expect::that(1)->toBeAn('integer'); //pass
Expect::that('foo')->toBeAn('integer'); //failed
Expect::that('foo')->toBeInteger(); //failed
```

```
Expect::that('foo')->toBeAn('string'); //pass
Expect::that(1)->toBeAn('string'); //failed
Expect::that('foo')->toBeString(); //failed
```

```
Expect::that(1.1)->toBeAn('float'); //pass
Expect::that('foo')->toBeAn('float'); //failed
Expect::that('foo')->toBeFloat(); //failed
```

```
Expect::that(true)->toBeAn('boolean'); //pass
Expect::that('foo')->toBeAn('boolean'); //failed
Expect::that('foo')->toBeBoolean(); //failed
```

```
Expect::that(1)->toBeA('integer'); //pass
Expect::that('foo')->toBeA('integer'); //failed
```

```
Expect::that([])->toBeA('array'); //pass
Expect::that('foo')->toBeArray('array'); //failed
```

### toMatch

[](#tomatch)

```
Expect::that('foobar')->toMatch('/foo/'); //pass
Expect::that('foobar')->toMatch('/cat/'); //failed
```

### toStartWith

[](#tostartwith)

```
Expect::that('foobar')->toStartWith('foo'); //pass
Expect::that('foobar')->toStartWith('cat'); //failed
```

### toEndWith

[](#toendwith)

```
Expect::that('foobar')->toEndWith('bar'); //pass
Expect::that('foobar')->toEndWith('cat'); //failed
```

### toHaveLength

[](#tohavelength)

```
Expect::that('foobar')->toHaveLength(6); //pass
Expect::that('foobar')->toHaveLength(5); //failed
```

```
Expect::that([ 1 ])->toHaveLength(1); //pass
Expect::that([ 1, 2 ])->toHaveLength(3); //failed
```

```
Expect::that(new ArrayIterator([ 1 ]))->toHaveLength(1); //pass
Expect::that(new ArrayIterator([ 1, 2 ]))->toHaveLength(3); //failed
```

### toBeEmpty

[](#tobeempty)

```
Expect::that([])->toBeEmpty(); //pass
Expect::that([ 1 ])->toBeEmpty(); //failed
```

### toPrint

[](#toprint)

```
Expect::that(function () {
    echo 'foo';
})->toPrint('foo'); //pass

Expect::that(function () {
    echo 'bar';
})->toPrint('foo'); //failed
```

### toBeGreaterThan / toBeAbove

[](#tobegreaterthan--tobeabove)

```
Expect::that(11)->toBeGreaterThan(10); //pass
Expect::that(10)->toBeGreaterThan(10); //pass
Expect::that(9)->toBeGreaterThan(10); //failed
```

```
Expect::that(11)->toBeAbove(10); //pass
Expect::that(10)->toBeAbove(10); //pass
Expect::that(9)->toBeAbove(10); //failed
```

### toBeLessThan / toBeBelow

[](#tobelessthan--tobebelow)

```
Expect::that(9)->toBeLessThan(10); //pass
Expect::that(10)->toBeLessThan(10); //failed
```

```
Expect::that(9)->toBeBelow(10); //pass
Expect::that(10)->toBeBelow(10); //failed
```

### toBeWithin

[](#tobewithin)

```
Expect::that(11)->toBeWithin(10, 20); //pass
Expect::that(9)->toBeWithin(10, 20); //failed
Expect::that(21)->toBeWithin(10, 20); //failed
```

### toContain

[](#tocontain)

```
Expect::that('foo')->toContain('foo'); //pass
Expect::that('foo')->toContain('foo', 'bar'); //failed
```

```
Expect::that([ 'foo', 'bar' ])->toContain('foo'); //pass
Expect::that([ 'foo', 'bar' ])->toContain('foo', 'bar'); //pass
Expect::that([ 'foo', 'bar' ])->toContain('foo', 'bar', 'bar1'); //failed
```

### toHaveKey

[](#tohavekey)

```
Expect::that([ 'foo' => 1 ])->toHaveKey('foo'); //pass
Expect::that([ 'foo' => 1 ])->toHaveKey('bar'); //failed
```

### ToBeTruthy

[](#tobetruthy)

```
Expect::that(true)->ToBeTruthy(); //pass
Expect::that('')->ToBeTruthy(); //pass
Expect::that(0)->ToBeTruthy(); //pass
Expect::that(false)->ToBeTruthy(); //failed
```

### ToBeFalsey

[](#tobefalsey)

```
Expect::that(false)->ToBeFalsey(); //pass
Expect::that(null)->ToBeFalsey(); //pass
Expect::that('')->ToBeFalsey(); //failed
Expect::that(0)->ToBeFalsey(); //failed
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 99.7% 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 ~26 days

Recently: every ~62 days

Total

20

Last Release

3616d ago

Major Versions

0.6.1 → 1.0.02015-05-01

1.0.7 → 2.0.02016-08-08

PHP version history (3 changes)0.6.1PHP &gt;=5.4.0

1.0.0PHP &gt;=5.5.0

2.0.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/70c299d6d6015ee714954aa05e4d0e9c7b1d31318a5d7db5e9bb4e1f70f78afc?d=identicon)[holyshared](/maintainers/holyshared)

---

Top Contributors

[![holyshared](https://avatars.githubusercontent.com/u/167190?v=4)](https://github.com/holyshared "holyshared (306 commits)")[![waffle-iron](https://avatars.githubusercontent.com/u/6912981?v=4)](https://github.com/waffle-iron "waffle-iron (1 commits)")

---

Tags

testBDDassertspecexpect

### Embed Badge

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

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k526.2M26.9k](/packages/mockery-mockery)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k37.5M3.2k](/packages/phpspec-phpspec)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

37419.9M125](/packages/php-mock-php-mock)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1719.0M541](/packages/php-mock-php-mock-phpunit)[polishsymfonycommunity/symfony-mocker-container

Provides base Symfony dependency injection container enabling service mocking.

1448.2M263](/packages/polishsymfonycommunity-symfony-mocker-container)[dvdoug/behat-code-coverage

Generate Code Coverage reports for Behat tests

623.9M54](/packages/dvdoug-behat-code-coverage)

PHPackages © 2026

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