LoginSignup
1
1

More than 5 years have passed since last update.

functions.phpのテストを書く

Last updated at Posted at 2019-02-20

functions.phpのテストコードを書きたいが、ローカルにWordPressを入れていないので、 functions.phprequire すると、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);
    }
}

名前やパスはそれぞれの環境にあわせてよしなにする。

なんかもっと良い方法があったら教えてください。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1