phpunit.xml 似乎不起作用

发布于 2024-10-09 21:14:53 字数 2189 浏览 0 评论 0原文

我试图让这个测试

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>

我读过的所有内容似乎都说这应该起作用

I have bee trying to get this test to run

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.');
    }

}

on this Command

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

but keep geting the error message

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

I am using a phpunit.xml to try to set the $_SERVER['HTTP_HOST'] but seem like it is not working at all

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

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

Everything I have read seem to say this should work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强辩 2024-10-16 21:14:53

据我所知,xml 看起来很好。两个建议:

class DivisionTest extends PHPUnit_Framework_TestCase
{
    public function Divisiontest()

我将函数名称更改为 testDivision() ,以便 phpunit 将其作为真正的测试(代码得到执行,因为它的名称类似于类(又名 php 4 样式构造函数),但那就是不是真正的最佳)

如果这不能解决您的问题:当您

$_SERVER['HTTP_HOST'] = "DEV";

在声明之前

$division = new division();

添加它时它会起作用吗?只是为了确保错误是 xml 文件未被读取并且没有隐藏在其他地方

The xml looks fine as far as i can see it. Two suggestions:

class DivisionTest extends PHPUnit_Framework_TestCase
{
    public function Divisiontest()

i'd change the function name to testDivision() so phpunit picks it up as a real test (the code gets execution because its named like the class (a.k.a. php 4 style constructor) but thats not really optimal)

If that doesn't fix your problem: Does it work when you put

$_SERVER['HTTP_HOST'] = "DEV";

before the

$division = new division();

statement ? Just to make sure the error is that the xml file isn't read and doesn't hide somewhere else

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文