PHPackages                             cerbero/octane-testbench - 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. cerbero/octane-testbench

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

cerbero/octane-testbench
========================

Set of utilities to test Laravel applications powered by Octane.

1.0.1(4y ago)434.2k2[1 issues](https://github.com/cerbero90/octane-testbench/issues)[1 PRs](https://github.com/cerbero90/octane-testbench/pulls)1MITPHPPHP ^8.0

Since Jun 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/cerbero90/octane-testbench)[ Packagist](https://packagist.org/packages/cerbero/octane-testbench)[ Docs](https://github.com/cerbero90/octane-testbench)[ GitHub Sponsors](https://github.com/cerbero90)[ RSS](/packages/cerbero-octane-testbench/feed)WikiDiscussions develop Synced today

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

⛽ Octane Testbench
==================

[](#-octane-testbench)

[![Author](https://camo.githubusercontent.com/fffbc89ca2742dccf8be167716e04b7125a913abae0da6a488131999dab8ca25/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d617574686f72266d6573736167653d6365726265726f393026636f6c6f723d353041424631266c6f676f3d74776974746572267374796c653d666c61742d737175617265)](https://twitter.com/cerbero90)[![PHP Version](https://camo.githubusercontent.com/6d39f07717427e84df7e9b9b422db8b9e2a526b5162f2075feb756e2d02a4b10/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6365726265726f2f6f6374616e652d7465737462656e63683f636f6c6f723d253233344635423933266c6f676f3d706870267374796c653d666c61742d737175617265)](https://www.php.net)[![Laravel Version](https://camo.githubusercontent.com/ea18c12edb72175e59aba015ab13db2e68fb8c79a9b89a328c648ecdef4c42f0/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6c61726176656c266d6573736167653d254532253839254135382e3026636f6c6f723d666632643230266c6f676f3d6c61726176656c267374796c653d666c61742d737175617265)](https://laravel.com)[![Octane Compatibility](https://camo.githubusercontent.com/2bab41dd2c082d2a58c113b9fdd1fa5e56faafbfabd83b9195bab7ef1484b9e1/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d6f6374616e65266d6573736167653d636f6d70617469626c6526636f6c6f723d666632643230266c6f676f3d6c61726176656c267374796c653d666c61742d737175617265)](https://github.com/laravel/octane)[![Build Status](https://camo.githubusercontent.com/2ee6609badc70ca174f85a252633e1ec5a7daa4012cc5324b746530e8050b311/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6365726265726f39302f6f6374616e652d7465737462656e63682f6275696c643f7374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/cerbero90/octane-testbench/actions?query=workflow%3Abuild)[![Coverage Status](https://camo.githubusercontent.com/5e778c45f5d86908def8ce140a06ed2dc91d8e75006acdebcbdecec5a9a0101d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6365726265726f39302f6f6374616e652d7465737462656e63682e7376673f7374796c653d666c61742d737175617265266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/cerbero90/octane-testbench/code-structure)[![Quality Score](https://camo.githubusercontent.com/c621eb29572fe3a95131a9a701368bd1d4c47ea63c77f4ca1407c46fc3c4e042/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6365726265726f39302f6f6374616e652d7465737462656e63682e7376673f7374796c653d666c61742d737175617265266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/cerbero90/octane-testbench)[![Latest Version](https://camo.githubusercontent.com/3a1420d89d776c88e575d3d0109d23533d628d0da2ab5764c0cdaf0cf1f1e180/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6365726265726f2f6f6374616e652d7465737462656e63682e7376673f6c6162656c3d76657273696f6e267374796c653d666c61742d737175617265)](https://packagist.org/packages/cerbero/octane-testbench)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![PSR-12](https://camo.githubusercontent.com/9ba5754b3504e97a10e2b2f84770a218e69e544e9de8943eceb0b67599c83c6c/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d636f6d706c69616e6365266d6573736167653d5053522d313226636f6c6f723d626c7565267374796c653d666c61742d737175617265)](https://www.php-fig.org/psr/psr-12/)[![Total Downloads](https://camo.githubusercontent.com/c59b341146d4f0c3f59da37451ed9ad41fb8c346445f3fb3c55b98fb1c0f4445/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6365726265726f2f6f6374616e652d7465737462656e63682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cerbero/octane-testbench)

Set of utilities to test Laravel applications powered by Octane.

Install
-------

[](#install)

Via Composer:

```
composer require --dev cerbero/octane-testbench
```

In `tests/TestCase.php`, use the `TestsOctaneApplication` trait:

```
use Cerbero\OctaneTestbench\TestsOctaneApplication;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use TestsOctaneApplication;
}
```

Now all tests extending this class, even previously created tests, can run on Octane.

Usage
-----

[](#usage)

- [Requests and responses](#requests-and-responses)
- [Concurrency](#concurrency)
- [Cache](#cache)
- [Tables](#tables)
- [Events](#events)
- [Container](#container)

In a nutshell, Octane Testbench

1. is progressive: existing tests keep working, making Octane adoption easier for existing Laravel apps
2. stubs out workers and clients: tests don't need a Swoole or RoadRunner server to run
3. preserves the application state after a request, so assertions can be performed after the response
4. offers fluent assertions tailored to Octane:

```
public function test_octane_application()
{
    $this
        ->assertOctaneCacheMissing('foo')
        ->assertOctaneTableMissing('example', 'row')
        ->assertOctaneTableCount('example', 0)
        ->expectsConcurrencyResults([1, 2, 3])
        ->get('octane/route')
        ->assertOk()
        ->assertOctaneCacheHas('foo', 'bar')
        ->assertOctaneTableHas('example', 'row.votes', 123)
        ->assertOctaneTableCount('example', 1);
}
```

### Requests and responses

[](#requests-and-responses)

HTTP requests are performed with the [same methods](https://laravel.com/docs/http-tests#making-requests) we would normally call to test any Laravel application, except they will work for both standard and Octane routes:

```
Route::get('web-route', fn () => 123);

Octane::route('POST', '/octane-route', fn () => new Response('foo'));

public function test_web_route()
{
    $this->get('web-route')->assertOk()->assertSee('123');
}

public function test_octane_route()
{
    $this->post('octane-route')->assertOk()->assertSee('foo');
}
```

Responses are wrapped in a `ResponseTestCase` instance that lets us call [response assertions](https://laravel.com/docs/http-tests#available-assertions), any assertion of the [Laravel testing suite](https://laravel.com/docs/testing) and the following exception assertions:

```
$this
    ->get('failing-route')
    ->assertException(Exception::class) // assert exception instance
    ->assertException(new Exception('message')) // assert exception instance and message
    ->assertExceptionMessage('message'); // assert exception message
```

Furthermore, responses and exceptions can be debugged by calling the `dd()` and `dump()` methods:

```
$this
    ->get('failing-route')
    ->dump() // dump the whole response/exception
    ->dump('original') // dump only a specific property
    ->dd() // dump-and-die the whole response/exception
    ->dd('headers'); // dump-and-die only a specific property
```

### Concurrency

[](#concurrency)

[Concurrency](https://laravel.com/docs/octane#concurrent-tasks) works fine during tests. However, PHP 8 forbids the serialization of reflections (hence mocks) and concurrent tasks are serialized before being dispatched. If tasks involve mocks, we can fake the concurrency:

```
// code to test:
Octane::concurrently([
    fn () => $mockedService->run(),
    fn () => 123,
]);

// test:
$this
    ->mocks(Service::class, ['run' => 'foo'])
    ->expectsConcurrency()
    ->get('route');
```

In the test above we are running tasks sequentially without serialization, allowing mocked methods to be executed (we will see more about [mocks](#container) later).

If we need more control over how concurrent tasks run, we can pass a closure to `expectsConcurrency()`. For example, the test below runs only the first task:

```
$this
    ->expectsConcurrency(fn (array $tasks) => [ $tasks[0]() ])
    ->get('route');
```

To manipulate the results of concurrent tasks, we can use `expectsConcurrencyResults()`:

```
$this
    ->expectsConcurrencyResults([$firstTaskResult, $secondTaskResult])
    ->get('route');
```

Finally we can make concurrent tasks fail to test our code when something wrong happens:

```
$this
    ->expectsConcurrencyException() // tasks fail due to a generic exception
    ->get('route');

$this
    ->expectsConcurrencyException(new Exception('message')) // tasks fail due to a specific exception
    ->get('route');

$this
    ->expectsConcurrencyTimeout() // tasks fail due to a timeout
    ->get('route');
```

### Cache

[](#cache)

Octane Testbench provides the following assertions to test the [Octane cache](https://laravel.com/docs/octane#the-octane-cache):

```
$this
    ->assertOctaneCacheMissing($key) // assert the key is not set
    ->get('route')
    ->assertOctaneCacheHas($key) // assert the key is set
    ->assertOctaneCacheHas($key, $value); // assert the key has the given value
```

### Tables

[](#tables)

[Octane tables](https://laravel.com/docs/octane#tables) can be tested with the following assertions:

```
$this
    ->assertOctaneTableMissing($table, $row) // assert the row is not present in the table
    ->assertOctaneTableCount($table, 0) // assert the number of rows in the table
    ->get('route')
    ->assertOctaneTableHas($table, $row) // assert the row is present in the table
    ->assertOctaneTableHas($table, 'row.column' $value) // assert the column in the row has the given value
    ->assertOctaneTableCount($table, 1);
```

### Events

[](#events)

By default listeners for the Octane `RequestReceived` event are disabled to perform assertions on the application state. However we can register listeners for any Octane event if need be:

```
$this
    ->listensTo(RequestReceived::class, $listener1, $listener2) // register 2 listeners for RequestReceived
    ->get('route');

$this
    ->stopsListeningTo(TaskReceived::class, $listener1, $listener2) // unregister 2 listeners for TaskReceived
    ->get('route');
```

### Container

[](#container)

Octane Testbench also introduces the following helpers to bind and [mock services](https://docs.mockery.io/en/latest/reference/index.html) at the same time while preserving a fluent syntax:

```
$this
    ->mocks(Service::class, ['expectedMethod' => $expectedValue]) // mock with simple expectations
    ->mocks(Service::class, fn ($mock) => $mock->shouldReceive('method')->twice()) // mock with advanced expectations
    ->partiallyMocks(Service::class, ['expectedMethod' => $expectedValue]) // same as above but partial
    ->partiallyMocks(Service::class, fn ($mock) => $mock->shouldReceive('method')->twice())
    ->get('route');
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Andrea Marco Sartori](https://twitter.com/cerbero90)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 95% 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 ~167 days

Total

3

Last Release

1515d ago

Major Versions

0.1.0 → 1.0.02021-06-10

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/596523?v=4)[Matteo Picciolini](/maintainers/cerbero)[@cerbero](https://github.com/cerbero)

---

Top Contributors

[![cerbero90](https://avatars.githubusercontent.com/u/5838106?v=4)](https://github.com/cerbero90 "cerbero90 (19 commits)")[![faytekin](https://avatars.githubusercontent.com/u/4013224?v=4)](https://github.com/faytekin "faytekin (1 commits)")

---

Tags

laravellaravel-octaneoctanetesttestingtestingtestlaraveloctanelaravel-octane

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/cerbero-octane-testbench/health.svg)

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

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k42.5M40.8k](/packages/orchestra-testbench)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4236.6M68](/packages/timacdonald-log-fake)[sofa/eloquent-testsuite

Helpers for fast and reliable UNIT tests for your Eloquent Models with PHPUnit

10107.6k](/packages/sofa-eloquent-testsuite)

PHPackages © 2026

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