Commit graph

14 commits

Author SHA1 Message Date
Tim Starling
b3d762e148 Add HookRegistry
Add a HookRegistry interface and two concrete implementations,
representing HookContainer's view of its environment. This simplifies
creation of a HookContainer for testing.

Add MediaWikiTestCaseTrait::createHookContainer() which can be used
in most of the places that were previously creating mock hook
containers. It can also replace setTemporaryHook() in some cases.

Change-Id: I9ce15591dc40b3d717c203fa973141aa45a2500c
2020-05-13 11:51:02 +10:00
Timo Tijhof
355a6cd4c3 phpunit: Add error_reporting/AtEase check to MediaWikiUnitTestCase
This existed on MediaWikiIntegrationTestCase, but not on
MediaWikiUnitTestCase. As a result of that, I spent about four
days tracking down a dangling AtEase::suppressWarnings with
missing AtEase::restoreWarnings (as part of Ib6758d724c).

Move it to the common MediaWikiTestCaseTrait instead so that we
get it on unit/ as well.

Example:

> There was 1 failure:
>
> 1) Pbkdf2PasswordTest::testCryptThrows
> PHP error_reporting setting found dirty.
> Did you forget AtEase::restoreWarnings?

Change-Id: I7dc3fe90385c8066b89a5e06c55f5455edfbb4ca
2020-05-09 01:48:45 +00:00
Tim Starling
df05164822 More flexible deprecation warnings
* Split MWDebug::sendRawDeprecated() from MWDebug::deprecated(). The new
  function can be used to send arbitrary messages to the deprecation
  log, rather than being constrained by the fixed format of
  MWDebug::deprecated().
* Split formatCallerDescription() from sendMessage() to allow the caller
  of sendRawDeprecated() to do its own caller formatting.
* Use the new function in MWLBFactory::logDeprecation()
* In tests, replace the ugly implementation of hideDeprecated() with one
  that works by setting a list of regexes to filter. hideDeprecated()
  now filters deprecation warnings that are a string match to the
  supplied function. filterDeprecated() can be used to filter a regex,
  and is intended to be used to filter warnings sent via
  sendRawDeprecated(). The filter list is reset at the start of each
  test, instead of leaking across tests as before.

Change-Id: I0d0df86db2e61cdd1769426bfa7bad4c2ae5e977
2020-04-22 12:37:22 +10:00
daniel
9884139d65 SearchHandler: add unit test
Change-Id: I963a2f31afddd37ada615f12d6d5725c20a18631
2020-03-02 20:52:46 +01:00
Gergő Tisza
8a08f2a806
Use dependency injection for AuthManager and allow it for providers
Change-Id: Icf3345bec993f8cb103f065e76b04fe1f3521639
2020-02-19 01:18:16 -08:00
Gergő Tisza
02bbdd3d81
Improve phpdoc in MediaWikiTestCaseTrait
- add MockObject as a return type for createNoOpMock. Technically
  object and object|MockObject are the same but this is enough to
  prevent some IDE warnings about incompatible types (and to guide
  IDE autocomplete although there is probably not much use for that
  in a no-op mock).
- fix a legacy classname alias which modern PHPUnit does not provide
  anymore

Change-Id: I6445bce2dd7a4bf97ad2374ab2dac566b3d73546
2020-02-11 14:13:25 -08:00
Gergő Tisza
035db6bb59
Share assertArrayEquals with MediaWikiUnitTestCase
assertArrayEquals is a generic assertion that does not have anything
to do with integration testing, and is quite useful for isolated
testing of classes which return unordered sets.

Change-Id: I45af77402a1bc922579aff14b21874ec8680e765
2020-01-07 16:05:40 -08:00
Umherirrender
97ed35e2e8 Add missing @param and @return to documentation
Change-Id: I48ee838a7ebf4f25a4883d4c7886b39c2d3916af
2019-11-16 13:45:55 +01:00
Aryeh Gregor
b0795a2550 Hard-deprecate LockManagerGroup::getDefault/getAny
These appear to be unused. Moreover, their behavior doesn't match their
documentation. getDefault() claims to return NullLockManager if no lock
manager could be found, but really returns it if there's no lock manager
named 'default'. getAny() claims to throw if no lock manager can be
found, but actually throws if no lock manager is named 'default' or
'fsLockManager'. The behavior can be easily replicated by just using
get() yourself and catching any exception.

Bug: T234227
Change-Id: Iad083847f45d6e017a3f7dbfece1f9c155c5efd6
2019-10-29 14:48:44 +02:00
David Causse
d29adfe276 MediaWikiTestCaseTrait use $this instead of static calls
for consistency.

Change-Id: Ie769751cf6d08335932dd66c56acb1d3f43f1dab
2019-09-20 18:53:28 +02:00
David Causse
b3b95c3927 Add assertFileContains to MediaWikiTestCaseTrait
Used by CirrusSearch unit tests.

Change-Id: I1b67a9cddfca7fa06fb0b916981d1efde0764018
2019-09-17 17:24:33 +02:00
mainframe98
4941f2de91 Permit destructors in MediaWikiTestCaseTrait::createNoOpMock
709773ab57 introduced this method, but its implementation
does not permit calls to __destruct. PHP documentation on destructors
says that they'll be called unconditionally, which makes using the
mock created with this method unusable for classes that implement
__destruct.

Bug: T231656
Change-Id: Icb4f978c78e726401d75627128c9c76f6f9afc87
2019-08-30 15:27:38 +00:00
Aryeh Gregor
709773ab57 createNoOpMock() method for PHPUnit tests
This is just a shortcut for a commonly-used pattern, when you want to
create a mock that's never supposed to have methods called.

Change-Id: Ia7267e3d3108c1ff94485f7e44bf409808a762be
2019-08-29 18:00:37 +03:00
Aryeh Gregor
5e2199c5b0 BadFileLookup to replace wfIsBadImage
I think this probably shouldn't be directly in the MediaWiki namespace,
but I don't know where is a better place to put it.

In order to avoid gratuitous use of TitleFormatter, I changed the cache
format -- the old implementation used getPrefixedDBkey() and I switched
to an ns/dbkey pair. I also changed the cache keys to use SHA1 instead
of MD5, by Daniel's request.

The previous implementation cached the parsed blacklist for one minute
without invalidation, so it could return slightly stale results, but it
didn't retrieve the bad image list message on a cache hit. The new
implementation unconditionally retrieves the bad image list message, but
uses a hash of it in the cache key and caches for one day. The new
behavior happens to be more cleanly implementable in a service.

Bug: T200882
Bug: T139216
Change-Id: I69fed1b1f3cfc1aa149e0739780e67f6de01609d
2019-08-21 20:45:37 +03:00