PHPackages                             genl/laravel-broadcast-testing - 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. genl/laravel-broadcast-testing

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

genl/laravel-broadcast-testing
==============================

A broadcast provider for testing event broadcasting

1.0.3(5y ago)46.5k↓44.8%1MITPHP

Since Apr 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/GENL/laravel-broadcast-testing)[ Packagist](https://packagist.org/packages/genl/laravel-broadcast-testing)[ Docs](https://github.com/GENL/laravel-broadcast-testing/)[ RSS](/packages/genl-laravel-broadcast-testing/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

Test Laravel Event Broadcasting
===============================

[](#test-laravel-event-broadcasting)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1b7548bc2b040d0ccd862cfbac6c69e075189dcd147c95c0438e8c2f4e3babdc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f47454e4c2f6c61726176656c2d62726f6164636173742d74657374696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/GENL/laravel-broadcast-testing)[![GitHub Actions Status](https://camo.githubusercontent.com/c9ef54850b467b5b065109ac8a37760c9a6376e84ad18de8ebf4ad68329802fa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f67656e6c2f6c61726176656c2d62726f6164636173742d74657374696e672f54657374733f6c6162656c3d7465737473267374796c653d666c6174)](https://github.com/genl/laravel-broadcast-testing/actions?query=workflow:Tests+branch:master)[![Total Downloads](https://camo.githubusercontent.com/52eae9fb68f10f48434db4665bc75c4752c57afed0ff3eca46746c13bc99c388/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f47454e4c2f6c61726176656c2d62726f6164636173742d74657374696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/GENL/laravel-broadcast-testing)

This package lets you test if Laravel events has been broadcasted. This is useful for TDD and End-to-end testing.

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

[](#installation)

1. Install the package via composer:

```
composer require GENL/laravel-broadcast-testing
```

2. Add the test broadcaster to the `connections` array in `app/config/broadcasting.php`.

```
'connections' => [
    ...
    'test' => [
        'driver' => 'test'
    ],
],
```

3. Set the default broadcaster for testing in the `php` element of `phpunit.xml`.

```

    ...

```

4. Finally add the `Genl\TestBroadcaster\CanTestBroadcasting` trait to `tests/TestCase.php`.

```
use Genl\TestBroadcaster\CanTestBroadcasting;
abstract class TestCase extends BaseTestCase
{
    use CanTestBroadcasting;
}
```

Usage
-----

[](#usage)

This package adds the `assertEventBroadcasted` method to your testing.

```
/**
 * @test
 */
public function it_can_assert_when_an_event_is_broadcasted()
{
    event(new TestEvent());
    $this->assertEventWasBroadcast(TestEvent::class);
}
```

Futhermore it is also possible to test for how many times an even is broadcasted

```
/**
 * @test
 */
public function it_can_assert_if_an_event_was_broadcasted_a_given_amount_of_times()
{
    event(new TestEvent());
    $this->assertEventWasBroadcast(TestEvent::class, 1);

    event(new TestEvent());
    $this->assertEventWasBroadcast(TestEvent::class, 2);
}
```

```
/**
 * @test
 */
public function it_can_assert_if_an_event_was_broadcasted_a_given_amount_of_times()
{
    event(new TestEvent());
    $this->assertEventWasBroadcast(TestEvent::class, 1);

    event(new TestEvent());
    $this->assertEventWasBroadcast(TestEvent::class, 2);
}
```

The `assertEventWasBroadcast` method can also assert on which channels the event is broadcasted to. It can either take a single string, for a single channel, or an array of channel names.

```
/**
 * @test
 */
public function it_can_assert_if_an_event_was_broadcasted_on_multiple_channels()
{
    event(new TestEvent());

    //
    $this->assertEventWasBroadcast(TestEvent::class, ['private-channel-name', 'private-another-channel-name']);

    try {
        $this->assertEventWasBroadcast(TestEvent::class, [
            'private-channel-name',
            'somethingelse-fake-channel',
        ]);
        $this->fail("assertEventBroadcasted asserted that an event was broadcasted on given channels when it wasn't");
    } catch (ExpectationFailedException $e) {
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [jlndk](https://github.com/jlndk)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 57.1% 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 ~60 days

Total

5

Last Release

1983d ago

Major Versions

v0.1 → 1.0.02020-12-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe67c0f9ce1ee8a696fd8289e69c64743ab39f31f4d8544412a0b2d37da375f9?d=identicon)[Ekcel Henrich](/maintainers/Ekcel%20Henrich)

---

Top Contributors

[![jlndk](https://avatars.githubusercontent.com/u/3009101?v=4)](https://github.com/jlndk "jlndk (8 commits)")[![GENL](https://avatars.githubusercontent.com/u/36866702?v=4)](https://github.com/GENL "GENL (6 commits)")

---

Tags

testinglaraveleventsBroadcasting

### Embed Badge

![Health badge](/badges/genl-laravel-broadcast-testing/health.svg)

```
[![Health](https://phpackages.com/badges/genl-laravel-broadcast-testing/health.svg)](https://phpackages.com/packages/genl-laravel-broadcast-testing)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[hotmeteor/spectator

Testing helpers for your OpenAPI spec

3021.4M1](/packages/hotmeteor-spectator)[orchestra/workbench

Workbench Companion for Laravel Packages Development

8017.0M43](/packages/orchestra-workbench)[guanguans/laravel-soar

SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

2227.8k](/packages/guanguans-laravel-soar)[spurwork/spectator

Testing helpers for your OpenAPI spec

3021.5k](/packages/spurwork-spectator)[sofa/laravel-kahlan

Kahlan specs suite for testing Laravel applications

1524.2k](/packages/sofa-laravel-kahlan)

PHPackages © 2026

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