承接 rosio/wordpress-testing-harness 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱: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
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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