24. ユニットテストを書いてみよう
# VCCWにログイン
$ vagrant ssh
# プラグインのディレクトリに移動
[vccw]$ cd /var/www/wordpress/wp-content/plugins/sample-plugin
# テスト実行
[vccw]$ phpunit
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests... To execute these, use --group ajax.
PHPUnit 4.3.1 by Sebastian Bergmann.
Configuration read from /var/www/wordpress/wp-content/plugins/sample-plugin/phpunit.xml
∼ 省略 ∼
FAILURES!
Tests: 2, Assertions: 2, Failures: 2.
プラグインのコードを書いていないので当然エラー…
34. プラグインを作成してみよう
# VCCWにログイン
$ vagrant ssh
# プラグインのディレクトリに移動
[vccw]$ cd /var/www/wordpress/wp-content/plugins/sample-plugin
# テスト実行
[vccw]$ phpunit
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests... To execute these, use --group ajax.
PHPUnit 4.3.1 by Sebastian Bergmann.
Configuration read from /var/www/wordpress/wp-content/plugins/sample-plugin/phpunit.xml
Time: 1.43 seconds, Memory: 12.00Mb
OK (2 tests, 2 assertions)
緑のメッセージならテストクリア
46. リポジトリにプッシュしてTravis CIで自動
的にテストが実行されることを確認しよう
# 変更をコミット
[vccw]$ git commit -m "first commit”
Committer: vagrant <vagrant@2inc.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
6 files changed, 260 insertions(+), 0 deletions(-)
create mode 100644 bin/install-wp-tests.sh
create mode 100644 phpunit.xml
create mode 100644 readme.txt
create mode 100644 sample-plugin.php
create mode 100644 tests/bootstrap.php
create mode 100644 tests/test-sample.php
47. リポジトリにプッシュしてTravis CIで自動
的にテストが実行されることを確認しよう
# リモートリポジトリを設定
[vccw]$ git remote add origin git@github.com:example/sample-plugin.git
# リモートリポジトリにプッシュ
[vccw]$ git push -u origin master
Warning: Permanently added the RSA host key for IP address
‘xxx.xx.xxx.xxx’ to the list of known hosts.
Counting objects: 10, done.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (10/10), 4.28 KiB, done.
Total 10 (delta 0), reused 0 (delta 0)
To git@github.com:example/sample-plugin.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
GitHubのリポジトリの情報に
合わせてください。