Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor phpunit tests #36501

Merged
merged 8 commits into from Dec 7, 2019
Merged

Refactor phpunit tests #36501

merged 8 commits into from Dec 7, 2019

Conversation

phil-davis
Copy link
Contributor

@phil-davis phil-davis commented Dec 1, 2019

Description

Revive PR #34961 Declare testCase methods void to match modern phpunit declaration
And do stuff that we can do now in phpunit7 and PHP 7.1 to be up-to-date for phpunit8 and PHP 7.2
https://phpunit.de/announcements/phpunit-8.html
https://thephp.cc/news/2019/02/help-my-tests-stopped-working

PR #36499 runs phpunit tests with phpunit V8. That is where we can see easily what stuff needs to be done to make the phpunit tests more future-proof.

  1. the setup* and teardown* methods in phpunit8 have return type void, so they have to be declared like that where we inherit-override them.

  2. expectException annotations are being deprecated in favour of $this->expectException() so change them.
    https://thephp.cc/news/2016/02/questioning-phpunit-best-practices
    php-cs-fixer fixes this automagically by adding this to the config:

			'php_unit_no_expectation_annotation' => true,
			'php_unit_expectation' => true,

That could be added to owncloud-codestyle so that we find and "fix" any of these in people's PRs.

  1. assertInternalType is being deprecated in favour of assertIsArray() assertIsInt() etc.
    Implement specialized alternatives to assertInternalType() and assertNotInternalType() sebastianbergmann/phpunit#3368
    php-cs-fixer fixes this automagically by adding this to the config:
			'php_unit_dedicate_assert_internal_type' => true,

That could be added to owncloud-codestyle so that we find and "fix" any of these in people's PRs.

  1. there is now assertStringContainsString to replace assertContains when checking for a sub-string of a string. Use it.

  2. the canonicalizing parameter of assertEquals is being removed, so replace those usages with assertEqualsCanonicalizing

  3. assertArraySubset is being removed. Replace it with appropriate code. (We only used it in 2 places)

  4. In tests/lib/Lock/LockingProvider.php we now have calls to expectException. But some classes that inherit from this also have their own expectException exception to expect. That is trouble for the test infrastructure to know which exception is really expected. Refactor that (see the diff of 7th commit)

  5. Similar for tests/lib/Files/External/Service/StoragesServiceTest.php - refactor for expected exception.

Motivation and Context

Now that we are running phpunit V7, make the changes needed to be ready for V8...
Then when we drop PHP 7.1 support in the future, we can also easily move to phpunit V8.

How Has This Been Tested?

CI

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:
  • Changelog item, see TEMPLATE

@phil-davis phil-davis self-assigned this Dec 1, 2019
@phil-davis phil-davis force-pushed the refactor-phpunit-tests-20191201 branch 2 times, most recently from 7fe6672 to 8a8f9a2 Compare December 1, 2019 16:42
@codecov
Copy link

codecov bot commented Dec 1, 2019

Codecov Report

Merging #36501 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #36501      +/-   ##
============================================
+ Coverage     64.64%   64.66%   +0.01%     
  Complexity    19049    19049              
============================================
  Files          1269     1269              
  Lines         74469    74497      +28     
  Branches       1311     1311              
============================================
+ Hits          48142    48170      +28     
  Misses        25941    25941              
  Partials        386      386
Flag Coverage Δ Complexity Δ
#javascript 54.02% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 65.83% <100%> (+0.01%) 19049 <8> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
...s/systemtags/tests/unit/activity/ExtensionTest.php 81.81% <100%> (ø) 3 <1> (ø) ⬇️
...pps/comments/tests/unit/Dav/CommentsPluginTest.php 100% <100%> (ø) 11 <1> (ø) ⬇️
...pps/comments/tests/unit/Dav/RootCollectionTest.php 98.55% <100%> (+0.19%) 17 <1> (ø) ⬇️
apps/comments/tests/unit/ActivityListenerTest.php 100% <100%> (ø) 2 <1> (ø) ⬇️
...ps/systemtags/tests/unit/activity/ListenerTest.php 90.9% <100%> (ø) 5 <1> (ø) ⬇️
...mments/tests/unit/Dav/EntityTypeCollectionTest.php 100% <100%> (ø) 6 <1> (ø) ⬇️
...s/comments/tests/unit/Dav/EntityCollectionTest.php 100% <100%> (ø) 8 <1> (ø) ⬇️
apps/comments/tests/unit/Dav/CommentsNodeTest.php 96.52% <100%> (+0.11%) 17 <1> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 841ea0b...7ee6f4e. Read the comment docs.

@phil-davis phil-davis force-pushed the refactor-phpunit-tests-20191201 branch from 8a8f9a2 to 91c914f Compare December 1, 2019 17:24
@phil-davis
Copy link
Contributor Author

CI is failing because of fsweb.test.owncloud.com being down - see #36502

@phil-davis phil-davis force-pushed the refactor-phpunit-tests-20191201 branch from 91c914f to 0baa229 Compare December 2, 2019 03:34
@phil-davis phil-davis changed the title Refactor phpunit tests 20191201 Refactor phpunit tests Dec 2, 2019
@phil-davis
Copy link
Contributor Author

phil-davis commented Dec 2, 2019

This is a weekend community contribution.
Most of the changes were done using php-cs-fixer "fixes" that processed it automatically.
If someone can review, that would be great. There are many lines of repetitive diff - nothing I can do about that. @micbar @DeepDiver1975 @PVince81 or whoever likes to review.

@phil-davis phil-davis force-pushed the refactor-phpunit-tests-20191201 branch from f0e2735 to 7ee6f4e Compare December 7, 2019 03:06
@phil-davis
Copy link
Contributor Author

Thanks @individual-it - I got no response from anyone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants