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

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

jasonmccreary/expect
====================

BDD-style assertions for PHP.

v1.0.1(9y ago)5571MITPHP

Since Jun 30Pushed 9y agoCompare

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

READMEChangelogDependencies (1)Versions (3)Used By (1)

Expect
======

[](#expect)

[![Build Status](https://camo.githubusercontent.com/ac80826a4b99bfd598df85f8b9eb4857656be015f6d3358e3db18c34310f36f0/68747470733a2f2f7472617669732d63692e6f72672f6a61736f6e6d636372656172792f6578706563742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jasonmccreary/expect) [![Latest Stable Version](https://camo.githubusercontent.com/da134bcc90138eb5142bb221b3f829d1ea00e0f976e9df4bcc010f0a13fb0cc7/68747470733a2f2f706f7365722e707567782e6f72672f6a61736f6e6d636372656172792f6578706563742f762f737461626c652e706e67)](https://packagist.org/packages/jasonmccreary/expect)

Expect is a BDD-style assertion library for PHP - allowing you to express expectations using a natural, fluent interface.

```
// equality
expect(1)->toEqual('1');
expect(2)->toBe(2);

// comparison
expect(5)->toBeLessThan(7);
expect(5)->toBeLessThanOrEqualTo(5);
expect(5)->toBeGreaterThan(4);
expect(5)->toBeGreaterThanOrEqualTo(5);

// true / false / null
expect(true)->toBeTrue();
expect('1')->toBeTruthy();
expect(false)->toBeFalse();
expect('0')->toBeFalsy();
expect(null)->toBeNull();

// strings
expect('string')->toContain('in');
expect('string')->toStartWith('str');
expect('string')->toEndWith('ing');
expect('string')->toHaveLength(6);
expect('string')->toMatchPattern('/string/');
expect('string')->toMatchFormat('%s');

// arrays
expect(['a', 'b', 'c'])->toHaveCount(3);
expect(['a', 'b', 'c'])->toContain('a');
expect(['key' => 'value'])->toHaveKey('key');

// types
expect(1)->toBeType('int');
expect(new Example())->toBeInstanceOf(Example::class);
expect('{"key": "value"}')->toBeJson();
expect('value')->toBeXml();

// files
expect('file.txt')->toExist();

// negation
expect(1)->not()->toEqual(2);
expect(true)->not()->toBeFalse();
expect($value)->not()->toBeNull();
```

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

[](#installation)

Install Expect as a **development** dependency to your project using [Composer](https://getcomposer.org):

```
composer require --dev jasonmccreary/expect
```

Usage
-----

[](#usage)

Expect is used by [PSpec](https://github.com/jasonmccreary/pspec), but can be used within other PHP testing frameworks or as a stand-alone.

Documentation
-------------

[](#documentation)

Documentation and additional examples will be available in the official release.

License
-------

[](#license)

Expect is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

Thanks
------

[](#thanks)

Expect was built atop [Verify](https://github.com/Codeception/Verify) and heavily inspired by [RSpec](https://github.com/rspec/rspec-core) and [Jasmine](https://github.com/jasmine/jasmine). I want to recognize and thank these projects.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~0 days

Total

2

Last Release

3646d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/92a6bfc994b500ee991e6a7c581fb07af26b68b85821ff354bed0ac786fc9211?d=identicon)[jasonmccreary](/maintainers/jasonmccreary)

---

Top Contributors

[![DavertMik](https://avatars.githubusercontent.com/u/220264?v=4)](https://github.com/DavertMik "DavertMik (20 commits)")[![jasonmccreary](https://avatars.githubusercontent.com/u/161071?v=4)](https://github.com/jasonmccreary "jasonmccreary (18 commits)")[![Ragazzo](https://avatars.githubusercontent.com/u/1748844?v=4)](https://github.com/Ragazzo "Ragazzo (10 commits)")[![cmoralesweb](https://avatars.githubusercontent.com/u/5377322?v=4)](https://github.com/cmoralesweb "cmoralesweb (7 commits)")[![sergeyklay](https://avatars.githubusercontent.com/u/1256298?v=4)](https://github.com/sergeyklay "sergeyklay (4 commits)")[![stevekr](https://avatars.githubusercontent.com/u/7532372?v=4)](https://github.com/stevekr "stevekr (2 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")[![asppsa](https://avatars.githubusercontent.com/u/453170?v=4)](https://github.com/asppsa "asppsa (1 commits)")

---

Tags

testBDDassertmatcher

### Embed Badge

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

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k516.1M26.1k](/packages/mockery-mockery)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k41.3M38.7k](/packages/orchestra-testbench)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69519.1M606](/packages/spatie-phpunit-snapshot-assertions)[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.

36919.3M119](/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.

1718.7M509](/packages/php-mock-php-mock-phpunit)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1489.3M94](/packages/ergebnis-phpunit-slow-test-detector)

PHPackages © 2026

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