Whenever I run phpunit tests from PHPStorm I get an error. I have provided more info below. I am not sure where I have miss configured the setup.
PHPUnit.phar is located at /usr/local/bin/phpunit.phar
. I have setup PHPUnit path directly in PHPStorm. Tests run from bash with no issues. I have also setup my configuration file phpunit.xml
in PHPUnit, which is located in the root of my project. The phpunit.xml
file tells phpunit to load the composer autoload.php
file.
/usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 /tmp/ide-phpunit.php --configuration /home/mkelley/projects/CompanyName/phpunit.xml
Testing started at 10:33 AM ...
PHPUnit 4.3.4 by Sebastian Bergmann.
Configuration read from /home/mkelley/projects/CompanyName/phpunit.xml
PHP Fatal error: Call to undefined method CompanyNameTests\Boundaries\BoardMemberVotingBoundaryTest::hasExpectationOnOutput() in phar:///usr/local/bin/phpunit.phar/phpunit/TextUI/ResultPrinter.php on line 545
PHP Stack trace:
PHP 1. {main}() /tmp/ide-phpunit.php:0
PHP 2. IDE_Base_PHPUnit_TextUI_Command::main($exit = *uninitialized*) /tmp/ide-phpunit.php:500
PHP 3. PHPUnit_TextUI_Command->run($argv = *uninitialized*, $exit = *uninitialized*) /tmp/ide-phpunit.php:243
PHP 4. PHPUnit_TextUI_TestRunner->doRun($suite = *uninitialized*, $arguments = *uninitialized*) phar:///usr/local/bin/phpunit.phar/phpunit/TextUI/Command.php:186
PHP 5. PHPUnit_Framework_TestSuite->run($result = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:423
PHP 6. PHPUnit_Framework_TestSuite->run($result = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/Framework/TestSuite.php:703
PHP 7. PHPUnit_Framework_TestCase->run($result = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/Framework/TestSuite.php:703
PHP 8. PHPUnit_Framework_TestResult->run($test = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/Framework/TestCase.php:771
PHP 9. PHPUnit_Framework_TestResult->endTest($test = *uninitialized*, $time = *uninitialized*) /home/mkelley/projects/CompanName/vendor/phpunit/phpunit/src/Framework/TestResult.php:760
PHP 10. PHPUnit_TextUI_ResultPrinter->endTest($test = *uninitialized*, $time = *uninitialized*) /home/mkelley/projects/CompanyName/vendor/phpunit/phpunit/src/Framework/TestResult.php:378
Process finished with exit code 255
I have searched Google and was unable to find a similar issue. I appreciate any help!
Here is my phpunit.xml file. PHPStorm is using this as a "Use alternative configuration file"
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
bootstrap="./vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
This appears to be the autoloading issue. When you bootstrap your app for the test suite you must initialise your autoloader, which doesn't seem to be happening, as something doesn't get found. The easiest way would be to use Composer to manage the PHPUnit dependency and autoload your classes via the autoload
directive. See the the psr-4
part in documentation.
Then in your PhpStorm PHPUnit configuration window select Use custom autoloader
and specify path to your vendor/autoload.php
script.
Sometimes is better an image...
As you can see, you can also use your phpunit.phar
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With