phpunit.xml似乎没有用

时间:2011-01-04 00:15:35

标签: php configuration phpunit

我试图让这个测试运行

require_once 'PHPUnit/Framework.php';
require_once('../config/config.php');
require_once('../classes/division.class.php');

class DivisionTest extends PHPUnit_Framework_TestCase
{
    public function Divisiontest()
    { 
     $division = new division();
     try{
      $division->createDivisionDetails();
     }catch (CustomException $e) {
   return;
  }
     $this->fail('An expected exception has not been raised.');
    }

}

在此命令

phpunit --configuration = phpunit.xml division.test.php

但请继续提交错误消息

PHP Notice:  Undefined index: HTTP_HOST in /home/workspace/people_scope/config/config.php on line 13

Notice: Undefined index: HTTP_HOST in /home/workspace/people_scope/config/config.php on line 13
PHP Notice:  Undefined index: HTTP_HOST in /home/workspace/people_scope/config/config.php on line 26

Notice: Undefined index: HTTP_HOST in /home/workspace/people_scope/config/config.php on line 26
PHP Warning:  require_once(/people_scope/config/standard.inc.php): failed to open stream: No such file or directory in /home/workspace/people_scope/config/config.php on line 46

Warning: require_once(/people_scope/config/standard.inc.php): failed to open stream: No such file or directory in /home/workspace/people_scope/config/config.php on line 46
PHP Fatal error:  require_once(): Failed opening required '/people_scope/config/standard.inc.php' (include_path='/usr/bin:.:/usr/share/php:/usr/share/pear:/people_scope/assets/PEAR/:/people_scope/classes/base/') in /home/workspace/people_scope/config/config.php on line 46

Fatal error: require_once(): Failed opening required '/people_scope/config/standard.inc.php' (include_path='/usr/bin:.:/usr/share/php:/usr/share/pear:/people_scope/assets/PEAR/:/people_scope/classes/base/') in /home/workspace/people_scope/config/config.php on line 46

我正在使用phpunit.xml尝试设置$ _SERVER ['HTTP_HOST'],但似乎根本无法正常工作

<?xml version="1.0" encoding="utf-8" ?>

<phpunit>
        <php>
                <server name="HTTP_HOST" value="DEV"/>
        </php>
</phpunit>

我读过的所有内容似乎都说这应该有效

1 个答案:

答案 0 :(得分:1)

就我所见,xml看起来很好。两个建议:

class DivisionTest extends PHPUnit_Framework_TestCase
{
    public function Divisiontest()

我将函数名称更改为testDivision()所以phpunit选择它作为一个真正的测试(代码得到执行,因为它的命名类似于类(也就是php 4样式构造函数),但那不是真正的最佳)< / p>

如果这不能解决你的问题:当你输入

时它是否有用
$_SERVER['HTTP_HOST'] = "DEV";

之前的

$division = new division();
声明?只是为了确保错误是xml文件没有被读取而且没有隐藏在其他地方