Trickylastname
Trickylastname

Reputation: 145

Phpunit tries to test all Symfony console commands

I'm working on a Symfony project. As I need to do unit testing, I downloaded and installed Phpunit 6.2.4 from its website. However, when I tried to update my database, I got this output

php bin/console doctrine:schema:update --dump-sql
PHPUnit 6.2.4 by Sebastian Bergmann and contributors.

unrecognized option --dump-sql

bin/console doctrine:schema:update
Cannot open file "doctrine:schema:update.php".

I tried other console commands, but the result is the same. Basically, my guess was that somehow Phpunit tries to test every single file, so I edited the phpunit.xml file like this, using a previous one that worked in other project.

<?xml version="1.0" encoding="UTF-8"?>

<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="app/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="KERNEL_DIR" value="app/" />
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory suffix=".php">tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory suffix=".php">src</directory>
            <exclude>
                <directory>src/*Bundle/Resources</directory>
                <directory>src/*/*Bundle/Resources</directory>
                <directory>src/*/Bundle/*Bundle/Resources</directory>
            </exclude>
        </whitelist>
        <blacklist>
            <directory>bin</directory>
            <directory>docker</directory>
        </blacklist>
    </filter>
</phpunit>

As far as I know, blacklisting both bin and docker directories should result in phpunit not running anything inside them, but it still doesn't work.

Then I checked my composer.json for the symfony/phpunit-bridge, removed it and tried again, but the problem continues.

Has anyone ever faced this?

Upvotes: 1

Views: 186

Answers (1)

Alister Bulman
Alister Bulman

Reputation: 35169

Blacklisting appear to remove directories from the code-coverage generation whitelist - but if src/ does not contain those sub-directories, and so it is redundant - and also a great deal slower adding and discarding huge numbers of files. On one project, I tried to blacklist vendor/, it was taking a minute to even show the initial command banner, before starting to run the tests.

Remove the <blacklist/> section, and the rest should be fine - if you don't mention bin/ or docker/ then PHPunit won't need to read the files, it so won't run them either.

Upvotes: 0

Related Questions