PHPUnitによる自動テスト

WordPress公式が提供する「WP-CLI Scaffold」コマンドを使うと、テスト環境の雛形を自動生成できます。

wp scaffold plugin-tests my-plugin
cd my-plugin
composer install
bin/install-wp-tests.sh wordpress_test root '' localhost latest
phpunit
<?php
class MyPluginTest extends WP_UnitTestCase {
    public function test_addition_function_returns_correct_sum() {
        $result = my_plugin_add(2, 3);
        $this->assertEquals(5, $result);
    }
}

デバッグツールの活用

<?php
error_log(print_r($my_variable, true));

ステージング環境でのテスト

本番環境で直接テストしない特にデータベース操作を伴うテストは、本番環境とは別のステージング環境(またはローカル環境)で行ってください。

関連コンテンツ

↑