4

I am using Composer for dependencies.

My project's dependencies require PHP 5.5 or later, so I want to test my project on PHP 5.5 - 7.2 (latest) with PHPUnit 7.

I set up Travis CI tests with different PHP versions:

language: php
php:
  - '5.5'
  - '5.6'
  - '7.0'
  - '7.1'
  - '7.2'
  - hhvm # on Trusty only
  - nightly

The problem is that the PHPUnit 7 requires PHP 7.1, so I can't test project on PHP 5.5 - 7.0.

I could test old PHP versions with old PHPUnit versions, but the problem is that after PHPUnit 6, PHPUnit's units of code are namespaced, so I will have to write different tests for PHPUnit 4 - 5 and PHPUnit 6 - 7.

How can I test my project on old PHP versions with PHPUnit 7 with Travis CI?

Filip Š
  • 746
  • 2
  • 13
  • 22
  • 1
    "the problem is that after PHPUnit 6, PHPUnit's units of code are namespaced, so I will have to write different tests for PHPUnit 4 - 5 and PHPUnit 6 - 7" is not true as PHPUnit 4.8 has the same forward compatibility layer as PHPUnit 5.6. TL;DR: `PHPUnit\Framework\TestCase` can be used with PHPUnit 4.8, PHPUnit 5.6, PHPUnit 6, and PHPUnit 7. – Sebastian Bergmann Jun 17 '18 at 12:36
  • 1
    @SebastianBergmann PHPUnit 8 now has return type declaration so old test cases are now incompatibile with it. What to do now? I still want to use same test cases for PHP 5.5+. – Filip Š Feb 09 '19 at 17:02

1 Answers1

3

Sebastian Bergmann noticed me that the PHPUnit 4.8 has forward compatibility, so I can use namespace syntax with PHPUnit 4.8, PHPUnit 5.6, PHPUnit 6, and PHPUnit 7.

"the problem is that after PHPUnit 6, PHPUnit's units of code are namespaced, so I will have to write different tests for PHPUnit 4 - 5 and PHPUnit 6 - 7" is not true as PHPUnit 4.8 has the same forward compatibility layer as PHPUnit 5.6. TL;DR: PHPUnit\Framework\TestCase can be used with PHPUnit 4.8, PHPUnit 5.6, PHPUnit 6, and PHPUnit 7. – Sebastian Bergmann

See PHPUnit 4.8 Changelog for details about forward compatibility.

Filip Š
  • 746
  • 2
  • 13
  • 22
  • 1
    I can confirm that if you write your tests for the latest Phpunit versions there a pretty little changes required to have them run w/ older Phpunit versions. On Travis it is possible to do variable downgrades for example w/ composer based installments, here an example: https://github.com/ktomk/pipelines/blob/master/.travis.yml#L28-L33 - or even back down to PHP 5.3: https://github.com/ktomk/pipelines/blob/master/bitbucket-pipelines.yml#L19-L27 - it works really well with little changes: https://github.com/ktomk/pipelines/blob/master/tests/unit/UnitTestCase.php#L25-L41 – hakre Jun 17 '18 at 19:46