Core: Refactor PHPUnit Test Suite and adjust Recommendations

Created on 9 Mar 2018  路  4Comments  路  Source: owncloud/core

Since PHPUnit 5 support has ended in February 2018 - and phpunit 5 does not officially support php 7.2 we need to refactor the test suite.

PHPUnit 5 already has a forward compatibility layer that we could start using now, before we move fully to phpunit6+

How to migrate:
https://thephp.cc/news/2017/02/migrating-to-phpunit-6

Update recommendations:

We propose to have a namespace adjusted to reflect these best practices:
https://phpunit.readthedocs.io/en/latest/organizing-tests.html

Tests for a Class should reside in the same namespace, but finish with *Test

Application Classes
/srv/http/owncloud/apps/myapp/lib/MyClass.php

Test Classes for Application
/srv/http/owncloud/apps/myapp/tests/unit/MyClassTest.php
Documentation changes tracked here: https://github.com/owncloud/documentation/pull/3889

documentation orga technical debt

Most helpful comment

Oh dear, I have got a reputation as "Mr Refactoring" as well as "Mr 0"

All 4 comments

GitMate.io thinks the contributor most likely able to help you is @phil-davis.

Possibly related issues are https://github.com/owncloud/core/issues/22492 (test), https://github.com/owncloud/core/issues/22485 (test), https://github.com/owncloud/core/pull/29586 (Refactor UI tests user creation), https://github.com/owncloud/core/pull/29584 (Refactor UI tests user creation), and https://github.com/owncloud/core/issues/22466 (need to adjust required phpunit version).

Oh dear, I have got a reputation as "Mr Refactoring" as well as "Mr 0"

We propose to have a namespace adjusted to reflect these best practices:
https://phpunit.readthedocs.io/en/latest/organizing-tests.html

Tests for a Class should reside in the same namespace, but finish with *Test

We shall have a closer look at the namespace definition - while phpunit suggests to use the same namespace - other big projects are not following this recommendation - see https://github.com/symfony/http-foundation/blob/1905ca19c77563e7de033fc76b8f93e70dc25286/Tests/CookieTest.php#L12

Before we dive into heavy renaming of our testing namespace we shall have a very close eye on this.

Would be great to find a reasoning - in many symfony projects we've followed the symfony practice - but so far more over "let's do it as they do it".

What I've also seen is, that people added Test\Vendor\Package - which I found very confusing

Was this page helpful?
0 / 5 - 0 ratings