定制 wp-launchpad/phpunit-wp-hooks 二次开发

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

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

wp-launchpad/phpunit-wp-hooks

Composer 安装命令:

composer require wp-launchpad/phpunit-wp-hooks

包简介

Custom annotations to mock WP hooks for PHPUnit.

README 文档

README

This library is a PHPUnit library aimed to facilitate mocking WordPress hooks during integration testing.

Install

To install the extension require it:

composer require wp-launchpad/phpunit-wp-hooks --dev

Once you done that then you can use the trait MockHooks and at the following logic to your base TestCase where my_prefix is your plugin prefix:

    protected function setUp(): void
    {
        parent::setUp();
        $this->mockHooks();
    }

    protected function tearDown(): void
    {
        $this->resetHooks();
        parent::tearDown();
    }


     protected function getPrefix(): string {
        return 'my_prefix';
     }

     protected function getCurrentTest(): string {
        return $this->getName();
     }

Mock hooks

Register a callback

It is possible to add a callback inside the test class to control the value from a filter. For that first you need to create a callback in the class:

public function myCallback() {
    return false;
}

Then in the dockblock of that callback you can add the @hook annotation:

/** 
 * @hook my-event 15
 */ 

Where 15 is the priority from the filter. If you forget this part the default priority will be 10.

Isolate a hook

To isolate a hook to reduce it to a single callback it is possible by adding @hook-isolated annotation on the test method:

/**
 * @hook-isolated my-event myCallback 15
 */

Where 15 is the priority from the filter. If you forget this part the default priority will be 10.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固