Commit graph

82 commits

Author SHA1 Message Date
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Reedy
729f20afc8 Tests: Mark more closures as static
Bug: T274036
Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
2021-02-07 13:26:56 +01:00
Timo Tijhof
a53a38ec5e phpunit: Remove odd "MediaWiki" group from tests using it
Doesn't appear to have any meaning.

Change-Id: Id12599874f7f5bd727693b9decb190e9d5c7305d
2021-01-08 18:35:30 +00:00
Tim Starling
c8f51d1fb7 Use the old HookContainer to set up the post-reset services
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
2020-12-01 13:04:12 +11:00
jenkins-bot
5ce1ff06cd Merge "MediaWikiServicesTest: newMediaWikiServices never has parameters passed" 2020-07-08 07:27:35 +00:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00
Daimona Eaytoy
2b37cfaf18 build: Bump mediawiki-codesniffer to 31.0.0
Done with `composer fix` and suppressing the rest (i.e. sniffs for
global variables, which for core should be suppressed anyway).

Additionally, add `-p` to `phpcbf`, as otherwise it just seems stuck.

Change-Id: Ide8d6cdd083655891b6d654e78440fbda81ab2bc
2020-05-30 14:56:28 +00:00
DannyS712
9fad1ec16b MediaWikiServicesTest: newMediaWikiServices never has parameters passed
Remove unneeded handling of an optional parameter; private method, none
of the callers provide the parameter, so just drop it

Change-Id: I8e346f7f0ae66bc7d40445ac64f1b1b5dff2d76c
2020-05-22 04:22:37 +00:00
Daimona Eaytoy
8b7127c5e6 tests: Remove BC code for PHP < 7.1
MediaWiki currently requires PHP 7.2+.

Change-Id: I3456998a8323ff1a5567d1b65db5a28ea550d9c8
2020-03-09 18:12:43 +01:00
Daimona Eaytoy
6365eaab8d Autofix 94 PHPUnit 8 compat issues
Done automatically using the master version of MW codesniffer and
running composer fix.

Bug: T192167
Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
2019-12-13 15:29:10 +01:00
Thiemo Kreuz
32a429e8c4 tests: Prefer assertSame() when comparing the integer 0
assertSame() is guaranteed to not do any type conversion. This can be
critical when acciden tially comparing, for example, 0 to 0.0.

Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
2019-09-19 15:35:23 +00:00
Máté Szabó
eafbacb43c services: Do not use deprecated ReflectionType::__toString() in tests
The \MediaWikiServicesTest::provideGetService() PHPUnit data provider
method uses the ReflectionType::__toString() method to obtain the
return type of service instantiator callables as a string.

In PHP 7.4, calling this method generates an E_DEPRECATED notice.
The solution is to use ReflectionType::getName() instead, available
since PHP 7.1.[1]

This patch updates the method to use ReflectionType::getName()
if it is available, and fall back to ReflectionType::__toString()
otherwise.

---
[1] https://github.com/php/php-src/blob/php-7.4.0RC1/UPGRADING#L395

Bug: T233012
Change-Id: I69b97f75795e6c4e005bf1a23fb798f7e52da2fd
2019-09-16 21:14:07 +02:00
Legoktm
4e35134f7a Revert "Separate MediaWiki unit and integration tests"
This reverts commit 0a2b996278.

Reason for revert: Broke postgres tests.

Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
2019-06-13 23:00:08 +00:00
Máté Szabó
0a2b996278 Separate MediaWiki unit and integration tests
This changeset implements T89432 and related tickets and is based on exploration
done at the Prague Hackathon. The goal is to identify tests in MediaWiki core
that can be run without having to install & configure MediaWiki and its dependencies,
and provide a way to execute these tests via the standard phpunit entry point,
allowing for faster development and integration with existing tooling like IDEs.

The initial set of tests that met these criteria were identified using the work Amir did in
I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory
under phpunit/ and organized into a separate test suite. The environment for this suite
is set up via a PHPUnit bootstrap file without a custom entry point.

You can execute these tests by running:
$ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml

Bug: T89432
Bug: T87781
Bug: T84948
Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d
2019-06-13 22:56:31 +02:00
Max Semenik
20865b4a6f Remove CryptRand and related stuff
Deprecated in 1.31 and not used anywhere.

Change-Id: Idc2e9cec907e39cacc391fdd7e2718bd880081ae
2019-04-11 18:20:09 +01:00
Tim Starling
421b4258b5 Sort MediaWikiServices and ServiceWiring alphabetically
Don't sort them asciibetically, which is a weird sort order people only
use by accident.

Change-Id: I69be64dab104130841855f2ce58bf94667c0c300
2019-04-10 20:59:49 +10:00
Lucas Werkmeister
7585985a46 Fully extract services framework as a library
This code doesn’t use any MediaWiki-specific code, so rename
MediaWiki\Services to Wikimedia\Services and move it below libs/. (Of
course, this does not apply to the MediaWikiServices subclass.)

Class aliases are added to retain backwards compatibity for now.

Bug: T211608
Change-Id: Ic14ea28ef21c359695b309d4293dbaaf5deedc09
2019-01-16 17:31:05 +01:00
Max Semenik
ff2804804f Hard deprecate functionality replaced with random_bytes()
Deprecated in 1.32, no callers.

Change-Id: Id2d59c303fd60fab2b323af6cab137fdf74b5377
2018-10-17 19:57:52 -07:00
Aryeh Gregor
1174776e47 Don't require a list of services in tests
We already have two lists in other files, there's no need for a third.

Change-Id: I516a26e1170834b27aafeb0049a5893ec965d820
2018-08-10 04:28:31 +00:00
Aryeh Gregor
3c45e203a8 Alphabetize service lists
Adding everything at the end makes the list arbitrarily ordered, and
also invites lots of merge conflicts as new things are added.

Change-Id: I58bcca4fa79140f5d5f2f6ef447e67035cc37aae
2018-08-09 22:19:58 -06:00
addshore
f5cc67524d Introduce RevisionStoreFactory & Tests
This is based on I0a8a441b803, which was reverted because it was
incomplete.

Bug: T198701
Change-Id: I3e4a5f1ef687418c06dfc979cfe04da336e876b1
2018-08-02 18:55:29 +00:00
Kunal Mehta
fb73286fba Add PasswordFactory to MediaWikiServices
Instead of having basically every caller do:
 $pf = new PasswordFactory();
 $pf->init( RequestContext::getMain()->getConfig() );
Just create a single PasswordFactory via MediaWikiServices and pass that
around. Things that want to use their own config can still pass settings
via the new constructor.

This will eventually let us remove the init() function, removing the
only hard dependency upon MediaWiki, to make it easier to librarize
(T89742).

Change-Id: I0fc7520dc023b11a7fa66083eff7b88ebfe49c7b
2018-08-02 14:46:35 +01:00
Aryeh Gregor
1e079652e0 Introduce ContentLanguage service to replace $wgContLang
Bug: T200246
Depends-On: I31c2e20fc70ba3cbc124b9f462f4924a139dd9bd
Depends-On: I4aaf1c641ec6abef214eb96c0e4b42a67488ac00
Depends-On: I461cf2f441a4040bb15d6c4bb93ce6114c143845
Depends-On: I4b1cc4257348d1773fd2ccf045966261f801e7d0
Depends-On: I9790b7efdd484366dc36eb8880778aea1a559e5e
Change-Id: I193f5b9a95430b0a05573c361715e053e5411e32
2018-07-31 21:42:53 -07:00
Aryeh Gregor
5189333c39 MagicWordFactory to replace MagicWord static members/methods
Static members of MagicWord have been removed.

Static methods are soft-deprecated and forward to the factory.  They
will be hard-deprecated when all callers are removed from core.

MagicWord::clearCache() has been removed.  Instead, call
resetServiceForTesting( 'MagicWordFactory' ) on your MediaWikiServices
object.

Change-Id: Ie061fe90f9b9eca0cbf7e8199d9ca325c464867a
Bug: T200247
2018-07-30 21:20:43 +03:00
jenkins-bot
7ca601fd08 Merge "config: Add new ConfigRepository" 2018-07-19 14:40:26 +00:00
Florian Schmidt
418cb8d9b3 config: Add new ConfigRepository
This, for now, has the focus for holding metadata of each
configuration option inside of MediaWiki (both extensions and core).
It's very close to the Config interface and friends, and uses these
implementations to retrieve the actual value of the
configuration option.

The goal with this change is to implement a basic architecture to
allow to display the values of the curent configuration of the MediaWiki
installation on-wiki (e.g. on a special page). It also provides a
central point, where the currently known options can be fetched
from.

The long-term goal, of course, would be to get a web interface to really
configure the MediaWiki installation. But, this is more like a dream,
then a plan (from the point of view of this commit).

Next steps would be:
 * Enable ExtensionRegistry to "register" the configuration options of
   extensions, so they're available in the repo (done).
 * Find a good way to get mediawiki/core configurations into this repo
 * Work out an overall architecture to display the different possible
   values. (I think about something like different formatters for types).

Change-Id: I9419508eaa85ffc55520db7f33b3e9530fc99f00
2018-07-19 14:21:56 +00:00
jenkins-bot
368c698631 Merge "Revert "Introduce RevisionStoreFactory & Tests"" 2018-07-05 15:08:36 +00:00
Addshore
2a6af6854d Revert "Introduce RevisionStoreFactory & Tests"
This needs more work, I'll file some tickets with TODOs

This reverts commit eb39d5f945.

Change-Id: I0678d0c4e4e7496a67dfe826b00246723e9c7d54
2018-07-03 14:32:44 +01:00
addshore
72c50093a4 Add MediaWikiService::getPerDbNameStatsdDataFactory
Bug: T196609
Change-Id: I08a4909e2855e33569641166b77be5d8bf4e2c34
2018-07-02 18:31:03 +01:00
addshore
fb97a7bad3 Ensure services are added to MediaWikiServicesTest::provideGetService
Change-Id: I3f6ded009ed98b615adb7c46d41bced450972b54
2018-06-29 12:55:35 +00:00
addshore
c37c3a66b7 MediaWikiServicesTest, remove out of date note
provideGetters is now automatically populated using the
provideGetService method so we don't need to actually add
the service there

Change-Id: I07e8f54e5c4aa7ff22d02312bf51ac8d1cc4b5c2
2018-06-29 12:55:28 +00:00
addshore
eb39d5f945 Introduce RevisionStoreFactory & Tests
Bug: T194729
Change-Id: I0a8a441b803816281113e52a2a57cc07af8a1119
2018-06-29 12:55:20 +00:00
Amir Sarabadani
bd8cd912a7 Turning change_tag_def store to a service
This will be useful when reading the table.

Bug: T194162
Change-Id: I8c0a0075910a79465a648a052b4e7fbc888b10e7
2018-06-21 09:40:56 +02:00
James D. Forrester
2121cca716 MediaWikiServicesTest::testDisableStorageBackend: Make PHPUnit6 happy
Ugly, but it works.

Bug: T191678
Change-Id: I0436034370dd66191990aa195ee3bdf5cd638e76
2018-04-12 15:29:56 -07:00
addshore
e5879da149 Pass $key into CommentStore methods and use MediawikiServices
This allows CommentStore to be added to MediaWikiServices
without the need of an aditional Factory.

This change includes a compatability layer to allow the behaviour
from 1.30 to continue to be used while deprecated.

CommentStore::newKey has been deprecated.
Keys are now passed into the public methods of CommentStore
where needed.
The following CommentStore methods have had their signatures changed
to introduced a $key parameter, but when used in conjunction with
CommentStore::newKey behaviour will remain unchanged:
  * CommentStore::getFields
  * CommentStore::getJoin
  * CommentStore::getComment
  * CommentStore::getCommentLegacy
  * CommentStore::insert
  * CommentStore::insertWithTemplate

Change-Id: I3abb62a5cfb0dcd456da9f4eb35583476ae41cfb
2018-02-05 15:34:12 +00:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
addshore
d3c721fd28 Use RevisionLookup and RevisionFactory interfaces in Revision
Lets not depend on the big blob that is RevisionStore.
Try to bind to the nice interfaces that we have where possible.

In the future RevisionStore should be split up further into
it's individual interfaces.

It looks like there are some more methods which should be moved
to both RevisionLookup and RevisionFactory.
See draft:
I214c5952d4a0fad55ff4116e90eab9ac3ba54fd3

Change-Id: I8df61374e24abcf4a7e38e53647489b8ecc1fd77
2018-01-24 14:11:31 -08:00
Stanislav Malyshev
ebbfe592fe Create factory for MWHttpRequest
This will allow classes that need MWHttpRequest to inject HttpRequestFactory
and thus make it overridable and testable.

Also made MWHttpRequest abstract class since it doesn't implement
execute anyway. Maybe a good idea to move execute to an abstract
method?

Change-Id: I5c0e035542ff5f791a21a95ed13bed4cea6906d0
2018-01-23 11:39:02 -08:00
addshore
e51f95dea3 [MCR] Introduce BlobStoreFactory
This allows Revision::getRevisionText to get
a different BlobStore instance when $wiki is passed in
restoring the behaviour for $wiki before the MCR Revision
overhaul patch was merged.
Ia4c20a91e98df0b9b14b138eb4825c55e5200384

Bug: T183634
Bug: T183631
bug: T183583
Change-Id: Ib0949454e9a003c2965adc1aab38e31fcf121afe
2017-12-24 23:22:30 +00:00
daniel
6af796f3e0 MCR: Deprecate and gut Revision class
This is a re-submission of I4f24e7fbb68.

As a first major step towards Multi-Content-Revisions (MCR),
this patch turns the Revision class into a legacy proxy for
the new RevisionRecord and RevisionStore classes.

Backwards compatibility is maintained for all but some
rare edge cases, like constructing a completely empty
Revision object.

For more information on MCR, see
<https://www.mediawiki.org/wiki/Requests_for_comment/Multi-Content_Revisions>.

NOTE: once this is merged, verify create/delete/restore cycle on beta,
      ideally with emulated replication lag.

Bug: T174025
Change-Id: Ia4c20a91e98df0b9b14b138eb4825c55e5200384
2017-12-21 18:08:54 +00:00
Daniel Kinzler
09bf4f5bb2 Revert "[MCR] Turn Revision into a proxy to new code."
This reverts commit 9dcc56b3c9.

With this patch applied, newly created revisions are sometimes not found
just after submitting an edit, until replicas have caught up.

Our best theory is that it somehow interfere with ChronologyProtector,
but we don't have a good idea how.

Also, as legoktm mentioned, the commit message is terrible and needs fixing.

Change-Id: Idf3404f3fa8f8d08a7fb2ab8268726e2c1edecfe
2017-12-19 12:38:48 +00:00
daniel
9dcc56b3c9 [MCR] Turn Revision into a proxy to new code.
Change-Id: I4f24e7fbb683cb51f3fd8b250732bae9c7541ba2
2017-12-18 14:37:29 +00:00
Max Semenik
32912b8c8d Introduce Shell\CommandFactory
Bug: T177038
Change-Id: Id875e68ea1fa72b44a463f977ab52270fe1e7088
2017-10-17 18:55:11 -07:00
Umherirrender
bd741b83bc build: Updating mediawiki/mediawiki-codesniffer to 13.0.0
Change-Id: Ia24dbf015f2b4781683ca980a460d0ac3e85674e
2017-09-25 17:31:56 +02:00
Timo Tijhof
01938ae7db statsd: Rename MediawikiStatsdDataFactory to IBufferingStatsdDataFactory
Follows-up I2874175647e (7fdc3d09a3).

* Avoid "MediaWiki" in class names. If unavoidable, always camelcase.
* Use a more descriptive name, matching the implementing the class ("Buffering").
* Use "I" prefix for consistency with other MediaWiki-provided interfaces.
  (Avoid "Interface" suffix, which is foreign to MediaWiki and is only used
  in the StatsdClient namespace, which this interface is not in).

Bug: T166354
Change-Id: I06de59122625f9c23e7c1a1bfa69a7ddabbf379e
2017-07-07 17:22:50 -07:00
Kunal Mehta
399adec9ad Turn ParserCache into a service, deprecate $parserMemc
ParserCache is already a singleton, making it a good candidate for a
service. $parserMemc is an odd global (it lacks the "wg" prefix) and is
ripe for deprecation.

The following are now deprecated:
* $parserMemc global
* ParserCache::singleton()
* wfGetParserCacheStorage()

A ParserCache::getCacheStorage() method was added for cases where direct
access to the underlying BagOStuff object is necessary.

Usage of $parserMemc will emit deprecation warnings through the
DeprecatedGlobal class mechanism. All usage in core was migrated.

Also take this opportunity to inject the $wgCacheEpoch global value into
ParserCache. This will require an update to the FlaggedRevs extension.

Change-Id: I2ac7afff0d8522214329248c3d1cdccd0f72bbd4
2017-07-05 19:56:49 -07:00
Umherirrender
be42e09aa8 build: Prepare for mediawiki/mediawiki-codesniffer to 0.9.0
The used phpcs has a bug, so the version 0.9.0 could not be enforced at the moment.
Will be fixed in next version, see T167168

Changed:
- Remove duplicate newline at end of file
- Add space between function and ( for closures
- and -> &&, or -> ||

Change-Id: I4172fb08861729bccd55aecbd07e029e2638d311
2017-06-26 17:14:31 +00:00
Stanislav Malyshev
7fdc3d09a3 Refactor Statsd classes to enable null collector to work.
The following changes are added:
- Created MediawikiStatsdDataFactory interface
- Added hasData() method to see if there are any data to send
- Added getData() method to fetch data
- Made service infrastructure use MediawikiStatsdDataFactory interface
- Made wfLogProfilingData() use MediawikiStatsdDataFactory interface
- Added capability to enable/disable buffering collector

Bug: T166354
Change-Id: I2874175647e987996a9a399829b3319674471aaa
2017-05-29 15:33:02 -07:00
Timo Tijhof
447ce7e39a phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat
The default will remain PHPUnit 4.x due to PHP 5.5 support.

But, we should allow developers to run tests with newer PHPUnit
versions which are noticably faster (especially for code coverage
reports).

* <https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0>
  PHPUnit 5 deprecates the getMock() shortcut for getMockBuilder()->getMock().
  It instead introduces the shortcut createMock() which has better defaults
  than getMockBuilder(). For example, it sets 'disableArgumentCloning' and
  other things by default.

  Going forward, code should either use getMockBuilder directly and configure
  it using the setter methods (instead of the confusing variadic arguments
  of getMock) or simply use the new minimalistic createMock method. This patch
  backports the createMock method to MediaWikiTestCase so that we can start
  using it.

Change-Id: I091c0289b21d2b1c876adba89529dc3e72b99af2
2017-04-06 00:44:32 +00:00
Aaron Schulz
4a177b34ef Move LBFactory to Rdbms namespace
Change-Id: I5ae10783228d0252284807c9562bc8e328d4becb
2017-02-03 17:24:03 -08:00