7

I'm having trouble getting phpunit working inside of a Symfony project in PhpStorm - phpunit -c app works fine in the OSX terminal.

Here is the error:

Unable to attach test reporter to test framework of test framework quit unexpectedly
/Applications/MAMP/bin/php/php5.4.4/bin/php/private/var/folders/4l/hw8g4qlj6nnc37lfkc6hcj7w0000gn/T/ide-phpunit.php --bootstrap
/Users/greg/Repos/MyApp/app/bootstrap.php.cache --configuration    
/Users/greg/Repos/MyApp/app/phpunit.xml.dist
MyApp\MyBundle\Tests\Controller\MyControllerTest 
/Users/greg/Repos/MyApp/src/HvH/MyBundle/Tests/Controller/MyControllerTest.php

Testing started at 11:45 AM ...

Process finished with exit code 255

Edit: Here is the error from the PHP log:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The "app/" directory does not exist.' in /Users/greg/Repos/MyApp/vendor/symfony/symfony/src/Symfony/Component/Finder/Finder.php:650
3
  • 2
    Possible things: 1) PHP is out of memory (unlikely; I think it will have different exit code); 2) (most likely) PHP is unable to find some file that was required to load (check php error log for possible details) Commented Apr 25, 2013 at 20:51
  • 1
    Found the error, not sure how to fix though, the directory definitely exists... PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The "app/" directory does not exist.' in /Users/greg/Repos/MyApp/vendor/symfony/symfony/src/Symfony/Component/Finder/Finder.php:650 Stack trace: Commented Apr 26, 2013 at 23:07
  • Check access rights / owner; not just for the folder, but all files inside as well (not a Mac/Linux user .. but that is the first thing that comes into my mind) Commented Apr 27, 2013 at 0:00

4 Answers 4

7

I ran into the same issue and found the following solution in the documentation: http://symfony.com/doc/current/book/testing.html#your-first-functional-test

To run your functional tests, the WebTestCase class bootstraps the kernel of your application. In most cases, this happens automatically. However, if your kernel is in a non-standard directory, you'll need to modify your phpunit.xml.dist file to set the KERNEL_DIR environment variable to the directory of your kernel:

<phpunit>
    <!-- ... -->
    <php>
        <server name="KERNEL_DIR" value="/path/to/your/app/" />
    </php>
    <!-- ... -->
</phpunit>

So check your phpunit.xml.dist configuration file and try to add the absolute path to your app-directory.

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

This answer will get the tests to start but any other relative path you may use in the test (such as opening a JSON file) will still fail.
2

PhpStorm does not always instantiate the test runner from the project root, to fix this add the absolute path to the project root under 'custom working directory' in the run/debug config. This will save you having to add the absolute path to the app in the phpunit.xml.dist config, it will also ensure that any relative path file includes (such as JSON test data) can be found.

Comments

2

Steps to make it work (test in PHPStorm 8.0.1):

1) In Preferences > PHP > PHPUnit make sure that nothing is set for Default configuration file or default bootstrap file.

2) Make a custom PHPUnit Configuration via Run > Edit Configurations > in the Command Line subsection, and be sure to:

a) set Custom working directory: to be /absolute/path/to/vendor.

b) check "Use alternative configuration file:" and set it to /absolute/path/to/vendor/your_app/(sub_app_if_applicable)/phpunit.xml.dist

Then you can run any test class in the suite by specifying the class and file, or just check "Defined in the configuration file" to run all of them according to the config.

Comments

0

I ran into the same issue. If you are using yii2/phpStorm, try to select codeception.yml instead unit.yml under 'alternative configuration file' in the debug configuration section.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.