rosio/wordpress-testing-harness 问题修复 & 功能扩展

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

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

rosio/wordpress-testing-harness

Composer 安装命令:

composer require rosio/wordpress-testing-harness

包简介

Makes testing plugins and themes with WordPress and Composer much easier

README 文档

README

This library is meant to make it easier to test plugins and themes with the WordPress runtime via PHPUnit.
This is basically just a rewrite of kurtpayne/wordpress-unit-tests.

Usage:

  1. Add this library, your testing library, and your WordPress deployment of choice to your plugin or themes composer.php:

    	"autoload-dev": {
    		"psr-4": {
    			"Plugin\\SomePlugin\\": "tests/"
    		}
    	},
    	"require-dev": {
    		"phpunit/phpunit": "~3.7",
    		"rosio/wordpress-testing-harness": "dev-master",
    		"johnpbloch/wordpress": "~3.8"
    	},

    You don't actually have to include WordPress, and instead have it download to the correct folder during testing (which means you can then test multiple versions of WordPress easily), but it's recommended to add one for easy local testing.

  2. Configure your phpunit.xml.dist

    <?xml version="1.0" encoding="UTF-8"?>
    <phpunit backupGlobals="false"
             beStrictAboutTestSize="true"
             backupStaticAttributes="false"
             bootstrap="tests/bootstrap.php"
             colors="true"
             convertErrorsToExceptions="true"
             convertNoticesToExceptions="true"
             convertWarningsToExceptions="true"
             processIsolation="false"
             stopOnFailure="false"
             syntaxCheck="false"
    >
        <testsuites>
            <testsuite name="Application Test Suite">
                <directory suffix="Test.php">./tests/</directory>
            </testsuite>
        </testsuites>
    </phpunit>
    
  3. Configure your phpunit's tests/bootstrap.php file:

    <?php
    
    require_once __DIR__ . '/../vendor/autoload.php';
    
    $bootstrapper = new Rosio\WordPressTestingHarness\Bootstrapper(array(
        'bootstrap-path' => __FILE__,
    
        'db-name' => 'wp_test',
        'db-user' => 'root',
        'db-pass' => 'root',
        'db-host' => 'localhost',
        'db-prefix' => 'wptests_',
        'db-charset' => '',
        'db-collate' => '',
        'wplang' => '',
    
        'wordpress-path' => __DIR__ . '/../wordpress',
        'domain' => 'wp.localhost',
        'admin-email' => 'admin@example.org',
        'blog-title' => 'Tests',
        'admin-password' => 'admin',
    
        'always-reinstall' => true,
    
        'php-binary' => 'php',
        'testdata-path' => __DIR__ . '/../data',
    ));
    
    // Require in plugin
    require __DIR__ . '/../index.php';
  4. Write your first test!

    <?php
    namespace Plugin\SomePlugin;
    
    use WP_UnitTestCase;
    use \Mockery as m;
    
    class MainPluginTest extends WP_UnitTestCase
    {
    	public function setUp()
    	{
    
    	}
    
    	public function tearDown()
    	{
    		m::close();
    	}
    
    	public function testPluginIsCreated()
    	{
    		$this->assertInstanceOf('Plugin\SomePlugin\MainPlugin', getSomePlugin());
    	}
    }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固