PHP-Simpletest-如何测试&x201C;包括”;班级 问题:
我正在尝试为Wordpress插件编写代码更改测试PHP-Simpletest-如何测试&x201C;包括”;班级 问题:,php,eclipse,wordpress,testing,simpletest,Php,Eclipse,Wordpress,Testing,Simpletest,我正在尝试为Wordpress插件编写代码更改测试 <?php require_once('.\simpletest\autorun.php'); require_once('.\wp-content\plugins\appointment-booking\includes.php'); // The line above causes [No runnable test cases in...] problem. // In my actual code, I have absolu
<?php
require_once('.\simpletest\autorun.php');
require_once('.\wp-content\plugins\appointment-booking\includes.php');
// The line above causes [No runnable test cases in...] problem.
// In my actual code, I have absolute path and I've made sure that the path is correct.
class test extends UnitTestCase
{
function test_pass()
{
$this->assertFalse(false);
}
}
?>
我希望不会看到坏的TestSuite错误。我希望它能够运行测试,就像第二个require_once被注释掉一样
我看到这里描述的这个问题:,但我不理解这个问题,也不知道如何解决。多谢各位
答复2016年3月25日
因为我无法将此问题从“暂停”状态中删除,也无法找到回答此问题的方法。我在这里写解决方案
Vincent的答案中的get_home_path()帮助我找到了原因,因此我将其标记为答案,尽管从技术上讲,它不是真正的答案。当我试图在我的代码中使用它时,我做不到-函数名和ABSPATH等没有定义。原因是它不被认为是WordPress的一部分
进一步搜索发现
调试发现我想要包含的WordPress文件有以下代码
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
我可以使用WordPress API和插件的代码编写测试用例,而不是第二个require_once,并且可以正确设置ABSPATH 使用绝对路径是危险的。您可以使用:
require_once(get_home_path() .'wp-content\plugins\appointment-booking\includes.php');
(如果您在Windows环境中)您是否可以更新qus,但有错误。答案不正确,但get_home_path()帮助我找到答案,因此标记为答案并将解决方案放入问题中。
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
require_once(get_home_path() .'wp-content\plugins\appointment-booking\includes.php');