hjfcb Hfhbv
hjfcb Hfhbv

Reputation: 61

setting phpunit command from the console symfony

I have already posted this question on php unit first test symfony I installed phpunit via the composer as a per project installation. When trying vendor/bin>phpunit -c ../../app every thing is ok and I get a positive answer. Whereas this command give the answer to all the tests in the tests directory.

But I want the result to every test alone. When trying /vendor/bin>phpunit -c ../../src/xxx/Bundle/tests/entity/yyy.php and I get the following message : could not load c:\wamp\www\symfony\src/xxx/Bundle/tests/entity/yyy.php Parse PI : PI php never end ... Start ttag expected, '<' not found

and when trying /vendor/bin>phpunit -c ../../src/xxx/Bundle/tests/entity/yyy and I get the following message : could not read "..\..\src/xxx/Bundle/tests/entity/yyy"

Could anybody help me to know how should I write the command and from where execute it??? Any ideas???

Upvotes: 3

Views: 7879

Answers (2)

airton
airton

Reputation: 1

Happened with me too, but in fact we are misreading the documentation you are forgetting 'app' in the command line look:

phpunit -c app src/AppBundle/Tests/Util/CalculatorTest.php

Note the app parameter in command sentence.

Upvotes: 0

Wouter J
Wouter J

Reputation: 41934

Don't use the -c option here. The -c option is a shortcut for --configuration and it points to the directory of a PHPunit configuration file (like app/phpunit.xml.dist). That configuration tells PHPunit where to look for the test classes and some other configuration, like the bootstrap file.

If you want to run tests for a specific test, you can do it like phpunit path/to/tests/MyTest.php. But you'll loose the autoloading then. To get that back, you can use the --bootstrap option to point to the bootstrap file. So it'll be phpunit --bootstrap vendor/autoload.php path/to/tests/MyTest.php.

If you want to run this command more often, you can better edit the app/phpunit.xml.dist file and create a new suite:

<?xml version="1.0" encoding="utf-8" ?>
<phpunit ...>
    <!-- ... -->

    <testsuites>
        <testsuite name="MyBundle">
            <file>path/to/tests/MyTest.php</file>
        </testsuite>
    </testsuites>

    <!-- ... -->
</phpunit>

And then run: phpunit -c app --testsuite MyBundle

Upvotes: 12

Related Questions