Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force symfony's phpunit bridge to use phpunit 6.5 instead of 5.7?

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?

like image 893
Xavi Montero Avatar asked Jun 02 '18 23:06

Xavi Montero


1 Answers

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

<php>
    <env name="SYMFONY_PHPUNIT_VERSION" value="6.5" />
</php>
like image 127
rob006 Avatar answered Oct 19 '22 10:10

rob006