10quality/wpmvc-addon-testsuite 问题修复 & 功能扩展

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

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

10quality/wpmvc-addon-testsuite

Composer 安装命令:

composer require 10quality/wpmvc-addon-testsuite

包简介

Test suite for WordPress MVC (WPMVC) framework add-ons.

README 文档

README

Install

Composer command to install as required-dev:

composer install 10quality/wpmvc-addon-testsuite --dev

Test Case Class

Instead of the default PHPUnit test case use the following:

use WPMVC\Addons\PHPUnit\TestCase;

class MyTest extends TestCase
{
    // Your test methods
}

This classs will allow you to use the following assertiong methods:

Method Parameters Description
$this->assertDidAction $handle the action hook name handle. Asserts if an action ran.
$this->assertDidNotAction $handle the action hook name handle. Asserts if an action not ran.
$this->assertAppliedFilters $handle the filter hook name handle. Asserts if filters have been applied to a hook.
$this->assertNotAppliedFilters $handle the filter hook name handle. Asserts if filters have been not applied to a hook.
$this->assertAddedAction $handle the action hook name handle. Asserts if an action handler has been added for a hook.
$this->assertNotAddedAction $handle the action hook name handle. Asserts if no action handlers has been added for a hook.
$this->assertAddedFilter $handle the filter hook name handle. Asserts if a filter handler has been added for a hook.
$this->assertNotAddedFilter $handle the filter hook name handle. Asserts if no filter handlers has been added for a hook.
$this->assertHasRegisterStyle $handle the style name handle. Asserts if a style asset has been registered.
$this->assertNotHasRegisterStyle $handle the style hook name handle. Asserts if a style asset has not been registered.
$this->assertHasRegisterScript $handle the script name handle. Asserts if a script asset has been registered.
$this->assertNotHasRegisterScript $handle the script hook name handle. Asserts if a script asset has not been registered.
$this->assertHasEnqueueStyle $handle the style name handle. Asserts if a style asset has been registered.
$this->assertNotHasEnqueueStyle $handle the style hook name handle. Asserts if a style asset has not been registered.
$this->assertHasEnqueueScript $handle the script name handle. Asserts if a script asset has been enqueued.
$this->assertNotHasEnqueueScript $handle the script hook name handle. Asserts if a script asset has not been enqueued.
$this->assertHasCalledWP $function the name of a WordPress core function. Asserts if a core WordPress function has been called.
$this->assertNotHasCalledWP $function the name of a WordPress core function. Asserts if a core WordPress function has not been called.

Example:

use WPMVC\Addons\PHPUnit\TestCase;

class MyTest extends TestCase
{
    public function testAction()
    {
        // Run
        do_action( 'init' );
        // Assert
        $this->assertDidAction( 'init' );
    }
}

Test your addon

You addon main class needs a WordPress MVC main class (bridge) instance to work correctly. The TestCase class include the method getBridgeMock() that allows you to test your addon mocking the Bridge class.

Example:

use WPMVC\Addons\PHPUnit\TestCase;
use MyAddon;

class MyAddonTest extends TestCase
{
    public function testInit()
    {
        // Prepare
        $bridge = $this->getBridgeMock();
        $addon = new MyAddon( $bridge );
        // Run
        $addon->init();
        // Assert
        $this->assertAddedAction( 'init' );
        $this->assertHasRegisterScript( 'my-js' );
    }
}

The example above tests the method init() of the addon class MyAddon, which receives the $bridge initialized as a mock. The example asserts that an action hook has been added and a script has been registered during the method call.

You can mock the Bridge for your own benefit:

use WPMVC\Addons\PHPUnit\TestCase;
use WPMVC\Addons\PHPUnit\Mocks\Brige;
use MyAddon;

class MyAddonTest extends TestCase
{
    public function testInit()
    {
        // Prepare
        $bridge = $this->getMockBuilder( Brige::class )
            ->disableOriginalConstructor()
            ->getMock();
        $addon = new MyAddon( $bridge );
        // Run
        $addon->init();
        // Assert
        $this->assertAddedAction( 'init' );
        $this->assertHasRegisterScript( 'my-js' );
    }
}

Reset test suite data

You can reset test suite data by calling the function wpmvc_addon_phpunit_reset() inside the setUp or tearDown methods.

WordPress core functions mocked

The following WordPress core functions are mocked and included through composer:

  • __
  • _e
  • add_action
  • add_filter
  • add_query_arg
  • add_submenu_page
  • admin_url
  • apply_filters
  • do_action
  • esc_attr
  • esc_html
  • esc_html_e
  • esc_url
  • get_filesystem_method
  • get_locale
  • get_stylesheet_directory
  • home_url
  • request_filesystem_credentials
  • sanitize_text_field
  • site_url
  • submit_button
  • wp_enqueue_script
  • wp_enqueue_style
  • wp_register_script
  • wp_register_style
  • WP_Filesystem

WordPress core constants mocked

The following constants are mocked through composer if they are not defined:

  • ABSPATH

WordPress core classes mocked

The following WordPress classes are mocked and included through composer:

  • WP_Filesystem

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固