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
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
Refactor the database setup code to share more code between
ParserTestRunner and MediaWikiIntegrationTestCase. Made
`::setupAllTestDBs` static so it can be reused from
ParserTestRunner.
Made ParserTestRunner::addArticle more like
MediaWikiIntegrationTestCase::addCoreDBData(). Some additional
refactoring work could be done here in the future to share more code.
After the refactoring the ParserTestTables hook is no longer necessary
and so has been (soft) deprecated. MediaWikiIntegrationTestCase
clones all database tables, so ParserTestRunner no longer needs to ask
extensions for a list of specific tables it should clone. Cleaning up
the handful of extensions which define this hook will be left to a
future patch set.
Change-Id: I5124789fac333a664b73b4b4a1e801ecc0a618ca
Also fix two places where we were using `$this->` in a corner case.
Using `static::` lets subclasses override these method definitions,
at least in theory.
Change-Id: I76a6d10ce463a5bc79e14051a31f469668924494
Deprecated since 1.35, not compatible with PHPUnit 8. This could've
happened earlier, but here we go.
Unused in known repos (except for the sniff looking for this usage):
https://codesearch.wmcloud.org/search/?q=assertType%5C(&i=nope&files=php&repos=
Bug: T192167
Change-Id: I479cf71d0941c35096d21686077b4d1cbc4f898d
Some User methods fail if they are called before $wgRequest is
set. But according to the Setup.php comment, it is only set for b/c.
The global request object can be lazy-initialised at any time.
This is sufficient to avoid T263911 (loss/obfuscation of the $wgServer
error message).
In tests, try to keep $wgRequest and RequestContext::$request in sync.
Introduce MediaWikiIntegrationTestCase::setRequest() which sets both at
once, and use that instead of setMwGlobals() or direct assignment.
BlockManagerTest was accidentally exploiting the fact that the global
context request and $wgRequest were separate objects. Making them the
same causes session cookies to appear in the response, breaking the
cookie counts. Use a new response for the test.
Bug: T263911
Bug: T245940
Change-Id: I2be99f7251a837bc6b62be0b152038157dec10f2
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.
Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.
Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
The editPage() convenience function in MediaWikiIntegrationtestCase
should optionally accept a WikiPage instance as a parameter. This
allows edits to be made conveniently, without any WikiPage instance
held by the caller going out of sync.
Change-Id: I68ad6df5f6dc357658fe112957bea8b11cf2471e
This reverts commit c17ddfd786.
This time, also: Trying to get mock http to work in parser test
Bug: T262443
Change-Id: Id708cdfa3d3c27f30543c6bf212df96e6b0a69e1
Tests should not make real HTTP requests. Mock out the
HTTPRequestFactory service to prevent this.
Bug: T262443
Depends-On: I63bfd54c3de55d678e8b862b85c0adfb5fc94d91
Change-Id: I1702c11928f8760bb41b41f4c7c04d7af03f62e2
This is causing problems for Parsoid CI, as parser tests fail when
phpunit runs the tests at a different point than they are run in
core's CI due to the side-effects of content-language changes made in
other phpunit tests. (For example, phpunit runs all extension tests
after core tests, so the same parsertest can pass if included in core
and then fail when included in an extension.)
SpecialPageFactory::$aliases has a dependency on the current content
language, with no way to reset it other than to recreate the
SpecialPageFactory.
Change-Id: I278580ed5cf2c85403cbaf601f8af4753e14a9d0
The PHPDoc for the editPage method stated that if $user is null,
the test sysop user will be used instead. This is not the case in
practice, as the method simply passes null to the doEditContent
method.
As Ammarpad has pointed out in a comment, this confusion is due to
I5a10163 assuming the sysop would be used, which is incorrect.
It's also probably better for the default user to be a "regular"
user, not a sysop, so I changed it to getTestUser() and noted this
in the doc block.
Depends-On: I7a79e0eaa1617e4d87a8d615a5391723c0e30b6a
Change-Id: I9f77474f40e0f6901aa2c6f846e471b822636aa5
Since we reset all services between test cases, no special effort is
needed to restore the state of the HookContainer.
Bug: T255056
Change-Id: I364f2943d56644f9c7c3acc053e6b585bd8f535c
Previously, clear() and scopedRegister() would not disable hook handlers
registered using the new mechanism. Only old style hook handlers would
be suppressed.
The new implementation is based on tombstones: Instead of actually
removing registered handlers to override them, tombstone markers are
put into place to disable existing handlers until the tombstone is
removed again. This allows hook handlers to be disabled temporarily
in a consistent way.
This removes HookContainer::getOriginalHooksForTest(), which is
incompatible with the new logic.
Bug: T255056
Change-Id: I08c1824797ac60a5098a52b5781af8ac4dd38928
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
The new HookContainer.php introduces a scopedRegister() method for
temporarily setting hooks. Let's use that in MediaWikiUnitTestCase
and MediaWikiIntegrationTestCase instead of directly accessing
global $wgHooks to do so.
Also introduces setTemporaryHook() and removeTemporaryHook()
methods in MWIntegrationTestCase for easily adding/removing of
temporary hooks.
Bug: T250300
Change-Id: I8cefd41b66f882c53646b76de76c51f0d8730f72
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
This converts user options management to a separate
service for use in DI context.
User options are accessed quite early on in installation
process and full-on options management depends on the
database. Prior we have protected from accessing the DB
by setting a hacky $wgUser with 0 id, and relying on the
implementation that it doesn't go into the database to
get the default user options. Now we can't really do that
since DBLoadBalancer is required to instantiate the options
manager. Instead, we redefine the options manager with
a DefaultOptionsManager, that only provides access to
default options and doesn't require DB access.
UserOptionsManager uses PreferencesFactory, however
injecting it will produce a cyclic dependency. The problem
is that we separate options to different kinds, which are
inferred from the PreferencesFactory declaration for those
options (e.g. if it's a radio button in the UI declaration,
the option is of multiselect kind). This is plain wrong,
the dependency should be wise versa. This will be addressed
separately, since it's requires larger refactoring. For now
the PreferencesFactory is obtained on demand. This will be
addressed in a followup.
Bug: T248527
Change-Id: I74917c5eaec184d188911a319895b941ed55ee87
On PHP 7.4 and above, a memory leak can be observed in
ServiceContainer::loadWiringFiles when running PHPUnit tests. This patch aims to
work around the leak by changing
MediaWikiIntegrationTestCase::installMockMwServices to cache and reuse the
original service wirings if no config overrides were supplied. This
significantly reduces the amount of times that the wiring closures need to be
included; on PHP 8, it caused memory usage to drop to 894.25 MB from 4+ GB when
running the PHPUnit tests for MediaWiki core.
However, it seems to be causing some test failures and so it is currently a WIP.
Bug: T247990
Change-Id: I24971221b8accf78d61479d286e907c1111212a0
* 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
Only support passing RevisionRecord or int, remove use of
Revision::newFromId
Bug: T249021
Bug: T249561
Change-Id: Id4a8f64f239d0664865056887fe0a11c7e468d5f