Asked  11 Months ago    Answers:  5   Viewed   20 times

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    

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



I ran into the same issue and found the following solution in the documentation:

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:

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

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

Hope it helps.

Friday, July 30, 2021

Finaly i solve it! This is example of working code:

use SymfonyBundleFrameworkBundleTestWebTestCase;
use SymfonyComponentSecurityCoreAuthenticationTokenUsernamePasswordToken;
use SymfonyComponentBrowserKitCookie;

class ProfileControllerTest extends WebTestCase
    protected function createAuthorizedClient()
        $client = static::createClient();
        $container = static::$kernel->getContainer();
        $session = $container->get('session');
        $person = self::$kernel->getContainer()->get('doctrine')->getRepository('FoxPersonBundle:Person')->findOneByUsername('master');

        $token = new UsernamePasswordToken($person, null, 'main', $person->getRoles());
        $session->set('_security_main', serialize($token));

        $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId()));

        return $client;

    public function testView()
        $client = $this->createAuthorizedClient();
        $crawler = $client->request('GET', '/person/view');

Hope it helps to save your time and nerves ;)

Thursday, April 1, 2021

What I usually do is point my phpunit testing framework on PHPStorm to the secret .phpunit directory which was created by the bridge, like:

The location of the "phar" file is:


or in some cases:


After this, the specified phpunit executable will be called correctly when exeuting unit-tests, but with a --no-configuration option. This can cause autoloading problems (a lot of "class not found" errors), because the autoloader generated by Composer is not specified anywhere.

To fix this, you should have a phpunit.xml file in your project (this is common practice anyway), in which you specify Composer's autoloader, something like this:

<phpunit bootstrap="vendor/autoload.php">

This phpunit.xml should then be specified in the "Default configuration file" option and you should be good to go.

Regarding phpstorm using phpunit-bridge: It's possible as a custom script, but you won't have the nice interface and the possibility to run (and debug) specific tests via PHPStorm interface.

Thursday, April 1, 2021

It's my understanding that the mock should be replace the real WordPressBridge, but that isn't what's happening. My original is still being used. Am I missing something?

Basically you have to replace your service somehow in the Symfony Container.

If you doing "functional testing" then probably you should create test "dummy" service for "test" env which will overwrote original one. You can do something like that:

in src/YourBundle/Resources/config/services.yml

        class: %api.wp_bridge.class%
        arguments: [@service_container]

in app/config/config.yml

    api.wp_bridge.class: "ApiBundleUtilWordPressBridge"

in app/config/config_test.yml

    api.wp_bridge.class: "ApiBundleUtilTestWordPressBridge"

Then functional test will use "ApiBundleUtilTestWordPressBridge" - cause it is executed in "test" env.

You can try to mock container and pass it to test kernel but this can be painfull without some other mocking lib (in pure PHPUnit).

Personally I am using phpspec2 for "unit" testing where mocking is just easy :) and for some "acceptance criteria" stuff I am using behat and mink

Saturday, May 29, 2021

You can't access to the new entity manager because Symfony's client class shutdown's kernel before each request, which means that it erase whole service container and build it again from scratch.

So, after SECOND request you get very different entity manager than one you have in your own WebTestCase class. (I said after second because client shutdown's kernel only if any request has been already performed)

The question is - do you really need the same entity manafer in your WebTestCase class? Actually, you may want use the same entity manager because you want let say get controll over transaction between requests. But in this case you should create your own test client class extended symfony's one and there define static connection or entity manager, and put it into container before every request.

Look at example:

Saturday, May 29, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :