The output generated by assertStatusOK() when the status is not OK
should not include warnings, only errors. isOK() will return true even
if there are warnings, so the presense of warnings is not relevant to
the test failure, and should not be reported.
Change-Id: Ida32210e62636960671282883eba86ffe820edd6
The new class, UrlUtils, is usable standalone or as a service. Using it
as a service will just automatically load a few settings from site
configuration.
In addition to just making our code cleaner, this will enable making
some of Setup.php's dynamic configuration more sane.
Test coverage is all lines except invalid URLs -- I couldn't find any.
Bug: T305093
Change-Id: I706ef8a50aafb518e13222719575d274c3583b90
This ensures that assertions work in a uniform way,
and provides meaningful messages in cause of failure.
Change-Id: Ic01715b9a55444d3df6b5d4097e78cb8ac082b3e
Update/Create override classes of ContentHandler.
Soft-deprecate and remove method from Content and classes that override them.
Bug: T287158
Change-Id: Idfcfbfe1a196cd69a04ca357281d08bb3d097ce2
```
function check($txt) {
echo sprintf("er=%+5s, ini=%+5s # $txt\n",
error_reporting(), intval( ini_get( 'error_reporting' ) )
);
}
function turningItOffAndOnAgain() { // have you tried...
check('... enter');
$old = error_reporting(42);
check('... off');
error_reporting($old);
check('... on');
}
error_reporting(2);
check('start'); # er=2, ini=2
turningItOffAndOnAgain();
check('toggled'); # er=2, ini=2
@turningItOffAndOnAgain();
check('silence-toggled'); # er=2, ini=0
```
PHP correctly reflects the silenced state during the silenced state,
the same as our AtEase library.
PHP also correctly ignores changse to error_reporting while being
silenced. That is, it always restores it back to how it was regardless
of what a confused nested function may have done.
Where it fails is that it doesn't seem to sync the INI setting, which
caused this PHPUnit check to cause test failures.
While this an upstream bug, it was also a mistake on my part to
write the PHPUnit check based on the ini_get value. That's not the
idiomatic way to check the current state and apart from these two
lines of code, it seems nothing in any of our Codesearch-indexed
code bases, including third party, do this.
Bug: T291278
Change-Id: Ic3e66cb2e5b2b44b9997d323abbc87b7f8fe3c41
Dependency was added in T254053 so that we
could use a pimple ServiceLocator in
MediaWikiTestCaseTrait::createSimpleObjectFactory.
But, since the ServiceLocator being created is using
an empty container, its not actually used for anything,
and can easily be replaced with a mock that says
it has no services and throws if trying to retrieve any.
Per the PSR11 spec, the container interface should
throw an exception that implements
NotFoundExceptionInterface - use the
NoSuchServiceException from the Services library
that we use for MediaWikiServices
Change-Id: I721e7417036a8b0fa9084e9d13329262253ae0f6
See task. Existing callers are not being updated because explicit is
better than implicit.
Bug: T280780
Change-Id: If6e9569dd3e98a14f8412fd245f6ed5141ed8d0d
As I wrote in Ie9d5d7e53faee09b7fe63f9387f72dc87411c24d,
Assert::matches:
- Only accepts strings (and not arbitrary values)
- And it does so because the comparison uses format strings (à la
printf), which is not what we want here.
This currently works for method names like the docs suggest, but it
fails with basically anything that is not a string without '%' chars.
Instead, use identicalTo() which performs === comparisons. Note that
using equalTo() (which uses `==`) would perhaps be more consistent
with the PHPUnit API, but then we'd have the usual problems with weak
comparisons. A separate implementation (or method parameter) which uses
== can be added later if someone really finds it necessary.
Change-Id: I8444129198182f5eccc0a7282abd609b2f763299
Ended up using
grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'
special-casing setMethods( null ) -> onlyMethods( [] )
and then manual fix of failing test (from PS2 onwards).
Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
Discovered in another patch that while integration
tests automatically reset fake timestamps afterwards,
unit tests don't. Add a shared method to MediaWikiTestCaseTrait
to reset for both integration tests and unit tests
Do the same for TypeDefTestCase
Change-Id: I677aec4e60894053fc554f2e13b069fb599858f2
No integration needed, though it did rely on
checkPHPExtension which was only available in
MediaWikiIntegrationTestCase, moved to
MediaWikiTestCaseTrait
Also put under /includes/historyblob/ to match covered class
Change-Id: I0bfe3e44bd45535c18f5ee2534430330586a1c4c
We can't avoid this entirely where we're testing upstream features
that are yet to be renamed, but this is a start.
Bug:T277986
Change-Id: I5c1ae717cc008ca147ea31fe35c44b19d1fe5d98
With @after the tear down methods are separated by purpose,
and MWDebug::clearLog had nothing to do with phpErrorFilterTearDown.
Change-Id: I46a894737102fdbb74b24225dcf7617234259e31
Without this, expectDeprecation() will not work if the same
deprecation is emitted in more than one test in the same test suite.
Change-Id: I850a072cc61437d1ab33af082ee99534bc6deee6
The previous logic obsfucates the issue about these remaining args
and the fact that they are all deprecated.
This patch makes it clear what's deprecated and the remaining
acceptable args count and position.
Change-Id: Ia7cef161fb990fac700fd2360c170d6ff1c4a8d0
This makes it consistent with createNoOpMock, and in general a mock with
a restricted set of methods is needed way more often than a mock with no
methods.
Change-Id: I787586fea2c3d9c3082e9d1007ecd2d552da6e4d
HookContainer::salvage() expects to be called immediately after the
object is constructed, and I enforced this expectation by asserting that
$this->handlersByName is empty.
However, MediaWikiServices::resetGlobalInstance() calls
HookContainer::run() in between construction and salvage(). The effect
is that the assertion is hit if any hooks were executed using the old
HookContainer.
So, call onMediaWikiServices() using the old pre-reset HookContainer,
instead of using a partially-constructed HookContainer for this purpose.
Pass the new MediaWikiServices instance as the argument, since that is
the thing that the hook is configuring.
Bug: T263925
Change-Id: I2b462d82c82314b11563a5ba1f02c6fb6d29e608
Based on Daniel's work at Ia6e70179b7ee5ce4e93888585ccc30d92da165c3
however was changed enough to move into a separate changeset.
More acceptance tests and data will be added in a followup commit.
Bug: T264397
Change-Id: I135187e83cbfa02b97c5656f0752f8bf1ceb58d0
There is native support for all of this now in PHP, thanks to changes
and additions that have been made in later versions. There should be no
need any more to ever use call_user_func() or call_user_func_array().
Reviewing this should be fairly easy: Because this patch touches
exclusivly tests, but no production code, there is no such thing as
"insufficent test coverage". As long as CI goes green, this should be
fine.
Change-Id: Ib9690103687734bb5a85d3dab0e5642a07087bbc
This patch adds two more commonly used methods for params/rawParams to
getMockMessage and relocates the functionality to the MediaWikiTestCaseTrait.
Follows-Up: Ia94521b786
Change-Id: If9a6ccf1885ba11fbf3fb1b586006118462c1410
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
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
* 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
- 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
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
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
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
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
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