7
votes

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.

My Setup

  • Ubuntu
  • PHPStorm 8.0.1
  • PHPUnit 4.3.4

More Info:

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.

PHPUnit Output:

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

EDIT

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>
5

5 Answers

11
votes

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.

6
votes

Sometimes is better an image...

enter image description here

As you can see, you can also use your phpunit.phar file.

5
votes

I will answer my own question in case someone else comes across this issue.

The issue was autoloading PHPUnit via composer and using phpunit.phar. Once I removed the phpunit dependence from composer PHPStorm was able to successfully run all my tests.

3
votes

The problem isn't that you autoloading phpunit via composer, but that in the composer you use an old version of phpUnit. In my case instead of using 4.0.0 I updated to 4.6.*.

0
votes

I've been having this same issue with composer and found using the .phar didnt have any issues. Today I've just realised slaps forehead it was just caused by installing phpunit via composer and then not reindexing the vendor folder.

I haven't found that I've had this issue previously when installing new packages with composer but for some reason when installing phpunit it hadn't reindexed the vendor folder causing inconsistencies.

Reindex, everything working normally.