Use more specific and less fragile assertions whenever possible;
most tests don't need to examine the internals of the status so
closely. Use StatusValue::getMessages() when necessary.
Change-Id: Ie4b3ebc03abb0e352e82394ced6ab9e733c83fb4
Changes to the use statements done automatically via script
Addition of missing use statement done manually
Change-Id: I4ff4d0c10820dc2a3b8419b4115fadf81a76f7a2
StatusValue::replaceMessage() doesn't really work if given a
MessageSpecifier, and doesn't work at all if given a MessageValue.
StatusValue::hasMessage() and ::hasMessagesExcept() ignore the message
parameters when searching if given a MessageSpecifier or MessageValue.
Therefore, deprecate passing anything other than strings representing
message keys to these methods.
Change-Id: Icb4effc6c5319c12ba4ebeab447a0cef54f8e255
Lots of code duplication there. PHPUnit comes with neat helper
methods for that.
Depends-On: I30ab799ceab36b80c330d1233f3009814d7f6c98
Change-Id: I86ff2d61fb1c28cc6a285cce6dc2b6d4f5b7bca4
I keep running into this whenever I use createNoOpMock. I think it's
XDebug that's calling this method, and then PHPUnit flooding the
console with extremely long stack traces.
We pretty much never do anything custom with this method:
https://codesearch.wmcloud.org/search/?q=__debugInfo&files=%5C.php%24
Change-Id: Ib2ab86fb243555f5e4449ed72cb032cb465e415d
expectWarning() and friends have been deprecated in PHPUnit 9.6, and
removed in PHPUnit 10. Unfortunately, there is no simple replacement
because PHPUnit no longer converts them to exceptions in the first
place. In fact, Sebastian Bergmann explicitly stated that he does not
consider the use case of
> a library developer to verify a code block warns its consumer when
> certain action is performed
worth supporting.
So, add an ad-hoc replacement for all the deprecated methods. This is
quite ugly, but it's simple enough given the low number of usages.
On the bright side, this new method does not halt the test when the
warning is triggered. This seems to align with the developers'
expectation, seen in a few existing tests, that any code following the
notice will be executed.
Bug: T342110
Change-Id: I214abfed4280834840c115777ed78eb0a5570da9
- Mark test as skipped referring known task about improve of the tests
- Mark test as skipped testing for backward-compatibility on
parser cache serialization, test data contains old properties,
which are now unknown and created dynamically
Change-Id: If6a4c7dbba39389b06ce64fb5cac08cd8d7dd9fc
assertObjectHasAttribute and assertObjectNotHasAttribute are amongst the
assertion methods deprecated in PHPUnit 9.6. PHPUnit 10 introduced
replacement methods for them, assertObjectHasProperty and
assertObjectNotHasProperty respectively, but these weren't backported to
the 9.x branch.
Add temporary overrides for those methods in MediaWikiTestCaseTrait, so
that we can start migrating our code before the PHPUnit 10 update. The
signature, implementation, and error messages of these assertions are
copied from upstream, so the transition should be seamless. The only
tiny difference is that our version also prints "Failed asserting that
false is true" (and vice versa for NotHasAttribute) after the custom
message, but I don't think this is worth the complexity of adding a
custom Constraint.
Also migrate the few existing usages to the new methods.
Bug: T342110
Change-Id: If489d2c70fabbed6a068ef22d166f6e73f6adf6d
This isn't specific to integration tests.
Rename it to assertArrayContains() as the terms "submap" is uncommon.
The term "same" does correctly connotate strict equality, but seems
redundant/implied when operating on mutiple values, such as with
the built-in assertContains(), assertJsonStringEqualsJsonString(),
etc.
Change-Id: I9d8e7dca128a73d03b173a8ec3566f55edddde6a
PHPUnit 3.7.0 was the first version to support @requires extension. At
the time checkPHPExtension() was added in a7901801b4, MediaWiki
still supported PHPUnit 3.6.7.
MediaWiki now requires intl and xml, so I removed checks for those
extensions rather than converting them to annotations.
checkPHPExtension() is removed without deprecation; it does not appear
to have ever been used (and is not likely to be used) in MW extensions.
This is explicitly permitted under the stable interface policy. Even if
it were not, only tests are affected, and they are supposed to fail
anyway if hard deprecated code is used.
Change-Id: I45f9b4c0e120683103cead916f4d4ef58bd11530
Since `createNoOpMock()` & `createNoOpAbstractMock()` returns a `MockObject`
type, this makes callers of this method complain in the IDE as if the right
type is not passed in.
Using a Psalm template in this patch fixes this warnings (got the idea
from PHPUnit TestCase.php). In addition, using normal @params so that
phan can be happy as well.
Change-Id: Ic0074d0d0d432c71473a48d79653e59ca7ad0085
* DeprecatedHooksTest: Don't use assertContains().
* Replace uses of deprecated asserts:
- assertFileNotExists() -> assertFileDoesNotExist()
* Update hierarchy of MediaWikiPHPUnitResultPrinter, since ResultPrinter
is an interface in PHPUnit 9.
* Remove temporary forward-compat methods.
* Remove directories that don't exist from tests/phpunit/suite.xml, since
they now make PHPUnit exit:
- tests/phpunit/skins, it used to have SideBarTest, then moved to
tests/phpunit/includes/skins
- tests/phpunit/documentation, it used to have ReleaseNotesTest, then
moved to tests/phpunit/unit/documentation
* Update configuration with --migrate-configuration and reformat.
* Avoid redefining getMockBuilder() in
ActionModuleBasedHandlerTestTrait, use a @method annotation instead.
* In RCCacheEntryFactoryTest, avoid using internal PHPUnit logic for
HTML validation, and use native PHP methods instead. The code was
copied from Xml::load (moved to \Xml\Loader::load in PHPUnit 9) and
simplified for this use case.
Bug: T243600
Bug: T262076
Change-Id: I851b9158b73d0cfc315eed9d63b15c54b05895e3
assertRegExp was deprecated in PHPUnit 9 and its replacement,
assertMatchesRegularExpression, was also introduced in PHPUnit 9. Hence,
we cannot migrate callers before the upgrade, but we also can't upgrade
before callers are migrated due to deprecation warnings. This is
especially true in extensions.
So create a temporary method that extensions can use while we
transition.
Bug: T243600
Change-Id: Ibce4c2479a533d132eb9f0641f8473fc6ca14fdb
createMock() does the same, but is much easier to read.
A small difference is that some of the replacements made in this
patch didn't use disableOriginalConstructor() before. In case this
was relevant we should see the respective test fail. If not we can
save some CPU cycles and skip these constructors.
Change-Id: Ib98fb06e0fe753b7a53cb087a47e1159515a8ad5
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