定制 10up/wp-codeception 二次开发

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

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

10up/wp-codeception

最新稳定版本:1.0.3

Composer 安装命令:

composer require 10up/wp-codeception

包简介

The WordPress Plugin which integrates with the Codeception PHP testing framework and allows you to write and run Codeception tests for WordPress via WP CLI.

README 文档

README

This is a WordPress Plugin which integrates with the Codeception PHP testing framework and allows you to write and run Codeception tests for WordPress via WP CLI.

Support Level

We're working towards supporting all of Codeceptions commands. If you find one we haven't included yet, please submit a Pull Request!

Installation

Download the latest version and extract, or clone the repository with Git into a new directory wp-content/plugins/wp-codeception in your WordPress install.

Install required node modules and composer dependencies

We'll run our commands from within VVV because WP CLI, Node, and Composer are already installed for us there.

$ vagrant up
$ vagrant ssh
$ sudo apt-get install openjdk-7-jre-headless
$ cd /srv/www/yoursite/htdocs/wp-content/plugins/wp-codeception
$ composer install
$ wp plugin activate wp-codeception

Afterwards you'll have a new vendor directory within your plugins/wp-codeception directory which contains all the code libraries we're dependant on.

Install as a composer dependency

There is an alternative way to install this plugin. You can add it as a composer dependency for your project. To do it, run following command in your terminal:

$ composer require 10up/wp-codeception

This command will install the plugin and all its dependencies for your project. Please, pay attention that if you already use composer/installers dependency in your project, then wp-codeception will be installed into <PROJECT_DIR>/wp-content/plugins/wp-codeception/ folder. It happens, because wp-codeception has wordpress-plugin type and will be processed by composer/installers accordingly (read its documentation for more details).

If you want to add it as a dependency to your plugin or theme, you will need to update your composer.json file and tell it where to install wp-codeception. You can achieve it by providing installer-paths instructions like in the snippet below.

{
    ...,
    "extra": {
        "installer-paths": {
            "vendor/{$name}/": ["type:wordpress-plugin"]
        }
    },
    ...
}

Now composer/installers will know to install wordpress plugins into vendor folder. The final step which you need to do is to update your autoload section and add wp-codeception.php file to the autoload files list.

{
    ...,
    "autoload": {
        "psr-X": {
            ...
        },
        "files": [
            ...,
            "vendor/wp-codeception/wp-codeception.php"
        ]
    },
    ...
}

Install the test suite

See the Codeception bootstrapping documentation for further information.

# You'll create the test suite in your own plugin or theme directory..
$ cd /srv/www/yoursite/htdocs/wp-content/{your plugin or theme directory}
$ wp codeception bootstrap

Afterwards you'll have a new tests directory within your plugin or theme directory. This is your new test suite, and where you'll write all your tests.

Writing Tests

You can write tests using any of the three Codeception testing frameworks: Acceptance, Functional and Unit testing. If you look within the new tests directory you'll see three config files; one for each test framework (acceptance.suite.yml, functional.suite.yml, unit.suite.yml). Edit these files as you wish.

Generate your first test

# You should be in the plugin or theme directory where you ran the bootstrap
$ wp codeception generate-(cept|cest) (acceptance|functional|unit) MyTestName

# Example
$ wp codeception generate-cept acceptance LoginTest

Afterwards you'll have a new file in your plugin or theme directory tests/acceptance/LoginTest.php, where you can write your first test. Remember, any Codeception test will work here! For example, you could run any of the acceptance test examples mentioned in the Codeception documentation. Likewise, the same goes for Functional and Unit tests.

Example: Writing a Login Acceptance Test

<?php

// Make sure you've added your site URL to acceptance.suite.yml
// @see http://codeception.com/docs/03-AcceptanceTests#PHP-Browser
$I = new AcceptanceTester( $scenario );
$I->wantTo( 'Ensure WordPress Login Works' );

// Let's start on the login page
$I->amOnPage( wp_login_url() );

// Populate the login form's user id field
$I->fillField( 'input#user_login', 'YourUsername' );

// Popupate the login form's password field
$I->fillField( 'input#user_pass', 'YourPassword' );

// Submit the login form
$I->click( 'Log In' );

// Validate the successful loading of the Dashboard
$I->see( 'Dashboard' );

Running Your Tests

Now you've written some tests, it's time to run them! But first..

Selenium

If you've created any browser automation/acceptance tests you'll need to turn Selenium on, and likewise, you'll want to stop Selenium after you're through running tests.

# You can run these commands from anywhere in your WordPress install
$ wp selenium start

# Stop Selenium when you're through
$ wp selenium stop

Run

You'll use the run command to execute your tests from within your plugin or theme directory (where you ran the bootstrap). We've implemented most of the Codeception 'run' command arguments, but if you find one we've missed please submit a Pull Request!

# You should be in the plugin or theme directory where you ran the bootstrap
$ wp codeception run

Example: Running our Login Test

# You should be in the plugin or theme directory where you ran the bootstrap
# Let's display verbose output
$ wp codeception run -vvv

Codeception PHP Testing Framework v2.0.11
Powered by PHPUnit 4.5.1 by Sebastian Bergmann and contributors.

  Rebuilding AcceptanceTester...

Acceptance-production Tests (1) ---------------------------------
Modules: WebDriver, WordPress, AcceptanceHelper
-----------------------------------------------------------------
Ensure WordPress Login Works (LoginTest)
Scenario:
* I am on page "http://site.com/wp-login.php"
* I fill field "input#user_login","YourUsername"
* I fill field "input#user_pass","YourPassword"
* I click "Login"
* I see "Dashboard"
 PASSED

Support Level

Archived: This project is no longer maintained by 10up. We are no longer responding to Issues or Pull Requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!

Like what you see?

68747470733a2f2f313075702e636f6d2f75706c6f6164732f323031362f31302f313075702d4769746875622d42616e6e65722e706e67

10up/wp-codeception 适用场景与选型建议

10up/wp-codeception 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.22k 次下载、GitHub Stars 达 102, 最近一次更新时间为 2015 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「BDD」 「TDD」 「unit testing」 「wordpress」 「functional testing」 「acceptance testing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 10up/wp-codeception 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 10up/wp-codeception 我们能提供哪些服务?
定制开发 / 二次开发

基于 10up/wp-codeception 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.22k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 103
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 102
  • Watchers: 121
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-11-05