Page MenuHomePhabricator

Jenkins: Create phpcs sniff to ensure test functions have the proper signature
Closed, DeclinedPublic

Description

MediaWiki needs a (voting) sniff to ensure the test conventions[1]:

Data providers must be public static functions

[1]http://www.mediawiki.org/wiki/Manual:PHP_unit_testing/Writing_unit_tests#Test_conventions

See also bug 46434


Version: wmf-deployment
Severity: enhancement

Details

Reference
bz46483

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:13 AM
bzimport set Reference to bz46483.
bzimport added a subscriber: Unknown Object (MLST).

Maybe we can implement a unit test in tests/phpunit/StructureTest.php

The sniff should assert:

  • setUp/tearDown is "protected static function"
  • test function is "public function"
  • dataProvider is "public static function"

And maybe:

  • setUp/tearDown should call parent method

(not sure about the latter, I think there are some cases were we genuinely don't)

The convention has been added by Timo Revision as of 01:20, 6 October 2012

http://www.mediawiki.org/w/index.php?title=Manual:PHP_unit_testing/Writing_unit_tests&diff=591076&oldid=586470

I am not sure what is the rational behind it. Anyway, it should be possible to enhance MediaWikiTestCase to call a PHPUnit method that would gives out all the @dataprovider statements and then check whether they are public static methods.

hashar claimed this task.

PHPUnit does not seem to complain when the methods visibility are not set and I don't think it is worth the effort to write the phpcs sniff and have it deployed everywhere.