[dev] PHPUnit 9.5 compat

Ralf Lang lang at b1-systems.de
Mon Mar 29 06:18:10 UTC 2021


Hi Jan,

Am 28.03.2021 um 13:28 schrieb Jan Schneider:
>
> Zitat von Jan Schneider <jan at horde.org>:
>
>> Zitat von Ralf Lang <lang at b1-systems.de>:
>>
>>> Hello,
>>>
>>> Am 02.03.21 um 21:07 schrieb Ralf Lang:
>>>> Hello,
>>>>
>>>> I added some changes to make Horde_Test compatible with phpunit 9.5.
>>>>
>>>> This will not magically make all test suites run though.
>>>>
>>> I have fixed a minor glitch in Horde_Test_Functional breaking
>>> Horde_View
>>> unit tests in phpunit 9.5.
>>>
>>> A colleague and I began converting some library unit tests to
>>> phpunit 9.
>>>
>>> This meant
>>>
>>> - Namespacing unit tests, test base classes, mocks and test helpers.
>>> - Sometimes changing assert methods or method signatures to newer
>>> standards
>>> - amending risky assertion-less tests to tests containing assertions.
>>> - turning try/catch blocks into expectException.
>>> - turning unconditional requires into conditional requires.
>>> - other upgrade work
>
> Oh, and is any of this compatible with earlier PHPUnit/PHP versions?

It depends which unit tests and what version. Most tests should run just
fine with PHPUnit 8. Nothing will run with phpunit 4.

phpunit 8 and 9 are in support, phpunit 10 is coming.
https://phpunit.de/supported-versions.html


Major breaks are:
- PHPUnit uses namespaces since around v6 and has dropped support
unnamespaced.
- Mocks are now built using a MockBuilder or a shorthand method, but no
longer through the many-arguments method on Test.
- Some test methods have been deprecated or replaced by others.

As for PHP versions, I was updating code as I touched it, mostly adding
return types and type hints (including strings). This would

*Both the unit tests and the actual code should run fine on 7.2 (phpunit
8 only), 7.3, 7.4. **
*

However, currently I have an added dependency for Horde_Test on PHPUnit
9 and composer would not install it on 7.2 which does not support
phpunit 9. I need to remove that dependency to make multiversion work again.


> Or should we simply ignore older versions in master and keep those to
> FW_5?
I think PHPUnit 4 should be restricted for supporting the pear based
branches/FW_5.

I see no advantage in supporting very old phpunit versions for recent
code. It would be quite an effort and would make tests harder to read,
understand, maintain.


>>> While parts of it could be semi-automated using the rector tool,
>>> most is
>>> manual work.
>>>
>>> Next in line should be building a horde-components qc runner github
>>> action which can run on push or PR. And of course, converting all the
>>> remaining tests.
>>
>> Regarding the different PHPUnit versions that have different
>> compatibility with the PHP versons we support, I have played a bit
>> with dependencies and different major versions in the past:
>>
>> https://github.com/yunosh/phpunit-1 contains several major versions
>> with different dependencies on PHP and PHPUnit. This would be
>> Horde_Test.
>> https://github.com/yunosh/phpunit-2 would be the library that depends
>> on Horde_Test aka phpunit-1. Composer can resolve this to the correct
>> PHPUnit version, depending on the PHP version that is currently
>> installed.
>>
>> Since this is a bit older, 9.5. didn't exist at this point, but maybe
>> it could be extended to match this.
>>
I will look into this.



-- 
Ralf Lang
Linux Consultant / Developer
Tel.: +49-170-6381563
Mail: lang at b1-systems.de
B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537



More information about the dev mailing list