【问题标题】:Why would Eclipse not be able to include a file when running a PHPUnit test?为什么在运行 PHPUnit 测试时 Eclipse 不能包含文件?
【发布时间】:2011-01-04 16:06:50
【问题描述】:

我在 Eclipse 的一个 PHP 项目中有以下 classunit test

我知道我的单元测试有效,因为我可以在命令行运行它:

现在我想从 Eclipse 运行这个测试。我在 Eclipse 中这样设置 PHP 单元:

但是,当我运行 PHPUnit 测试时:

它告诉我它不能包含类文件:

/usr/bin/php -c /var/folders/UA/UAv38snBHd0QMgEPMCmM9U+++TM/-Tmp-/zend_debug/session4910937990995915704.tmp -d asp_tags=off /Applications/eclipse/plugins/org.phpsrc.eclipse.pti.tools.phpunit_0.5.0.R20101103000000/php/tools/phpunit.php --log-junit /var/folders/UA/UAv38snBHd0QMgEPMCmM9U+++TM/-Tmp-/pti_phpunit/phpunit.xml /Volumes/data/domains/et/extjslayout/phpunittest/tests
PHP Warning:  include_once(../Product.php): failed to open stream: No such file or directory in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 3
PHP Warning:  include_once(): Failed opening '../Product.php' for inclusion (include_path='/usr/local/PEAR') in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 3
PHP Fatal error:  Class 'Product' not found in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 9

为什么 PHPUnit 从命令行运行时能找到类,而从 Eclipse 运行时却不能?

【问题讨论】:

    标签: eclipse phpunit


    【解决方案1】:

    当您从命令行启动某些内容时,“当前目录”具有明确定义的含义:它是您启动命令的目录。

    在 Eclipse 中,什么是“当前目录”?它可能是您启动 Eclipse 的目录,也可能是安装 Eclipse 的文件夹。

    我之前没有在 Eclipse 中使用过 PHP,但是对于其他语言,我可以在启动配置中的某个地方设置当前目录。如果这不起作用,请定义一个指向您的项目的变量,然后使用绝对路径(使用该变量作为起点)。

    【讨论】:

      【解决方案2】:

      有同样的问题。通过使用内部 PHPUnit 向导创建测试找到唯一的解决方案,如下图所示:

      来源:HowTo create a Test Case Class from a PHP Class

      但以下调查表明,您的测试用例文件应包含对测试代码的引用,例如:require_once 'C:\Apache2\htdocs\jobeet\src\Ibw\JobeetBundle\Utils\Jobeet.php';

      其他插件配置实验没有带来好运。所以在我看来,来自 PHP Tools 的 PHPUnit 不是很好开发的插件。考虑使用 MakeGood 插件作为更好的选择。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-21
        • 1970-01-01
        • 1970-01-01
        • 2016-04-18
        • 2016-05-19
        • 2014-12-23
        • 2023-01-09
        • 2012-10-19
        相关资源
        最近更新 更多