PHPackages                             friendsofhyperf/co-phpunit - 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. friendsofhyperf/co-phpunit

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

friendsofhyperf/co-phpunit
==========================

The Co-PHPUnit component for Hyperf.

v3.1.75(5mo ago)099MITPHP

Since Oct 27Pushed 5mo agoCompare

[ Source](https://github.com/friendsofhyperf/co-phpunit)[ Packagist](https://packagist.org/packages/friendsofhyperf/co-phpunit)[ Fund](https://hdj.me/sponsors/)[ GitHub Sponsors](https://github.com/huangdijia)[ RSS](/packages/friendsofhyperf-co-phpunit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (10)Used By (0)

Co-PHPUnit
==========

[](#co-phpunit)

[![Latest Stable Version](https://camo.githubusercontent.com/15aca63509878109ba3c021a832ae0e66ba29928ea38eddc08ed7c940bac4401/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f667269656e64736f666879706572662f636f2d706870756e6974)](https://packagist.org/packages/friendsofhyperf/co-phpunit)[![Total Downloads](https://camo.githubusercontent.com/56de58cc2957ba305af8c101b4a4eba9d704455dc2530c13524b7244b2a5015f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f667269656e64736f666879706572662f636f2d706870756e6974)](https://packagist.org/packages/friendsofhyperf/co-phpunit)[![License](https://camo.githubusercontent.com/ca6f2110c82e486fa26ca30810a80e1f7ddeafed4b37683e03a3b1159412b0c1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f667269656e64736f666879706572662f636f2d706870756e6974)](https://github.com/friendsofhyperf/components)

A PHPUnit extension that enables tests to run inside Swoole coroutines, specifically designed for testing Hyperf applications and other Swoole-based frameworks.

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

[](#installation)

```
composer require friendsofhyperf/co-phpunit --dev
```

Why Co-PHPUnit?
---------------

[](#why-co-phpunit)

When testing Hyperf applications, many components rely on Swoole's coroutine context to function properly. Running tests in a traditional synchronous environment can lead to issues such as:

- Coroutine context not being available
- Timers and event loops not working correctly
- Coordinator pattern failures
- Database connection pool issues

Co-PHPUnit solves these problems by automatically wrapping test execution in a Swoole coroutine context when needed.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Simply use the `RunTestsInCoroutine` trait in your test class:

```
