为什么 Eclipse 在运行 PHPUnit 测试时无法包含文件?

发布于 2024-10-10 10:42:37 字数 1477 浏览 0 评论 0原文

我在 Eclipse 的 PHP 项目中有以下单元测试

alt text

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

 alt text

现在我想从 Eclipse 运行此测试。我在 Eclipse 中设置 PHP 单元,如下所示:

alt text

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

alt text

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

/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:

alt text

I know my unit test works as I can run it at the command line:

alt text

Now I want to run this test from Eclipse. I set up PHP Unit in Eclipse like this:

alt text

However, when I run the PHPUnit tests:

alt text

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 技术交流群。

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

发布评论

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

评论(2

终难愈 2024-10-17 10:42:37

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

在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).

空心↖ 2024-10-17 10:42:37

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

来源:如何从 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:
phpunit test wizard. eclipse

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.

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