PHP code example of alibayat / laravel-test-broadcaster

1. Go to this page and download the library: Download alibayat/laravel-test-broadcaster library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alibayat / laravel-test-broadcaster example snippets


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


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

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

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

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

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

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

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

    try {
        $this->assertEventBroadcasted(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) {
    }
}
 php
/**
 * @test
 */
public function it_can_assert_when_an_event_is_broadcasted()
{
    event(new TestEvent());
    $this->assertEventBroadcasted(TestEvent::class);
}