Commit graph

193 commits

Author SHA1 Message Date
daniel
c6c62e2c8f PHPUnit: enable main object cache in tests
This sets MainCacheType to 'hash', so the main cache is functional
within test cases. Between tests we are already calling ObjectCache::clear,
so the cache will not leak data into other test cases.

It turned out that the way we have been overriding configuration
settings in MediaWikiIntegrationTestCase is insufficient, since the
overrides would only apply in the main Config object, not in global
variables. This means they could not be overwritten with setMwGlobals.
So this patch also changes how we apply config overrides for test setup.

Config overrides that happen during tests work as before.

Depends-On: Ic36e92b73f22fd64e2d0b680d8e900f598158460
Change-Id: Ia60cb0bc18b235f23d9778da8241f65accfc0d35
2022-07-07 16:26:03 +10:00
daniel
bf092744c9 PHPUnit: introduce setMainCache
The main object cache is disabled during testing. Some integration tests
need it though. This provides a clean way to enable it, to replace the hacks
that were used so far.

Note that we may want to enable the main cache during testing soon. When
that happens, this method is still useful to disable the cache in certain
tests, and to set a specific cache instance.

Change-Id: I04ae1bf1b6b2c8f6310acd2edf89459d01a9c870
2022-07-07 16:25:59 +10:00
jenkins-bot
0f75ef7180 Merge "Use HashConfig to override config variables in phpunit tests" 2022-07-07 05:13:52 +00:00
daniel
ac7138d45b Use HashConfig to override config variables in phpunit tests
This implements config overrides with a HashConfig that is layered on
top of the base config, so we can move away from global variables.

Global variables are still updated using setMwGlobals, for compatibility
with code that is still reading configuration from global variables.

This fixes an issue with the default overrides not being applied to
global variables.

Change-Id: I1922d9b903dcafb83691c2d96790f72747eeef9c
2022-07-07 14:54:06 +10:00
Umherirrender
6629932569 tests: Remove unneeded Title::newFromLinkTarget calls
Use the page identity from RevisionRecord instead

Change-Id: I80550f41645b55278b085968295ed016c212934c
2022-07-05 23:57:30 +02:00
jenkins-bot
bf5806d4ff Merge "tests: Move assertHTMLEquals to the test case trait" 2022-06-24 01:51:57 +00:00
daniel
033060bbaa PHPUnit: introduce overrideConfigValues.
overrideConfigValues() is introduced as a replacement for
setMwGlobals(). Since we are moving away from reading configuration
from global variables, test cases should not use global variables to set
configuration.

Bug: T294739
Change-Id: I9d41045bd13932bd853f53e00322233fc4f1321c
2022-06-21 13:29:29 +02:00
mainframe98
3fd374e974 tests: Move assertHTMLEquals to the test case trait
This allows accessing it in both integration and unit tests.

Bug: T310514
Change-Id: I5c97364cbdc81fe67f156cffb04b252af7ccf6ff
2022-06-13 15:32:57 +00:00
Lucas Werkmeister (WMDE)
acae1c5107 Revert "phpunit: Default to vendor/bin/phpunit, remove suites.xml"
This caused unexpected problems with no obvious fixes. Needs more work.

This reverts commit 7238dff532.

Bug: T310255
Bug: T90875
Change-Id: I3758cbb6d0029b20ec1b0f67dbf2f422031c50ae
2022-06-09 14:15:54 +00:00
Kosta Harlan
7238dff532 phpunit: Default to vendor/bin/phpunit, remove suites.xml
* switch to phpunit.xml.dist instead of suites.xml
* switch composer.json to vendor/bin/phpunit
  * tests/phpunit/phpunit.php is retained but will be removed after CI
    jobs and other references on
    codesearch (https://codesearch.wmcloud.org/search/?q=tests%2Fphpunit%2Fphpunit.php&i=nope&files=&excludeFiles=&repos=)
    are removed
* add a default bootstrap.integration.php; unit tests in
  composer.json use the non-MW bootstrap file (bootstrap.php)
  * Migrate the phpunit.php logic into tests/phpunit/BootstrapIntegrationWrapper.php

Depends-On: I19d560bdcdb2ee914ab055e094841f2b5db8be55
Depends-On: Ib23209fc3b095e3c012ed84ce5c11f8b2d27b898
Co-authored-by: Daimona Eaytoy <daimona.wiki@gmail.com>
Bug: T227900
Bug: T90875
Change-Id: I82045c207738d152d5b0006f353637cfaa40bb66
2022-06-08 18:31:16 +00:00
Amir Sarabadani
24115a8f4c Start clean up of revision_actor_temp table
It is being dropped in production

Bug: T215466
Change-Id: I66b2cb8653252e720c897351065978119f040ba7
2022-05-23 15:37:42 +00:00
daniel
237bbf089f Turn DefaultSettings.php into a deprecated stub
DefaultSettings.php has been replaced by MainConfigSchema.
Loading DefaultSettings.php is deprecated.

Code that needs to have access to configuration defaults should use the
ConfigSchema service object.

Bug: T300129
Change-Id: I7b2c0ca95a78990be1cdb9dd9ace92f6dcf1af15
2022-05-17 16:50:56 +02:00
Amir Sarabadani
a294e715a4 rdbms: Replace getConnection with getLazyConnectionRef
This would simplify the code for its users a lot.

Bug: T255493
Depends-On: I6ab4440a13f4682dd3a6e9cfc6c629222fbeab8a
Change-Id: I6e7544763bde56fc1e19de0358b71ba984a978ca
2022-05-12 07:43:03 +02:00
jenkins-bot
654ccb3a4c Merge "Setup.php: clarify the use of $IP." 2022-05-04 18:10:39 +00:00
daniel
bedd996fe6 Setup.php: clarify the use of $IP.
The global variable $IP has been replaced by the MW_INSTALL_PATH
constant. Clarify the continued use of $IP on Setup.php.

Change-Id: I157abfd9049fb8382da53005a084ab86f47e8d8a
2022-05-03 11:53:05 +02:00
Aryeh Gregor
79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00
Daimona Eaytoy
0a6ec1031a Move wfRequireOnceInGlobalScope to TestSetup
TestSetup seems a nice place for this function. This way, it can also be
reused in the other boostrap file whilst we migrate the entrypoint.
Also, replace the check in MediaWikiIntegrationTestCase with another
constant; this also makes it easier to understand when exactly that code
should run.

Bug: T90875
Change-Id: I7858d982378ab4b6f11c4e9bf955d83d1acbc85d
2022-04-25 12:52:58 +00:00
Aaron Schulz
218b68ed4c rdbms: add $fname parameter to LBFactory::closeAll() for better logging
Change-Id: I2f4b6466c22c89d7515290324e8e2e2f720ada61
2022-04-05 21:39:21 +00:00
Aaron Schulz
0381118090 phpunit: Set $wgSQLMode from DevelopmentSettings instead of MediaWikiIntegrationTestCase (ii)
This reverts commit 17bab86e7a.

Extension failures (ref T304625) have since been fixed.

Bug: T225730
Change-Id: Ia452e076bdce45f1151f970c16837b80813ee08a
2022-04-04 21:36:14 +00:00
Alexander Vorwerk
17bab86e7a Revert "phpunit: Set $wgSQLMode from DevelopmentSettings instead of MediaWikiIntegrationTestCase"
This reverts commit 8a54b5ec38.

Bug: T304625
Change-Id: Id54589603d56aa87b6a1e7d9570ebba5346dd70c
2022-03-24 16:55:02 +00:00
jenkins-bot
b89c59ba9a Merge "phpunit: Set $wgSQLMode from DevelopmentSettings instead of MediaWikiIntegrationTestCase" 2022-03-24 14:51:48 +00:00
Aaron Schulz
8a54b5ec38 phpunit: Set $wgSQLMode from DevelopmentSettings instead of MediaWikiIntegrationTestCase
This avoids a large number of SET query pairs during tests.

Bug: T225730
Change-Id: Ic2729428297162763a772e6a16549ded8de06c01
2022-03-24 09:13:54 +00:00
Aaron Schulz
509614bbda Improve handling of class-level test setup failures in run()
Signal that the test run needs to stop and record the exception via
addError() so that it will be displayed in the output and the exit
code will reflect test failure.

Previously, errors would cause the tests to suddenly stop, and any
buffered output about previous errors, warnings, and failed tests
was lost.

Bug: T292239
Change-Id: I5b2a7bcbb38760fcd10fccfbf000f4a8511f8774
2022-03-21 21:43:07 -07:00
jenkins-bot
5ec380a8f6 Merge "Integration test for extension registration" 2022-03-16 17:05:36 +00:00
Aaron Schulz
7ee3bc9334 Improve ensureMockDatabaseConnection() error message
Bug: T292239
Change-Id: I8f892d0148cbd3f475751d71143ac07a4b3b29d6
2022-03-15 20:07:57 -07:00
daniel
1c7ffcd46a Integration test for extension registration
This adds full integration tests for extension registration, ensuring
that ExtensionProcessor and ExtensionRegistry work together as expected.

The existing tests for ExtensionProcessor and ExtensionRegistry are
converted to "pure" unit tests.

This change is intended to protect against bugs while refactoring
ExtensionProcessor and ExtensionRegistry to better integrate with the
new SettingsBuilder class.

Bug: T297166
Change-Id: I2d9cc373b8a4aa014aef93b0a8e8d83758851783
2022-03-11 21:43:41 +00:00
Tim Starling
1bfa449f8e In BackupDumperPageTest, don't overwrite self::$dbClone
BackupDumperPageTest called MediaWikiIntegrationTestCase::
setupDatabaseWithTestPrefix() on a new private connection, overwriting
self::$dbClone. This can cause a fatal error on shutdown due to
self::$dbClone->destroy() being called after connection close. Hopefully
it also fixes the CI failure observed at I200f90e413b8a725828745f81925b.

Also, the method was documented as returning bool, but in fact it always
returned true.

So, move the responsibility for setting self::$dbClone to the only
caller where that makes sense. Have BackupDumperPageTest call
CloneDatabase::destroy() during test teardown.

Change-Id: I2a4cefe6207c02cc12b906d66f6016440e16b249
2022-03-09 15:49:28 +11:00
Timo Tijhof
128debb64b tests: Change use of AtEase to at operator
Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359.

Per T253461, not mass-changing source code, but the use of the native
error silencing operator (@) is especially useful in tests because:

1. It requires any/all statements to be explicitly marked. The
   suppressWarnings/restoreWarnings sections encourage developers to
   be "lazy" and thus encapsulate more than needed if there are multiple
   ones near each other, which would ignore potentially important
   warnings in a test case, which is generally exactly the time when
   it is really useful to get warnings etc.

2. It avoids leaking state, for example in LBFactoryTest the
   assertFalse call would throw a PHPUnit assertion error (not meant
   to be caught by the local catch), and thus won't reach
   AtEase::restoreWarnings. This then causes later code to end up
   in a mismatching state and creates a confusing error_reporting
   state.

See .phpcs.xml, where the at operator is allowed for all test code.

Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
2022-02-24 21:29:51 +00:00
Reedy
12aae45101 tests: Replace some usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I361fde0de7f4406bce6ed075ed397effa5be3359
2022-02-24 12:55:25 +00:00
Tim Starling
e582572622 Improve ObjectCache integration tests
* Add BagOStuffTest subclasses for all core BagOStuff subclasses,
  replacing PHPUNIT_USE_BAGOSTUFF, as suggested in a todo comment.
* Add config $wgEnableRemoteBagOStuffTests which causes all tests
  enabled by $wgObjectCache to execute, which means that the memcached
  tests are executed by default.

I have verified all except RESTBagOStuff and WinCacheBagOStuff. The
memcached tests fail against memcached 1.5.x but pass against memcached
1.6.x.

Bug: T90875
Change-Id: Id74b5226669f8cb857f859fbc35bc58ab001e873
2022-02-11 10:20:33 +11:00
daniel
dcef1674a5 Allow main settings file to be selected via env variable.
This allows a file other than LocalSettings.php to be used as the primary
settings file by setting the MW_CONFIG_FILE environment variable.
This also allows the primary settings file to use YAML or JSON format.

Using static configuration files should be the default in the future.
However, YAML files in the document root could easily be exposed to the
public. Better not to encourage that, and require them to be enabled
explicitly and loaded from a different place.

Bug: T294750
Change-Id: I7747f83481cb05a6d05f819be652259951183819
2022-02-06 21:13:00 +01:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
jenkins-bot
fd84c0f087 Merge "tests: Replace usages of deprecated WikiPage::doDeleteArticleReal" 2022-01-27 19:32:06 +00:00
Tim Starling
c38285c5bf Fix PHP 8.0 failure of RefreshSecondaryDataUpdateTest
"TypeError: preg_replace(): Argument #3 ($subject) must be of type
array|string, null given"

Bug: T283275
Change-Id: I4be7dfafe56fd8a46f7ef3d0a743c2036e6fb40d
2022-01-21 15:17:44 +11:00
Daimona Eaytoy
2688c59606 tests: Replace usages of deprecated WikiPage::doDeleteArticleReal
Add a new helper to MediaWikiIntegrationTestCase, since deleting pages
seems to be pretty common in tests.

Some calls to WikiPage::factory were also updated to use WikiPageFactory.

Change-Id: I5b5100273a00ac292a1900022ca79708fa254347
2022-01-17 15:38:02 +00:00
Kosta Harlan
0c2cc804e1 phpunit: Use is_file/is_dir instead of file_exists
Yes, it's a micro-optimization. See https://bugs.php.net/bug.php?id=78285
and https://thephp.cc/articles/caching-makes-everything-faster-right
for more info.

Change-Id: Ib8e8e9794e15066476f35cdb1236df8b983274d6
2022-01-03 21:47:56 +01:00
Thiemo Kreuz
b4c63c64ae Remove some more comments that literally repeat the code
Nothing to learn from these.

You can find a longer explanation in the comments in I93751e6.

Change-Id: I195aae70fc282b58be5b18160783f27d38605d15
2021-12-09 19:01:36 +01:00
Alexander Vorwerk
bf56204a44 Remove the MediaWikiTestCase class alias
Bug: T293043
Depends-On: I53852a255ceeab8083d0f5354949929df6c55b96
Change-Id: I477c0dfcb7bbb53a9972ce6b48acb470118c1ace
2021-12-05 13:50:40 +00:00
jenkins-bot
683495458e Merge "MediaWikiIntegrationTestCase::getExistingTestPage: Don't assume NS0 is wikitext" 2021-09-16 20:34:55 +00:00
DannyS712
a2b20b63d7 Emit deprecation warnings reading from $wgUser
With this patch deprecation warnings will be emitted
if $wgUser is accessed or written into. The only pattern
of usage still allowed is

$oldUser = $wgUser;
$wgUser = $newUser;
// Do something
$wgUser = $oldUser;

Once there is no deprecation warnings, we know that nothing
legitimately depends on $wgUser being set, so we can safely
remove the code that's still allowed as well.

Bug: T267861
Change-Id: Ia1c42b3a32acd0e2bb9b0e93f1dc3c82640dcb22
2021-09-15 20:17:04 -07:00
James D. Forrester
f4eef180a0 MediaWikiIntegrationTestCase::getExistingTestPage: Don't assume NS0 is wikitext
Found in the WikiLambda extension following the landing of 2b24f6d20.

Change-Id: I19aa4c9833e3659325977beac7d790045da73df1
2021-09-13 09:48:55 -07:00
James D. Forrester
eeaec4ce6b ExternalStoreDB: Rename getMaster to getPrimary
Bug: T282894
Change-Id: I6d6361a0b84f7130a27df6a6c75a983c73e5dd95
2021-09-03 13:44:04 -07:00
Tim Starling
0fc428c803 Make IResultWrapper extend Countable
Provide ResultWrapper::count() as an alias for numRows(), and implement
Countable, so that you can do count($res).

Change-Id: Id9909f7143dae623b318b2fb24205c3e58a7d178
2021-08-30 14:19:45 +10:00
Fomafix
c7ebc1ec44 Fix various typos in documentation
Bug: T201491
Change-Id: I144c120cc88bda723c8608ed7fb0ccb709f295f1
2021-08-23 09:03:44 +00:00
Petr Pchelko
dc321179c9 Utility in MWIntegrationTest to skip is extension not loaded
For testing extensions that optionally depend on other
extensions this is rather useful.

Change-Id: Id996abdb353547b95d795494ba961b9a215ef2ef
2021-08-13 18:39:31 +00:00
Petr Pchelko
39c6c5e34c Tests: reset ParserOptions static cache with MW services
ParserOptions store the result of ParserOptionsRegister
hook execution in a static cache. If we register a lazy
option, which depends on user options and use OptionsLookup,
tests break because a lookup from a destroyed service container
ends up being reused between tests.

The reset was added to resetLegacyGlobals because 1) it's
called at all the right times 2) this static cache is legacy,
when we have a factory service for ParserOptions, this will
not be needed anymore.

Change-Id: I9e820045443be1df2c89e1ed4b56f0d55662c486
2021-08-10 09:11:19 -07:00
Petr Pchelko
0484ac9e7a Remove deprecated Language::$mLangObjCache
Removing this deprecated cache allows LanguageFactory
to start using MapCacheLRU instead of implementing
LRU semantics manually.

Change-Id: I8093067fb6f51110351b8592fcbcfa7559d942ee
2021-07-26 06:28:18 -07:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
James D. Forrester
719cf161f2 More master -> primary documentation and internal var renaming
Bug: T254646
Change-Id: I63cc8895033714bdfbf09aee933a8f0a43b387f3
2021-07-15 11:20:20 +01:00
DannyS712
b0ab985420 Fix some @stable for ... annotations to use @stable to ...
Bug: T257789
Change-Id: I3ba94a9d6b739cd57cd57afe5d397963127160a8
2021-07-08 02:54:59 +00:00