为什么 Eclipse 在运行 PHPUnit 测试时无法包含文件?
我在 Eclipse 的 PHP 项目中有以下类和单元测试:
我知道我的单元测试有效,因为我可以在命令行运行它:
现在我想从 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 运行时?
I have the following class and unit test in a PHP project in Eclipse:
I know my unit test works as I can run it at the command line:
Now I want to run this test from Eclipse. I set up PHP Unit in Eclipse like this:
However, when I run the PHPUnit tests:
It tells me that it can't include the class file:
/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
Why would PHPUnit be able to find the class when run from the command line but not when run from Eclipse?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您从命令行启动某些内容时,“当前目录”具有明确定义的含义:它是您启动命令的目录。
在Eclipse中,什么是“当前目录”?它可能是您启动 Eclipse 的目录,也可能是安装 Eclipse 的文件夹。
我以前没有在 Eclipse 中使用过 PHP,但对于其他语言,我可以在启动配置中的某处设置当前目录。如果这不起作用,请定义一个指向您的项目的变量,然后使用绝对路径(使用该变量作为起点)。
When you start something from the command line, the "current directory" has a well-defined meaning: It's the directory where you started the command.
In Eclipse, what is the "current directory"? It's probably the directory from which you started Eclipse or maybe the folder in which Eclipse is installed.
I haven't used PHP in Eclipse before but for other languages, I can set the current directory in the launch config somewhere. If that doesn't work, define a variable which points to your project and then use absolute paths (using that variable as a starting point).
有同样的问题。通过使用内部 PHPUnit 向导创建测试找到了唯一的解决方案,如下屏幕截图所示:
来源:如何从 PHP 类创建测试用例类
但以下调查表明您的测试用例文件应包含对测试代码的引用,例如:
require_once ' C:\Apache2\htdocs\jobeet\src\Ibw\JobeetBundle\Utils\Jobeet.php';
插件配置的其他实验没有带来好运。所以我认为 PHP Tools 中的 PHPUnit 不是一个开发良好的插件。考虑使用 MakeGood 插件作为更好的选择。
Have same problem. Found only solution by creating tests with internal PHPUnit wizard like at this screenshot:
Source: HowTo create a Test Case Class from a PHP Class
But following investigate show that your test case file should contain reference to tested code for example like this:
require_once 'C:\Apache2\htdocs\jobeet\src\Ibw\JobeetBundle\Utils\Jobeet.php';
Other experiments with plugin config not bringing luck. So in my opinion PHPUnit from PHP Tools not well developed plugin. Consider using MakeGood plugin as better alternative.