我正在使用别人的源代码 ecshop 开发一个网站,这是一个电子商务网站。我想使用 PHPUnit 对我的代码进行单元测试,但遇到了问题。这是错误的样子:
C:\Users\maoqiuzi\Documents\Shanglian\XinTianDi\xintiandi\admin>phpunit --stderr wang_test.php PHPUnit 3.7.27 by Sebastian Bergmann。
乙
时间:1.03 秒,内存:6.75Mb
有 1 个错误:
1) ShopTest::test_get_shop_name 未定义索引:ecs
C:\Users\maoqiuzi\Documents\Shanglian\XinTianDi\xintiandi\includes\lib_common.ph p:564 C:\Users\maoqiuzi\Documents\Shanglian\XinTianDi\xintiandi\admin\includes\init.ph p:147 C: \Users\maoqiuzi\Documents\Shanglian\XinTiandi\xintiandi\admin\wang.php:10 C:\Users\maoqiuzi\Documents\Shanglian\XinTianDi\xintiandi\admin\wang_test.php:10
失败!测试:1,断言:0,错误:1。
wang_test.php的源代码:
<?php
require_once("wang.php");
class ShopTest extends PHPUnit_Framework_TestCase
{
public function test_get_shop_name()
{
$shop = new Wang();
$first_row_of_shop_list = $shop->get_shop_list();
}
}
wang.php的源代码:
<?php
class Wang
{
private $exchange;
function get_shop_list()
{
define("IN_ECS", 1);
require(dirname(__FILE__).'/includes/init.php');
$this->exchange = new exchange($GLOBALS['ecs']->table('shop'), $GLOBALS['db'], 'shop_id', 'shop_name');
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('shop');
$shop_list = $GLOBALS['db']->getAll($sql);
if($shop_list != array())
return $shop_list;
else
return array();
}
}
init.php 中的代码
require(ROOT_PATH . 'includes/lib_common.php');
class ECS //line 82
{
var $db_name = '';
var $prefix = 'ecs_';
function ECS($db_name, $prefix)
{
$this->db_name = $db_name;
$this->prefix = $prefix;
}
...
}
...
$ecs = new ECS($db_name, $prefix); // line 114
... // other initialization codes here
$_CFG = load_config(); //line 147
lib_common.php 中的代码
function load_config()
{
$arr = array();
$data = read_static_cache('shop_config');
if ($data === false)
{
$sql = 'SELECT code, value FROM ' . $GLOBALS['ecs']->table('shop_config') . ' WHERE parent_id > 0';
$res = $GLOBALS['db']->getAll($sql);
...
}
我已经为此工作了几天,感到非常沮丧。希望有人帮助我!谢谢!!!