mercredi 15 novembre 2017

event dispatcher assertion fails to find assertDispatched event

I get the error

Error: Call to undefined method Illuminate\Events\Dispatcher::assertDispatched()

for the test

<?php

namespace Tests\Unit;

use Tests\TestCase;
use App\Entities\Requester;
use App\Observers\RequesterObserver;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;

class RequesterObserverTest extends TestCase {

  use RefreshDatabase;

  public function setUp()
  {
    parent::setUp();
    Mail::fake();
  }

  public function testRequesterCreationTriggersObserver(){

    $expected = factory(Requester::class)->create();

    //assert the creation event observer is fired
    Event::assertDispatched(RequesterObserver::class, function($event) use ($expected){
      return $event->requester->email_id === $expected->email_id;
    });

  }
}

the method has been used as referred in the Laravel 5.5 documentation, when I run on a debug mode, I do see the actual event being fired, however the test gives an error on this line

Event::assertDispatched(RequesterObserver::class, function($event) use ($expected)



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AHHxza
via IFTTT

Aucun commentaire:

Enregistrer un commentaire