score-labs/laravel-event-fake 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

score-labs/laravel-event-fake

Composer 安装命令:

composer require score-labs/laravel-event-fake

包简介

An enhanced event fake for Laravel event testing

README 文档

README

Enhanced Laravel Event Fake for testing

Have you ever wanted more versatility when you're testing your Laravel events? If you're like me, you're uncomfortable with the idea of just testing the listeners in isolation, but leaving all of the events unfaked makes your tests a mess. Well fret no further kindred spirit! Score Labs' Laravel Event Fake is here!

So how's it work?

Score Labs' Laravel Event Fake adds two new methods to the already great Event facade.

Installation

composer require --dev score-labs/laravel-event-fake

In your test classes, just import the new Event facade

use ScoreLabs\Event; // full namespace
use Event; // overwritten alias via laravel auto-discovery

Methods

Fake Except

There are two ways to call Event::fakeExcept:

Event::fakeExcept(EventThatIWantToFire::class);

Will fake every event except for EventThatIWantToFire. That event and all of its listeners will fire normally.

Event::fakeExcept(EventThatIWantToFire::class, TheOnlyListenerIWantToFire::class);

Will fake every event except for EventThatIWantToFire and will spy every listener except for `TheOnlyListenerIWantToFire. This usage is great for when you want to isolate a single listener, but you still want to test that the event setup is working as expected.

Once you've passed listeners to spy, you can still assert that they were fired without their code running by using

Event::assertHandled(AnotherListener::class);
// or 
Event::assertHandled(AnotherListener::class, function ($event) {
    return $event instanceof EventIWantToFire;
});

☝️ You can also pass arrays of class names for either argument to allow through multiple events/listeners at once!

Fake Except Models

If you want to fake all events, but you still want events that you manually added in your models boot method to fire, just use

Event::fakeExceptModels();

This way you can fake all events as usual, but still let your models get any necessary information they may need during a creating or saving event.

But what about all of the great existing features of Event::fake?

They are all still there! This is just a drop in enhancement and will be compatible with all usages of Event::fake in Laravel 5.5+

This code is MIT Licensed and open to all contributors. For pull requests, please try to mimic the existing code style.

统计信息

  • 总下载量: 249
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固