functions.phpのテストコードを書きたいが、ローカルにWordPressを入れていないので、 functions.php
を require
すると、WordPressの関数を実行するところで Call to undefined function
がでる。なので、スタブを作って include
する。
wp_global_functions.php
<?php
//functions.phpで使用されるWordPressの関数を定義しておく
function add_action()
{
return true;
}
function add_filter()
{
return true;
}
function add_shortcode()
{
return true;
}
functionsPHPTest.php
<?php
namespace TestCase;
include_once __DIR__ . '/wp_global_functions.php';
require_once __DIR__ . '/functions.php';
class functionsPHPTest extends \PHPUnit\Framework\TestCase
{
function testHoge()
{
$hoge = functionInFunctionsPHP();
$this->assertNotNull($hoge);
}
}
名前やパスはそれぞれの環境にあわせてよしなにする。
なんかもっと良い方法があったら教えてください。