Why can't Eclipse include a file when running the PHPUnit test?

I have the following class and unit test in a PHP project in Eclipse:

alt text

I know that my unit test works , since I can run it on the command line:

alt text

Now I want to run this test from Eclipse. I created a PHP module in Eclipse as follows:

alt text

However, when I run the PHPUnit tests:

alt text

He tells me that he cannot 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 can PHPUnit find the class when it starts from the command line, but not when it starts from Eclipse?

+4
source share
2 answers

When you start something from the command line, the "current directory" has a clearly defined meaning: this is the directory in which you ran the command.

In Eclipse, what is the "current directory"? Perhaps this is the directory from which you started Eclipse, or perhaps the folder in which Eclipse is installed.

I have not used PHP in Eclipse before, but for other languages ​​I can set the current directory in the launch configuration somewhere. If this does not work, define a variable that points to your project, and then use absolute paths (using this variable as a starting point).

+3
source

Have the same problem. I only found a solution by creating tests using the internal PHPUnit wizard, as in this screenshot: phpunit test wizard. eclipse

Source: HowTo create test case class from PHP class

But the following research shows that your test case file should contain a link to the verified code, for example: require_once 'C:\Apache2\htdocs\jobeet\src\Ibw\JobeetBundle\Utils\Jobeet.php';

Other experiments with the plugin configuration do not bring good luck. So, in my opinion, PHPUnit from PHP Tools is not a well-developed plugin. Consider using the MakeGood plugin as a better alternative.

0
source

Source: https://habr.com/ru/post/1334231/