Test that classes use all their ServiceOptions
authorAryeh Gregor <ayg@aryeh.name>
Wed, 14 Aug 2019 12:58:53 +0000 (15:58 +0300)
committerAryeh Gregor <ayg@aryeh.name>
Mon, 19 Aug 2019 17:42:28 +0000 (20:42 +0300)
commitb058a0e562ff2ee1ae47517e52c7f1a83d6ce068
tree68c7a488715d078c3171f509585ddf5a69a6d9e6
parent4d10bb14e81aadb907a00e4bd13973ef668ab1f8
Test that classes use all their ServiceOptions

Classes that use ServiceOptions need to declare a list of keys that they
use, typically in self::$constructorOptions. If keys are missing from
that list that are supposed to be present, an exception will be thrown
when someone tries to access them. If keys are present on the list that
are never used, no error is flagged. This means if a dependency on a
given configuration option is removed and nobody updates the list, the
service will keep thinking it depends on that option when it doesn't.
This is messy at best, like an unused variable.

A new and easy-to-use TestAllServiceOptionsUsed trait fixes that
problem. It will log all the ServiceOptions accesses while the test
class runs and raise an error if there are any keys that were never
accessed.

In retrospect, it was probably not worth the time to write this, but
it's a sunk cost now.

Change-Id: Idcaf9a0e2f687069869e6f8057908ffee7dd5f11
tests/common/TestsAutoLoader.php
tests/phpunit/includes/block/BlockManagerTest.php
tests/phpunit/includes/config/LoggedServiceOptions.php [new file with mode: 0644]
tests/phpunit/includes/config/TestAllServiceOptionsUsed.php [new file with mode: 0644]
tests/phpunit/includes/preferences/DefaultPreferencesFactoryTest.php
tests/phpunit/includes/title/NamespaceInfoTest.php