I am running a test to ensure my events are firing properly.
MyTest
/** @test */
public function foil_products_DO_trigger_oos_event ()
{
$this->setUpTheWorld(true, 1);
$response = $this->sendInStockData($this->pusher, Carbon::now()->subHour());
$this->expectsEvents(\App\Events\InventoryOutOfStock::class);
$this->sendCustomStockData($this->pusher, 0, 1, Carbon::now());
// TEST THE RESULTS OF THE LISTENER FOR THAT EVENT
$this->pusher = $this->pusher->fresh();
$this->assertEquals(1, $this->pusher->oos);
$this->assertCount(2, $this->pusher->inventories, "Pusher doesnt have 2 Inventories");
$this->assertEquals(0, $this->pusher->latestInventory->tags_blocked);
}
If I comment out the line:
$this->expectsEvents(\App\Events\InventoryOutOfStock::class);
Then my test will pass. The line:
$this->assertEquals(1, $this->pusher->oos);
passes and this would only happen if the event fired. Additionally, I looked at my log file and I can guarantee that the event fired....
Is there anything I am doing wrong to tell PHPUnit that these events will be firing???
Thank you!
EventServiceProvider
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
\App\Events\InventoryOutOfStock::class => [
\App\Listeners\InventoryOutOfStockUpdater::class,
\App\Listeners\EmailInventoryOutOfStockNotification::class,
\App\Listeners\SMSInventoryOutOfStockNotification::class,
],
];
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire