Commit graph

46 commits

Author SHA1 Message Date
Timo Tijhof
41333fa512 profiler: Inject $wgProfiler from Setup.php to Profiler
Follows-up I58ff3c193190d78a. Small step toward not run-time reading
the global (and using Config here is non-trivial/unsafe).

Change-Id: Ic527e493baabe700c50f75fadaa5b51615a5e597
2022-11-09 02:58:19 +00:00
daniel
92e8f4e40a Collect autoloader info in ExtensionProcessor
This change cleans up when and how we register autoloader info for
extensions.

This bumps CACHE_VERSION to 8, to avoid issues in case this patch gets
reverted: the new code doesn't copy the map of class files into
$info['globals']['AutoloadClasses']. If old code was to read a new cache
entry, autoloading would fail.

BREAKING CHANGE: The following methods have been removed from
  ExtensionRegistry without deprecation and without replacement.
  They had been introduced in 1.35 for use in the testing framework,
  and were not in use by any known extension:
  - exportAutoloadClassesAndNamespaces
  - exportTestAutoloadClassesAndNamespaces

NOTE: breaks the hack that SocialProfile has in place for T243861.

Bug: T240535
Change-Id: I6e1ceac034c443d9475f1adc1babecddd6af6d05
2022-06-07 17:39:00 +02: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
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
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
daniel
cf581bb2ca Define MW_INSTALL_PATH constant and BaseDirectory config.
Application logic should use the BaseDirectory config variable.
Framework code should use MW_INSTALL_PATH to locate files should.

NOTE: Update https://www.mediawiki.org/wiki/Manual:$IP

Bug: T300301
Depends-On: I7142af16d692f26e90673b058029f572c1ea3991
Change-Id: Ib4caa80bb7007c4c7960a2fd370cf5da7d9ba344
2022-03-04 14:18:27 +01:00
daniel
ecf528e552 Fix duplicate define() in bootstrap.php
wfDetectLocalSettingsFile already defines MW_CONFIG_FILE, defining
it again in bootstrap.php triggers a warning.

Bug: T301503
Change-Id: I0f2892dd803e4d7be0e3e8c8bca26b1251bc6f14
2022-02-14 15:49:52 +01: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
daniel
f5641f9856 Do not rely on $IP in DefaultSettings.php
In order to allow configuration default to come from JsonSchema,
and dynamic defaults need to be initialized in Setup.php.

This movesd the initialialization of $wgExtensionDirectory and $wgStyleDirectory
to Setup.php

Bug: T294788
Change-Id: I11f5723aa299caa210cf6a1f5b7436f191b1ffc2
2022-02-03 22:05:34 +00:00
Kosta Harlan
fbbb2fd96c phpunit: Initialize CLI options for vendor/bin/phpunit
Otherwise using the environment variables does not have any effect.

Bug: T297348
Bug: T90875
Change-Id: I0e0706648ac9397067703b16ebb9e2b7dafbe09b
2021-12-16 15:21:58 +00:00
Antoine Musso
239cf16fa2 phpunit: Include DevelopmentSettings for composer phpunit:unit
When invoking `composer phpunit:unit` without any configuration, we lack
custom logging or developer enhancements such as $wgDevelopmentWarnings.

Inject `includes/DevelopmentSettings.php` in the PHPUnit bootstrap.

The $wgMWLoggerDefaultSpi is set to LegacyLogger which requires four
global variables:
- `$wgDebugLogFile`
- `$wgDebugLogGroups`
- `$wgDBerrorLog`
- `$wgDBerrorLogTZ`

Allow `$wgDebugLogFile` and `$wgDebugLogGroups` globals to be passed to
unit tests. `$wgDBerrorLog` and `$wgDBerrorLogTZ` are not, since I don't
think that applies to unit tests.

This change does not affect integration tests run via phpunit.php, where
developers may include DevelopmentSettings.php from LocalSettings.php in
a custom order before/after their own changes, or not at all.

Bug: T291227
Change-Id: I792ca0be3456f83b86fb4ebddae4117bf387be3a
2021-10-02 22:34:33 +00:00
Amir Sarabadani
a4acd59e2e Make phpunit:unit accept extension*.json to populate the classes
Right now, for autoloading, it depends on a complex logic of
DirectoryIterator and a hard-coded set of extension.json names.

This is not useful and also doesn't pick up Wikibase extension.json
files because they are extension-repo.json and extension-client.json
which in turn causes all sorts of warnings

This patch fixes that

Bug: T243124
Change-Id: Iaf47a6f485f4ba2769b4e384278c8121366dd9a5
2020-08-07 17:45:33 +02:00
Tim Starling
9c32292a23 Call TestSetup::applyInitialConfig() from bootstrap.php
applyInitialConfig() was introduced to merge config setup between
phpunit.php and parserTests.php, but this test entry point was missed.

Change-Id: I94c8a31056127f2e3d6a0ddf47d18b9bae114abb
2020-04-21 23:40:23 +00:00
Tim Starling
d9c662397d Add MW_ENTRY_POINT to bootstrap.php
This is an entry point that we missed.

Change-Id: I0e8529568adbf2ae887e4a5ed93ca6aca5ee53ad
2020-04-01 10:12:41 +11:00
mainframe98
ac48c84224 Allow specifying autoloaded classes for tests
This introduces two new keys to the extension schema, analogous to
the existing autoloader keys: TestAutoloadNamespaces and
TestAutoloadClasses.

The classes and namespaces defined by these keys are only loaded by
the registry when ExtensionRegistry::setLoadTestClassesAndNamespaces
is called. The phpunit wrapper does this in PHPUnitMaintClass::setup.
The unit test bootstrap file calls
ExtensionRegistry::exportTestAutoloadClassesAndNamespaces instead,
similar to how it loads the regular classes and namespaces.

Bug: T196090
Change-Id: I88cf69663362fd599c20649b1df641907a02678d
2019-12-10 21:39:30 +00:00
Timo Tijhof
29e0183a56 phpunit: Repair GLOBALS reset in MediaWikiUnitTestCase
This code didn't work because the $GLOBALS array is exposed by reference.
Once this reference was broken by unset(), the rest just manipulated a
local array that happens to be called "GLOBALS". It must not be unset or
re-assigned. It can only be changed in-place.

Before this, the execution of a MediaWikiUnitTestCase test stored a
copy of GLOBALS in unitGlobals, then lost the GLOBALS pointer and
created a new variable called "GLOBALS". As such, the tearDown() function
didn't do what it meant to do, either – which then results in odd
failures like T230023

Rewrite it as follows:

* In setup, store the current GLOBALS keys and values, then reduce
  GLOBALS to only the whitelisted keys and values.

* In teardown, restore the original state.

* As optimisation, do this from setUpBeforeClass as well, so that
  there are relatively few globals to reset between tests.
  (Thanks @Simetrical!)

The following tests were previously passing by accident under
MediaWikiUnitTestCase but actually did depend on global config.

* MainSlotRoleHandlerTest (…, ContentHandler, $wgContentHandlers)
* SlotRecordTest (…, ContentHandler, $wgContentHandlers)
* WikiReferenceTest (wfParseUrl, $wgUrlProtocols)
* DifferenceEngineSlotDiffRendererTest (DifferenceEngine, wfDebug, …)
* SlotDiffRendererTest (…, ContentHandler, $wgContentHandlers)
* FileBackendDBRepoWrapperTest (wfWikiID, "Backend domain ID not provided")
* JpegMetadataExtractorTest (…, wfDebug, …, LoggerFactory, …)
* ParserFactoryTest (…, wfDebug, …, LoggerFactory, InvalidArgumentException)
* MediaWikiPageNameNormalizerTest (…, wfDebug, …, LoggerFactory, …)
* SiteExporterTest (SiteImporter, wfLogWarning, …)
* SiteImporterTest (Site::newForType, $wgSiteTypes)
* ZipDirectoryReaderTest (…, wfDebug, …, LoggerFactory, …)

Bug: T230023
Change-Id: Ic22075bb5e81b7c2c4c1b8647547aa55306a10a7
2019-09-02 20:58:34 +01:00
Kosta Harlan
d66e16afb6 Unit tests: Remove duplicated code in ExtensionRegistry
Also use wgExtensionDirectory and wgStyleDirectory in bootstrap.php, and add
clarifying comment about why ExtensionRegistry->readFromQueue is not used.

Follows-Up: I237a9f82e4d1b05cf2f08b3e4bb7ffcd8d47111c

Bug: T226911
Change-Id: I9c8e70006600c6eebbdc46dc7483a4481859ea16
2019-08-19 10:16:06 +02:00
Kosta Harlan
ed92fc2103 Tests: Allow vendor/bin/phpunit from within extension directory
Prior to this patch, one could not run this command from within an extension
directory: `../../vendor/bin/phpunit -c ../../phpunit.xml.dist tests/phpunit`,
because our code in bootstrap.php loaded "LocalSettings.php" instead of
$IP/LocalSettings.php.

Note that making this change does not result in loading LocalSettings.php when
running unit tests.

Bug: T87781
Change-Id: Iee8440f11a2bb255567646289a1986d636c12765
2019-08-14 10:30:25 +02:00
Amir Sarabadani
06f645c453 Load GlobalFunctions.php to tests/phpunit/bootstrap.php
That mostly enables testing global functions

Bug: T87781
Change-Id: Ib42c56a67926ebcdba53f4c6c54a5bff98cb77a3
2019-07-14 01:28:07 +02:00
Kosta Harlan
6140d94f45 PHPUnit bootstrap: less aggressive unsetting of globals
Previous approach caused breakage with "Notice: Undefined index: _SERVER"
messages, see e.g.
https://gerrit.wikimedia.org/r/c/mediawiki/core/+/521268#message-4502e6c209f53f6dc1c7cdf4f60e5045bbfb6ee4

Change-Id: Ief20e4e21fd99d219ebef865c603e336c2609ce2
Follows-Up: I16691fc8ac063705ba0c2bc63b96c4534ca8660b
Bug: T87781
2019-07-10 13:51:55 -04:00
Kosta Harlan
1139a9af6a Unit tests: Support unit tests in extensions and skins
For now only extensions with skin/extension.json which follow PSR-4 are
supported.

DefaultSettings is loaded in bootstrap to work around errors when unit tests are
run followed by integration tests (e.g. `vendor/bin/phpunit`)

Usage:

 - composer phpunit:unit will run all unit tests in core and any tests in
   `{extensions/skins}/tests/phpunit/unit` which also extend
   MediaWikiUnitTestCase, and which have an extension.json file
- Pass a specific directory to only run unit tests for a particular extension,
   e.g. `composer phpunit:unit -- extensions/GrowthExperiments`

Bug: T226911
Change-Id: I237a9f82e4d1b05cf2f08b3e4bb7ffcd8d47111c
2019-07-01 16:21:01 -04:00
Máté Szabó
344481f60d Move trivially compatible tests to the unit tests suite
This changeset resumes work on T89432 and related tickets
by porting an initial set of tests to the new unit test suite
separated out in I69b92db3e70093570e05cc0a64c7780a278b321a.
The tests were only ported if they worked immediately without
requiring any changes other than changing the test case class
to MediaWikiUnitTestCase and moving the test to the new suite.
If a test failed for any reason (even trivial misconfiguration),
it was NOT ported.

With this change, the unit tests suite now consits of a total
of 455 tests. As before, you can run these tests via the following
command:
$ composer phpunit:unit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ibb8175981092d7f41864e641cc3c118af70a5c76
2019-06-30 15:23:53 +02:00
Kosta Harlan
214750d8d2 Define unit and integration test suites
Following discussion in Ibb8175981092d7f41864e641cc3c118af70a5c76, this patch
proposes to further reduce the scope of what unit tests may access, by removing
the loading of DefaultSettings and GlobalFunctions.php. This also has the
implied effect of disabling the storage backend, as well as the global service
locator.

MediaWikiTestCase is renamed to MediaWikiIntegrationTestCase so it's scope and
purpose is more clear. Whether we still need to keep `@group Database`
annotation around is debatable, as it's unclear to me what the performance costs
are of implying database access for all tests which extend IntegrationTestCase.
As far as I can tell, `@group Database` is primarily used in CI to run faster
tests before slower ones, and with the new UnitTestCase the annotation seems
redundant.

To run all testsuites, use `composer phpunit`. Other composer scripts:

- `composer phpunit:unit` to run unit tests
- `composer phpunit:integration` to run integration tests
- `composer phpunit:coverage` to generate code coverage reports from unit
   tests (requires XDebug).

Note that you can pass arguments to composer scripts with `--`, e.g. `composer
phpunit:integration --exclude-group Dump`.

Other changes:

- Rename bootstrap.php to bootstrap.maintenance.php so it's clear it's part of
  the legacy PHPUnit-as-maintenance-class setup
- Create new bootstrap.php which loads the minimal configuration necessary for
  the tests, and do additional setup in the run() method of the unit/integration
	test case classes
- Move the unit-tests.xml file to phpunit.xml.dist in preparation for this being
  the default test configuration

For a follow-up patch:

- Find unit/integration tests for extensions/skins
- Migrate other test suites from suite.xml
- Support running all tests via vendor/bin/phpunit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ie717b0ecf4fcfd089d46248f14853c80b7ef4a76
2019-06-28 12:18:18 -04:00
Timo Tijhof
f28d5f772f phpunit: Call 'teardownTestDB' from shutdown instead of destruct.
This will be called right before the shutdown procedure begins,
so that all variables and classes still exist, and the hooks
can actually work.

See task for details.

Bug: T219673
Change-Id: Id6b2b4b7958b78822a0868720f7b0ba46d7b4951
2019-03-29 19:52:00 +00:00
Chad Horohoe
950368c7e8 Remove phpunit profiling. It doesn't make any sense
Change-Id: I7aa98ddc0a80f931a685e2946e61aa4a7dfdabff
2015-02-10 18:50:52 +00:00
addshore
9d69b15958 Move profile In/OUT call out of MWPHPUnitCommand
Change-Id: I710fddc20e88745c9091432dff87b5e361c1f71a
2014-05-05 12:55:56 +00:00
addshore
159dc79049 Move teardownTestDB and wfLogProfilingData out of MWPHPUnitCommand
Change-Id: Ic175c1457e7f76a2b5232a2b5d3563c5982cfee2
2014-05-05 13:55:42 +01:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
Alexandre Emsenhuber
4742232b0d Fix bootstrap in unit tests
- Remove check for version, that version is already enforced in phpunit.php,
  so there is not point showing a warning for it is useless
- Remove call to MessageCache::destroyInstance(), there is no need for it,
  since $wgMessageCacheType is set in phpunit.php before running Setup.php
- Remove includes of bootstrap.php in LanguageSrTest.php and LanguageUzTest.php

Change-Id: I4b2db6b3e6f001175e1a407c5add2972aade5e60
2013-05-03 21:45:06 +02:00
Siebrand Mazeland
791d0b2a98 Update code formatting
Change-Id: I16a9b42651f1cfb1a70dffbb67b7b83dfeb90d03
2013-04-26 14:21:20 +00:00
Siebrand Mazeland
ac63001d8e Update formatting
1 of n.

Change-Id: I852729f08bbb0c5e39c2db44362ccdc7f59dcc08
2013-02-14 12:22:13 +01:00
jeroendedauw
38c7f444e1 Use __DIR__ instead of dirname( __FILE__ )
We can now do this since we finally switched to PHP 5.3 for MW 1.20 and get rid of the silly dirname(__FILE__) stuff :)

Change-Id: Id9b2c9cd2e678197aa81c78adced5d1d31ff57b1
2012-08-27 21:45:00 +02:00
Christian Aistleitner
096592cf14 Bumping minimum supported version of PHPUnit to 3.6.7
With PHPUnit 3.6.7, we can finally check the output of tests.

Change-Id: Ib0f1afe5fd9ab9784ba7f78b2921cf047ccc83f3
2012-04-29 10:02:23 +02:00
Platonides
4ef087080d maintenance/commandLine.inc loads DefaultSettings, LocalSettings and then runs Setup.php
As Setup.php assigns variables based on the cache config, bootstrap.php was late on reseting them, as some objects were already created.
So we could end up with a SqlBagOStuff created there, which when later accessed (such as trying to invalidate the cache for a user) would 
-as any non-sqlite SqlBagOStuff- open a new db connection. Which is precisely what we shall not be done when dealing with temporary tables
(and would indeed fail miserably due to not finding unittest_objectcache table).

In summary, reenabling temporary tables disabled in r79411.
2011-02-21 23:19:26 +00:00
Alexandre Emsenhuber
51c6afc751 * Replaced $wgMessageCache by MessageCache::singleton(); since we only use one instance of this class (as for ParserCache, LinkCache)
* MessageCache::singleton() calls wfGetMessageCacheStorage() directly instead of using $messageMemc, just in case this would be called before that variable is set
* Per TimStarling: also removed deprecated methods in MessageCache class: addMessages() and related, [get|set|enable|disable]Transform(), loadAllMessages(), loadMessageFile() and some others. Same for the legacyData stuff in LocalisationCache that was only used by MessageCache::addMessages() and related. 
* Converted remaining extensions
2011-01-26 15:42:04 +00:00
Platonides
71ee20cd18 Move $wgLocalisationCacheConf disabling from bootstrap.php to phpunit.php 2011-01-21 22:44:40 +00:00
Platonides
4cb81e08f4 Move MediaWikiTestCase class to a new file and load it from phpunit.php
This restores the ability to run single tests with 
php phpunit.php includes/filename.php
2010-12-29 15:52:07 +00:00
Platonides
d74edea7e4 Follow up r79107 for old PHPUnit versions. 2010-12-29 15:21:25 +00:00
Platonides
00df670538 Fix the DELETE FROM unittest_objectcache WHERE keyname = 'my_wiki-unittest_:user:id:1 error 2010-12-29 15:11:44 +00:00
Platonides
79eb9b5bdf Follow up r79173. Pass the parameters in the right order. 2010-12-29 15:08:29 +00:00
Platonides
84709ae3b3 Follow up r79109.
Don't setup/destroy for databaseless tests.
Make needsDB() return based on the DocComment.
Delayed db init until the test is run, so that it isn't set for excluded tests (the exclusion is done after all the classes are instantiated).
2010-12-29 15:01:47 +00:00
X!
edbf743aeb Make MediaWikiParserTest work now in PHPUnit. There are still a few bugs, such as stopping tests if one fails,
lack of fuzz testing and other parser test options, and the DB creation is still a little flaky.
A MediaWikiPHPUnitCommand class had to be created to allow for custom CLI parameters.
2010-12-29 02:23:51 +00:00
X!
d5866d9ef2 Followup to r79109: Use a clean DB by default for each test 2010-12-28 18:10:18 +00:00
Chad Horohoe
5f528203aa Rename MediaWikiTestSetup to MediaWikiTestCase: this is going to be the base class for all unit tests from now on 2010-12-28 17:45:33 +00:00
X!
86df2d2755 It's here! It's finally here! The skies are falling, pigs have sprouted wings, and it's pretty cold in hell!
-Add a working PHPUnit test that instantiates a new DB, adds set data, and deleted when done.
-Add listTables() to the Database classes (only MySql and SQLite use it, and only MySQL is tested)
2010-12-28 17:15:50 +00:00
Chad Horohoe
23f69f10ed Per wikitech-l discussion: Move tests from maintenance/tests/ to tests/. They're not strictly maintenance scripts, and some people want to do a selective checkout that doesn't include the tests. There's still debate on whether we should include these in the release downloads, but we had a pretty firm consensus to move this. 2010-12-14 16:26:35 +00:00