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.

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

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行