PHPackages                             matthiasnoback/phpunit-asynchronicity - 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. matthiasnoback/phpunit-asynchronicity

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

matthiasnoback/phpunit-asynchronicity
=====================================

Library for asserting things that happen asynchronously with PHPUnit

v3.0.1(2y ago)36229.0k↓20.9%77MITPHPPHP ^8.1

Since Mar 23Pushed 2y ago5 watchersCompare

[ Source](https://github.com/matthiasnoback/phpunit-asynchronicity)[ Packagist](https://packagist.org/packages/matthiasnoback/phpunit-asynchronicity)[ RSS](/packages/matthiasnoback-phpunit-asynchronicity/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (27)Used By (7)

Asynchronicity
==============

[](#asynchronicity)

Using this library you can make a test wait for certain conditions, e.g. to test the output of another process.

See my [blog post on the subject](https://matthiasnoback.nl/2014/03/test-symfony2-commands-using-the-process-component-and-asynchronous-assertions/) for an explanation of the concepts and some code samples. Please note that this article covers version 1 of the library.

Usage
=====

[](#usage)

With PHPUnit
------------

[](#with-phpunit)

```
use Asynchronicity\PHPUnit\Asynchronicity;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

final class ProcessTest extends TestCase
{
    use Asynchronicity;

    /**
     * @test
     */
    public function it_creates_a_pid_file(): void
    {
        // start the asynchronous process that will eventually create a PID file...

        self::assertEventually(
            function (): void {
                Assert::assertFileExists(__DIR__ . '/pid');
            }
        );
    }
}
```

With Behat
----------

[](#with-behat)

Within a Behat `FeatureContext` you could use it for example that a page eventually contains some text:

```
use Asynchronicity\PHPUnit\Asynchronicity;
use Behat\MinkExtension\Context\MinkContext;
use PHPUnit\Framework\Assert;

final class FeatureContext extends MinkContext
{
    use Asynchronicity;

    /**
     * @Then the stock level has been updated to :expectedStockLevel
     */
    public function thenTheFileHasBeenCreated(string $expectedStockLevel): void
    {
        self::assertEventually(function () use ($expectedStockLevel): void {
            $this->visit('/stock-levels');

            $actualStockLevel = $this->getSession()->getPage())->find('css', '.stock-level')->getText();

            Assert::assertEquals($expectedStockLevel, $actualStockLevel);
        });
    }
}
```

Comments and suggestions
------------------------

[](#comments-and-suggestions)

- You can use `$this` inside these callables.
- You can add `use ($...)` to pass in extra data.
- You can throw any type of exception inside the callable to indicate that what you're looking for is not yet the case.
- Often it's convenient to just use the usual assertion methods (PHPUnit or otherwise) inside the callable. They will often provide the right amount of detail in their error messages too.
- `assertEventually()` supports extra arguments for setting the timeout and wait time in milliseconds.
- You can use any callable as the first argument to `assertEventually()`, including objects with an `__invoke()` method or something like `[$object, 'methodName']`.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 77.8% 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 ~200 days

Recently: every ~312 days

Total

19

Last Release

831d ago

Major Versions

v0.1.0 → v1.0.02014-03-23

v1.4.1 → v2.0.02018-06-11

v2.4.1 → v3.0.02023-11-29

PHP version history (6 changes)v1.1.0PHP ^7.0

v1.4.0PHP ^7.1

v2.1.0PHP ^7.2

v2.3.0PHP ^7.3

v2.4.0PHP ^7.3 || ^8.0

v3.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1193078?v=4)[Matthias Noback](/maintainers/matthiasnoback)[@matthiasnoback](https://github.com/matthiasnoback)

---

Top Contributors

[![matthiasnoback](https://avatars.githubusercontent.com/u/1193078?v=4)](https://github.com/matthiasnoback "matthiasnoback (49 commits)")[![tuffz](https://avatars.githubusercontent.com/u/2077427?v=4)](https://github.com/tuffz "tuffz (6 commits)")[![MarijnKoesen](https://avatars.githubusercontent.com/u/711208?v=4)](https://github.com/MarijnKoesen "MarijnKoesen (4 commits)")[![ruudk](https://avatars.githubusercontent.com/u/104180?v=4)](https://github.com/ruudk "ruudk (3 commits)")[![malukenho](https://avatars.githubusercontent.com/u/3275172?v=4)](https://github.com/malukenho "malukenho (1 commits)")

---

Tags

phpunitassertionasynchronicity

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/matthiasnoback-phpunit-asynchronicity/health.svg)

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

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k910.7M134.8k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[johnkary/phpunit-speedtrap

Find and report on slow tests in your PHPUnit test suite

78337.2M122](/packages/johnkary-phpunit-speedtrap)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69617.9M510](/packages/spatie-phpunit-snapshot-assertions)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

57026.3M456](/packages/dg-bypass-finals)

PHPackages © 2026

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