dqsk4643 2015-03-04 18:44
浏览 55
已采纳

PHPUnit使用require_once和$ SERVER变量在Object Constructor上神秘失败

I'm trying to wrap a test class around a pre-existing PHP class file that does not adhere to any PSR standard.

The PHP object I'm trying to test has a constructor that accepts 1 argument.

When prepping my object in setUp, my test correctly fails because there is a constructor argument missing. Because of this, I feel good that my object is being correctly resolved.

protected function setUp() {
    $this->object = new HierarchyChange();
}

However, when I do add a value:

$this->object = new HierarchyChange('username');

NetBeans throws a "Perhaps error occurred, verify in Output window" message when I run the tests. And the output window has no information.

Executing "phpunit . -v" from the command line simply outputs the PHPUnit version I'm working with, but does not show any exception information.

I've tracked the failing line in my HierarchyChange class to this line in the class constructor:

public function __construct($agent_manager)
    {

        /* require contracting base class */
        require_once($_SERVER['DOCUMENT_ROOT'] . '/_inc/oc.class.php');

I've tried a number of different ways to add this file, thinking that the server variable was causing the problem, but even removing it and hardcoding the path in the constructor cause the test suite to crash.

It DOES, however, work when I comment out the require_once line completely.

It doesn't make sense to me why this fails, but I am grasping at straws with this. Thanks.

  • 写回答

1条回答 默认 最新

  • dongzhenge2014 2015-04-09 19:24
    关注

    The issue stemmed from a few things:

    1. incorrect configuration of PHP.ini (error messages were not being raised), but more importantly:
    2. incorrectly setting server vars; I ended up modifying the phpunit.xml configuration file to include:

    Since the tests were being executed via CLI, these server variables are not available, so they needed to be set. And when phpunit encountered this as an error, NetBeans didn't know how to report it in the output window because the local INI configuration was not set to do so.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan