Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 4, PHPUnit Bridge and phpunit location

If you install phpunit/phpunit package in Symfony 4 application, you get the message:

Adding phpunit/phpunit as a dependency is discouraged in favor of Symfony's PHPUnit Bridge.

  • Instead:
    1. Remove it now: composer remove --dev phpunit/phpunit
    2. Use Symfony's bridge: composer require --dev phpunit

So, I installed symfony/phpunit-bridge package.
It created bin/phpunit file and vendor/bin/simple-phpunit.

  • If I run bin/phpunit, it downloads phpunit project and installs its dependencies in bin/.phpunit/phpunit-6.5.
  • If I run vendor/bin/simple-phpunit, it downloads phpunit project and installs its dependencies in vendor/bin/.phpunit/phpunit-5.7.

Note that the versions are not the same. Why?
And why to not use composer and its autoloader? Now we have troubles with it and other tools like PHPStorm (broken phpunit debugging, etc).
I know, that I can add phpunit path to main composer autoload, but this method seems very dirty.

How to use phpunit in Symfony 4 proper way, with all debugging integrations, etc?

like image 625
Dmitry Avatar asked Nov 07 '22 02:11

Dmitry


1 Answers

I have managed to fix this issue by adding phpunit.xml.dist in the root of the Symfony.

The file existed previously but I suspect that when I did remove phpunit, it also removed this file.. (I could be wrong but I am pretty certain)

When I add back the standard phpunit.xml.dist file to the root, it prompts me to add 'KERNEL_CLASS' variable in it.

When I add it in, it started working fine.

Full contents of my phpunit.xml.dist in case someone needs it

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
     backupGlobals="false"
     colors="true"
     bootstrap="vendor/autoload.php"
>
<php>
    <ini name="error_reporting" value="-1" />
    <server name="KERNEL_CLASS" value="App\Kernel" />
</php>

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

<filter>
    <whitelist>
        <directory>src</directory>
    </whitelist>
</filter>

<listeners>
    <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
</phpunit>
like image 70
hsb1007 Avatar answered Dec 17 '22 19:12

hsb1007