Commit graph

333 commits

Author SHA1 Message Date
Umherirrender
839613ff77 tests: Use namespaced classes
Changes to the use statements and some additions
are done automatically via script
This also updates @covers tag for the namespaced classes

Change-Id: I859ba6d05018c99710b744e2becab432410d3bca
2024-10-21 18:53:02 +02:00
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
Umherirrender
c7cd5399e7 build: Use inline ignore for MediaWiki.Usage.DeprecatedGlobalVariables
This avoids addition of new code with the deprecated global,
or at least it gives extra attention on review when new code also uses
the inline ignore

Change-Id: I5c1bc5a1685c28f153d4fbe3525959930f54b557
2024-09-26 18:15:32 +00:00
Umherirrender
f5d4cf2654 tests: Pass no arguments to getDefaultWikitextNS
Change-Id: Ie57047dea892f74b5d83858d3b292963f45b14f2
2024-09-25 18:01:12 +02:00
Umherirrender
41f6d9eee4 tests: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: Ifc27750207edc09e94af030d882b6f1a5369cf98
2024-09-18 17:25:42 +00:00
Máté Szabó
f89aa38f69 objectcache: Remove WinCache support
WinCache is an APCu equivalent for use with Microsoft IIS, but in recent
years has been unmaintained and lacks support for PHP 8 and newer.[1]
So, remove support for it as MediaWiki will be raising the minimum
supported PHP version to 8.1.

[1] https://www.php.net/manual/en/install.windows.recommended.php

Bug: T365691
Change-Id: I4d2dc01a9119bb1f858132f0146b894750c1e86d
2024-09-05 17:59:26 +00:00
Umherirrender
0a69e0bc53 tests: Use const for some static data in test files
Change-Id: Id7ccd48e3bf626095e2d3929831b5d87ed0be948
2024-09-01 23:24:11 +02:00
Umherirrender
06f33763be tests: Remove deprecated MediaWikiIntegrationTestCase::addCoreDBData
Change-Id: I209d72de8131678dc02eb299e9ed2dee1fd81f9a
2024-08-25 23:16:07 +02:00
thiemowmde
ba36bf46a1 tests: Make use of ??= and ?? operators in various tests
The main benefit is that this syntax avoids repeating the variable
name. It does the same as before.

Change-Id: I2040be889c749f4e2416ca9948ba261345858af2
2024-08-15 11:44:46 +02:00
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
jenkins-bot
04719f28c4 Merge "tests: Streamline code in MediaWikiIntegrationTestCase a bit" 2024-08-08 15:52:24 +00:00
thiemowmde
f295ed765e tests: Streamline code in MediaWikiIntegrationTestCase a bit
Does the same as before, just more compact and hopefully more
readable.

Change-Id: Id3920b5642caebd68bedf13849373bc99c99c20c
2024-08-08 16:09:59 +02:00
thiemowmde
52963bbcc0 tests: Make use of ?? and ??= operators in test code
I believe the more recent syntax is quite a bit more readable. The
most obvious benefit is that it allows for much less duplication.

Note this patch is intentionally only touching tests, so it can't
have any effect on production code.

Change-Id: Ibdde9e37edf80f0d3bb3cb9056bee5f7df8010ee
2024-08-08 15:51:20 +02:00
Fomafix
f90af6c157 Use MediaWikiIntegrationTestCase::getConfVar in tests
Change-Id: I3a99f24da3d572281b49a8a8b92e006fde3eaa41
2024-08-06 12:52:34 +00:00
Máté Szabó
6dd5826402 Make MockHttpTrait::setService() compatible with MediaWikiUnitTestCase
MediaWikiUnitTestCase::setService is defined as (string $name,
$service), which is incompatible with the ($name, $service) signature
MockHttpTrait expects for this method. As a fix, add the type hint to
the trait and MediaWikiIntegrationTestCase as well, to allow using
MockHttpTrait in tests extending MediaWikiUnitTestCase.

Change-Id: Ic7df40469947eff4b2be07d53eb9e09f452a4886
2024-07-29 16:31:41 +02:00
jenkins-bot
fb46c87700 Merge "MediaWikiIntegrationTestCase: deprecate $db" 2024-07-15 23:22:27 +00:00
jenkins-bot
82d91ed739 Merge "Use MainConfigNames constants in tests where possible" 2024-07-11 12:46:04 +00:00
Novem Linguae
a5542861fd MediaWikiIntegrationTestCase: deprecate $db
The decision was made to mass refactor these across
several repos. We should mark this as deprecated to
keep this from creeping back into downstream repos.

Bug: T316841
Change-Id: Ie1dae1a3927e1f73bed22fc6b10c44c062d45dbf
2024-07-10 11:59:42 -07:00
thiemowmde
4bd95cd96b Use MainConfigNames constants in tests where possible
I believe this makes the code less brittle, and also makes it a bit
more obvious what these strings are meant to represent.

Change-Id: Ia39b5c80af4b495931d0a68fd091b783645dd709
2024-07-10 10:11:22 +00:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
Lucas Werkmeister
6c0ead7fe4 MediaWikiIntegrationTestCase: Cache needsDB()
This method is called relatively often (especially now that $this->db is
being replaced with $this->getDb() everywhere, T316841), and it’s not
entirely cheap: the underlying isTestInDatabaseGroup() method needs to
create a ReflectionClass for the test class and run a regex on its doc
comment. As the result is a constant for any single class (its doc
comment cannot change), we can easily cache it.

In a simple benchmark, caching the result reduces the time for 10
million self::needsDB() calls from 7.97 seconds to 2.28 seconds, and for
10 million $this->getDb() calls from 68.70 seconds to 61.60 seconds –
not a huge difference, but not nothing either. Some logging in changes
Ia7f622ff87 and I4454c00958 indicates that there are about a dozen test
classes (in the extensions pulled in by MediaWiki core and/or Wikibase)
that call needsDB() at least a thousand times, and two test classes
(ResourcesTest and ScopeStructureTest) that call it at least ten
thousand times; based on this, I think the expected savings are
somewhere between a tenth and a hundredth of a second per test run.

The “indexed by class name” trick to get per-class static method
variables is directly taken from the PHP RFC [1]; prior to PHP 8.1, a
plain static boolean would have worked as we need it in this case.

[1]: https://wiki.php.net/rfc/static_variable_inheritance#backward_incompatible_changes

Change-Id: I7917cb58aa0c86428798a207f7ad63484e8eb8ad
2024-07-01 13:36:39 +02:00
Kosta Harlan
41e7e15107 MediaWikiIntegrationTestCase#revisionDelete: Set context user to a named account
Why:

- With temp accounts enabled, IP addresses cannot be the performer of a log entry.
- The RequestContext user by default is an IP address, so needs to be set to a named user 
  to allow the test to pass when temporary accounts are enabled.

What:

- Set the context user to a named account

Bug: T365669
Change-Id: I2af80141c6c63073aaa16f8f84b9bf98fcd4b4ac
2024-06-26 10:55:32 +00:00
jenkins-bot
7153fb2383 Merge "MediaWikiIntegrationTestCase::getExistingTestPage: Throw if the requested page isn't wikitext" 2024-06-05 13:46:02 +00:00
Derick Alangi
83bb1d45db
ServiceWiring: Drop _LocalClusterCache service
With the ObjectCacheFactory refactor in T358346, this service is
pretty much used in 2 places, (1) service wiring which can be replaced
and (2) in MediaWikiIntegrationTestCase.

The service can be removed entirely and the local cluster cache gotten
from the ObjectCacheFactory service injected via service wiring. Hence,
usage of this internal service can be removed.

NOTE: See followup: 7475063 for the TODO to drop this service entirely.

Change-Id: I173f04456df6cc1782cec2f16d6653c6b0826dce
2024-05-23 13:36:33 +01:00
jenkins-bot
ebd65dd664 Merge "Clear $wgTitle state before suite runs" 2024-05-23 10:53:39 +00:00
Derick Alangi
7475063bfd objectcache: Complete refactor of ObjectCache.php
This patch completes the rest of the ObjectCache refactor and
migrates methods to the appropriate class while deprecating them
in `ObjectCache.php`.

It also moves the `_LocalClusterCache` internal service logic
into ObjectCacheFactory and calls that instead making sure that
wiring code stays wiring code and let the class do the heavy lifting.

`::makeLocalServerCache()` is retained as a static method in the
ObjectCacheFactory class because it's called early in Setup.php
before the services container is available (so it needs to be stand-
alone).

To add, we also converts all global variables that were used in the
`ObjectCache.php` class into the config schema approach and retrieves
them using ServiceOptions injected in service wiring.

NOTE: MediaWikiIntegrationTestCase::setMainCache() was slightly
rewritten to take care of service reset which throws away the cache
object preserved by setInstanceForTesting() after service reset.
Instead, we preserve the object via MainConfigNames::ObjectCaches
setting with a factory closure which returns the correct cache object.

As a nice side effect of the above, the setInstanceForTesting() method
was removed entirely.

As a follow-up to this patch, I would like to remove the internal
_LocalClusterCache service in a stand-alone patch.

Bug: T363770
Change-Id: Ia2b689243980dbac37ee3bcfcbdf0683f9e1779b
2024-05-21 14:03:08 +00:00
Arthur Taylor
8f56cf90f2 Clear $wgTitle state before suite runs
`MessageCache::parse` pulls in global `$wgTitle` on line 1492 and
sets the page for the parse to this value of none is set. Some
tests (for example SummaryFormatterTest in Wikibase that extends
MediaWikiLangTestCase) interact with the MessageCache in contexts
where the page is not set, making the test unreliable if other
test cases have run beforehand and set `$wgTitle`.

Bug: T365130
Change-Id: Ib4ee7dc5102d5998aa65dcafb4efa531c2533c69
2024-05-21 10:59:08 +02:00
James D. Forrester
31b5732860 MediaWikiIntegrationTestCase::getExistingTestPage: Throw if the requested page isn't wikitext
Change-Id: I8910d870a8ef226f22a3d5cbd6deb01405fdd80b
2024-05-17 09:57:29 -04:00
jenkins-bot
f0a2f1dd1d Merge "fix: use objectcachefactory methods instead of deprecated objectcache methods" 2024-05-05 11:08:07 +00:00
Irina Balaban
dc989f680f fix: use objectcachefactory methods instead of deprecated objectcache methods
Bug: T363770
Change-Id: Ie732f6925ec2b1316a60bebbe3c27f963c9dacb1
2024-05-05 12:40:30 +03:00
jenkins-bot
8254591942 Merge "namespace MWDebug" 2024-05-03 21:43:37 +00:00
Amir Sarabadani
214674d6b1 namespace MWDebug
Bug: T353458
Change-Id: I99d728bd111ff882220cd175ff09d4da20b81eae
2024-05-03 22:59:47 +02:00
Umherirrender
6f94bde337 tests: Migrate to IReadableDatabase::newSelectQueryBuilder
Bug: T344971
Change-Id: Ic6940fcc06225069a0c3618c22a0e62942e5dd88
2024-05-02 23:42:08 +02:00
Tim Starling
917f0a5996 Replace all instances of "per default" with "by default"
According to the dictionary, "per" (or more conventionally "as per")
means "according to". Refer OED "per" sense II.3.a. For example:

"No value was passed, so return null, as per default".

In this sentence, we are not specifying the default, we are referring
to the default. This correct usage of "per default" was used nowhere
in MediaWiki core as far as I can see.

Instead we have "per default" being used to mean "by default", that is,
giving the value to use when no explicit value was specified.

In OED, the phrase "by default" is blessed with its own section just
for computing usage:

"P.1.e. Computing. As an option or setting adopted automatically by a
computer program whenever an alternative is not specified by the user
or programmer. Cf. sense I.7a."

There are highly similar pre-computing usages of the same phrase,
whereas the phrase "per default" is not mentioned.

As a matter of style, I think "per default" should not be used even
when it is strictly correct, since the common incorrect usage makes it
ambiguous and misleading.

Change-Id: Ibcccc65ead864d082677b472b34ff32ff41c60ae
2024-04-29 10:47:54 +10:00
Timo Tijhof
c680154389 rdbms: Update outdated docs around deprecated reuseConnection()
Bug: T326274
Change-Id: I8f2da12b59f1977177b41548233cae4f441e6146
2024-04-17 16:55:32 +01:00
Umherirrender
a89a00ffb8 tests: Migrate to IDatabase::newInsertQueryBuilder
Changed some inserts to use multi-row insert for small performance
benefit where possible and not already used.
InsertQueryBuilder does not return a value, deprecated since 1.33

Bug: T353219
Change-Id: I2380ebc8ec8db178dd790247aefbdd798b6d62ff
2024-04-14 21:56:07 +02:00
Derick Alangi
d372626b97
objectcache: Introduce ObjectCacheFactory MW service
ObjectCache is already doing a lot of factory pattern logic like
creating instances of the various BagOStuff, this should really be
the responsibility of the factory servicet.

This patch introduces a proper factory (ObjectCacheFactory) to handle
the responsibility of creating various instances of BagOStuff. Since
`newFromParams()` is a static function that gets passed in configuration
of $wgObjectCaches, that can stay that way (to keep supporting how we do
this in prod today).

Technical Breaking Change: `ObjectCache::makeLocalServerCache()` now has
a parameter and requires it but there are no callers of this method outside
MW core hence it is safe to change (and this patch update all callers) to
work correctly. Cache prefix is gotten from global state because sometimes
at this stage, the services container is not available.

Bug: T358346
Change-Id: I3179a387486377c6a575d173f39f82870c49c321
2024-03-19 12:38:39 +03:00
Tim Starling
ae994ff6ff filebackend: Refactor FileBackendIntegrationTest
FileBackendIntegrationTest was running tests against different backends
in an unconventional way, using a combination of wrapper test cases that
run tests against two different classes, and CLI options which don't
really exist anymore and have an associated fixme.

So:
* Move the bulk of FileBackendIntegrationTest to a new abstract base
  class under tests/phpunit/integration.
* Add subclasses for the FS and multiwrite test cases. This allows us to
  eliminate the wrappers.
* Add a subclass for MemoryFileBackend.
* Add a Swift subclass which replaces the main use case for
  the CLI option --use-filebackend. It is automatically enabled when
  a Swift backend is configured, similar to PostgreSQL tests.
* Some miscellaneous tests with a medium level of integration, not
  requiring backend setup and teardown, were moved to new classes
  FileBackendMultiWriteTest and FileBackendStoreTest.

Change-Id: I0da531349d7627970a7bcb34f3c1f5fd7e05cb21
2024-03-14 20:27:25 +00:00
Aaron Schulz
9135f71f64 rdbms: replace truncate() with simpler truncateTable() method
For various reasons such as support and simplicity, multi-table
TRUNCATE ends up just being a for-loop anyway. The interface is
simpler if it just takes a string table name.

Migrate callers and deprecate the old method.

Change-Id: I37ee054ca24e6ba547f8c76aec5408aaedab364b
2024-02-20 09:00:43 -08:00
jenkins-bot
ba409888a1 Merge "Clean up tests" 2024-02-16 07:58:38 +00:00
James D. Forrester
060a1b1668 Replace last remaining wfGetDB() calls in core, except ResourceLoader
Bug: T330641
Change-Id: I6d30af6ff9f667e367d39befb80c2bb0bf5fb29e
2024-02-14 11:02:01 -05:00
Matěj Suchánek
45390a52eb Clean up tests
Replace strpos with str_contains, str_starts_with, etc.
Fix spelling of "cannot" and other typos.

Change-Id: Ie52900b323f46d1978a9dd9ea3b17619b8942160
2024-02-12 09:25:25 +01:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Bartosz Dziewoński
e4c7272976 Change uses of getDBLoadBalancerFactory() to getConnectionProvider()
Update cases where one of the IConnectionProvider methods is called
immediately.

This doesn't really change anything, but I hope it helps promote
getConnectionProvider() as the common way to do this.

Follow-up to 8604c384f6.

Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
2024-01-22 22:27:45 +01:00
Aaron Schulz
129547680b Avoid phpunit failures when using --filter=PageUpdaterTest
This fixes errors in paratest since the test class previously relied
on some prior test happening to cause site_stats to be initialized,
an assumption which does not hold when classes are run concurrently.

Change-Id: Icf24db250dd3b743efbaf925c075b4e1aed25f44
2024-01-11 18:13:35 -08:00
jenkins-bot
50c37120ee Merge "modify getMutableTestUser() and use it in api query all users test" 2024-01-09 07:12:37 +00:00
Novem Linguae
f34b654631 MediaWikiIntegrationTestCase: add comment
Took some digging to figure this out. State it more
explicitly.

Change-Id: I66d52e54f3f4ee054d94c81510cfc85e1410db38
2024-01-07 00:35:30 -08:00
Ariel T. Glenn
b0c82d3784 modify getMutableTestUser() and use it in api query all users test
Change-Id: I237f0aac25435514711ad529a273a69ea91a5b30
2024-01-05 11:14:30 +02:00
Tim Starling
c23829db2b Improve ChangedTablesTracker domain handling
* Have ChangedTablesTracker take a domain as a parameter. Getting the ID
  out of it is deferred to save some nanoseconds in production.
* Split getTablesAndStop() into getTables() and stopTracking(). Make
  getTables() take a domain ID parameter.

Change-Id: I52ade87e2f0305e6f2be541df5b38c7d76c409a7
2024-01-02 17:23:05 +11:00
jenkins-bot
d972c573d0 Merge "phpunit: Load MW settings in bootstrap.php if running integration tests" 2023-12-21 07:40:16 +00:00