PHP code example of digitalcloud / testable-event-listener

1. Go to this page and download the library: Download digitalcloud/testable-event-listener 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/ */

    

digitalcloud / testable-event-listener example snippets




namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    protected $dispatchesEvents = [
        'creating' => \App\Events\UserCreating::class
    ];
}




namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    // ...
    
    protected $listen = [
        \App\Events\UserCreating::class => [
            // ...
            \App\Listeners\UserCreating::class,
            \App\Listeners\UserCreated::class,
            // ...
        ],
    ];
    
    // ...
}





namespace Tests\Unit;

use App\User;
use DigitalCloud\TestableEventListener\EventFaker;
use Tests\TestCase;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        EventFaker::fake([
            \App\Events\UserCreating::class => [
                \App\Listeners\UserCreating::class
            ],
        ]);
        $user = factory(User::class)->create();
        EventFaker::assertDispatched(\App\Events\UserCreating::class);
    }
}