5

Problem

I'm using Symfony 3.3.10 on PHP 7.0.25-0ubuntu0.16.04.1

By default this combination goes with phpunit 5.x.

But I want to force phpunit 6.x.

Context

When I invoke the vendor/bin/simple-phpunit for the first time, it installs phpunit/phpunit version 5.7.* as stated in the source code here:

https://github.com/symfony/phpunit-bridge/blob/v3.4.11/bin/simple-phpunit

lines 18-27:

if (PHP_VERSION_ID >= 70200) {
    // PHPUnit 6 is required for PHP 7.2+
    $PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5';
} elseif (PHP_VERSION_ID >= 50600) {
    // PHPUnit 4 does not support PHP 7
    $PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.7';
} else {
    // PHPUnit 5.1 requires PHP 5.6+
    $PHPUNIT_VERSION = '4.8';
}

As my version of PHP is 7.0 it chooses phpunit version 5.7.

Tried solution

I see I may "force" the bridge to go with phpunit 6.5 if I set it in the environment variable:

In a shell, I do:

rm -Rf vendor
export SYMFONY_PHPUNIT_VERSION=6.5
composer install
vendor/bin/simple-phpunit

Now I properly get: PHPUnit 6.5.8

Instead, if I logout and login again, it looses the env-var and the next invocation to vendor/bin/simple-phpunit and it forces to install a 5.7.

Don't tell me to put in the .bashrc

I already know I could set the env-var into my bash scripts and blah, blah, blah, but this is not an acceptable solution for two reasons:

  1. I maintain over 50 repositories. Having this set always in all shells might cause side-effects on other projects.
  2. If I make another developer to work on this repo, he should be able to do git clone + composer install + vendor/bin/simple-phpunit and it should be properly testing with no extra, manual, steps.

Question

Is it possible to tell the project (maybe something in the composer.json) to have some fancy setup so symfony's phpunit bridge is forced to use phpunit 6.x (for example 6.5) over the 5.7 version for all installs of the repo and not depending on anything global external to the repo?

Xavi Montero
  • 9,239
  • 7
  • 57
  • 79

1 Answers1

6

Since version 4.1 you can configure this in phpunit.xml/phpunit.xml.dist:

<php>
    <env name="SYMFONY_PHPUNIT_VERSION" value="6.5" />
</php>
rob006
  • 21,383
  • 5
  • 53
  • 74
  • version 4.1 of symfony? or version 4.1 of phpuunit itself? – Xavi Montero Jun 03 '18 at 10:40
  • Version 4.1 of `symfony/phpunit-bridge` - https://github.com/symfony/phpunit-bridge/blob/v4.1.0/CHANGELOG.md#410 – rob006 Jun 03 '18 at 10:59
  • Ah ok... I see. I'm currenly requiring `"symfony/phpunit-bridge": "^3.0"` in my composer. If I upgrade the major, are there any risks to break all? I mean... is bridge 3 thought for symfony 3 and bridge 4 thought for symfony 4? Or symfony 3 may run safely with bridge 4 without expecting too much to break? – Xavi Montero Jun 03 '18 at 11:56
  • I have no idea about BC breaks, but Symfony 3.4.10 has `symfony/phpunit-bridge: ~3.4|~4.0` in their `require-dev`, so I guess it should work fine. https://packagist.org/packages/symfony/symfony#v3.4.10 – rob006 Jun 03 '18 at 12:16
  • I use `bin/phpunit` which is installed by `symfony/phpunit-bridge: 4.2.4`. I tried your method to set the phpunit version to 7.5, but it doesn't work. The only working way is to set the version in `bin/phpunit` on the line `putenv('SYMFONY_PHPUNIT_VERSION=7.5')`. Do you know why is it like that? – yifei3212 Mar 31 '19 at 23:21