我对 PHP 比较陌生,我正在尝试对命名空间中的一些代码进行单元测试。不幸的是,配置文件中的常量定义给我带来了问题。这是相关的代码。
目录结构为:
APITest
config.php
-/logging
-/test/logging
config.php 的代码:
<?php
namespace APITest;
define('BASE_DIR', pathinfo(__FILE__, PATHINFO_DIRNAME));
APITest/test/logging/TestLogItem的代码:
namespace APITest\test\logging;
require_once( BASE_DIR . '/logging/LogItem.php');
class TestLogItem extends PHPUnit_Framework_TestCase {
public function testLogItemCreationSuccess(){
code
}
public function testLogItemCreationException(){
code
}
public function testGetLogEntry(){
code
}
错误信息是:
PHP Notice: Use of undefined constant BASE_DIR - assumed 'BASE_DIR' in /var/test/APITest/test/logging/TestLogItem.php on line 6
PHP Warning: require_once(BASE_DIR/logging/LogItem.php): failed to open stream: No such file or directory in /var/test/APITest/test/logging/TestLogItem.php on line 6
PHP Fatal error: require_once(): Failed opening required 'BASE_DIR/logging/LogItem.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/test/APITest/test/logging/TestLogItem.php on line 6