定制 remarkablemark/rector-laravel-service-mocking 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

remarkablemark/rector-laravel-service-mocking

最新稳定版本:3.0.0

Composer 安装命令:

composer require --dev remarkablemark/rector-laravel-service-mocking

包简介

Rector to replace deprecated Laravel service mocking testing methods

README 文档

README

packagist test

Rector to replace deprecated Laravel service mocking testing methods such as expectsEvents, expectsJobs, and expectsNotifications.

From Laravel 10:

The deprecated MocksApplicationServices trait has been removed from the framework. This trait provided testing methods such as expectsEvents, expectsJobs, and expectsNotifications.

If your application uses these methods, we recommend you transition to Event::fake, Bus::fake, and Notification::fake, respectively. You can learn more about mocking via fakes in the corresponding documentation for the component you are attempting to fake.

Requirements

PHP >=8.2

Install

Install with Composer:

composer require --dev rector/rector remarkablemark/rector-laravel-service-mocking

Usage

Register the rule in rector.php:

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Remarkablemark\RectorLaravelServiceMocking\LaravelServiceMockingRector;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/tests',
    ]);
    $rectorConfig->rule(LaravelServiceMockingRector::class);
};

See the diff:

vendor/bin/rector process --dry-run

Apply the rule:

vendor/bin/rector process

Clear the cache and apply the rule:

vendor/bin/rector process --clear-cache

Rule

Before

$this->expectsEvents([MyEvent::class]);

After

 \Illuminate\Support\Facades\Event::fake([MyEvent::class])->assertDispatched([MyEvent::class]);

The test may still fail because of assertDispatched so it's recommended to refactor to:

Event::fake([MyEvent::class]);
// dispatch your event here...
Event::assertDispatched(MyEvent::class);

If you have multiple events, call assertDispatched for each event:

Event::fake([MyEvent1::class, MyEvent2::class]);
// ...
Event::assertDispatched(MyEvent1::class);
Event::assertDispatched(MyEvent2::class);

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固