Commit graph

32 commits

Author SHA1 Message Date
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
Thiemo Kreuz
b95a07380a Remove meaningless ->expects( $this->any() ) from all tests
It is not entirely meaningless. It might be an indicator that
the number of calls to a method is intentionally unlimited.
This is similar to e.g. an @inheritDoc PHPDoc comment that
marks a method as being "intentionally undocumented".

However, what's the meaning of being "intentionally
unconstrained"? Let's just not have any constraint then.

I feel all these ->expects( $this->any() ) bloat the test
code so much that it's never worth it.

Change-Id: I9925e7706bd03e1666f6eb0b284cb42b0dd3be23
2021-04-23 11:58:58 +02:00
Thiemo Kreuz
40764d277c Replace PHPUnit ->returnValue() with ->willReturn() shortcut
It's the same and makes the test code much more readable, I
would like to argue.

Because of the was I split all the changes I made into smaller
patches this patch contains some other changes in the same
lines where I could not split them off. E.g. removal of
->any(), which is the default anyway and doesn't do anything.

Change-Id: Ib297b989d4aec33b31a4e33fe9d5032865b39be0
2021-04-22 10:37:45 +02:00
jenkins-bot
e6a88353de Merge "Do not use a NullLogger when no handler is declared" 2021-04-16 16:40:15 +00:00
Sébastien Beyou
0108c05cc4 Fix the test MonologSpiTest::testDefaultChannel
The NullHandler does no more implement FormattableHandlerInterface.

Bug: T196906
Bug: T242751
Change-Id: I3262b46483d3d77d25600e7ab1821bc0d4eecaad
2021-04-06 02:09:32 +02:00
Sébastien Beyou
659cd2f3ae Do not use a NullLogger when no handler is declared
This reverts the patch I124391cc7b44 because it is no more needed with
Monolog 2.x to push a NullLogger to log nothing. This patch is a
micro-optimisation for Monolog channels where nothing is logged.

Bug: T196906
Change-Id: I1f414090a37cd4d84d37a2fca8833e3623c2983f
2021-04-06 01:51:18 +02:00
James D. Forrester
b4c6a5d629 Drop Avro format option for monolog without deprecation
Bug: T265967
Change-Id: I1b46df143b71db7cc387d3239a4a4489c1f47c96
2021-03-25 08:26:17 -07:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
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
Ammarpad
56247c2d5c logger: Fix broken Monolog\CeeFormatterTest
If we pass mock datetime in the data to be formatted, the
formatter will use it, so the time string will no longer vary.

Bug: T218688
Change-Id: I4ea846cf1e908de085a551bda2bd944e846f7a36
2021-02-09 00:07:25 +00:00
Thiemo Kreuz
2f66b3754f tests: Remove @param docs from test code that just repeat the signature
These are not only 100% identical to the actual code, but also:
* It's error-prone. Some are already wrong.
* These test…() functions are not meant to be called from
  anywhere. What is the target audience for this documentation?
* There is a @dataProvider. What such @param tags actually do is
  document the provider, but in an odd place. Just looking at
  the provider should give the same information.
* The MediaWiki CodeSniffer allows to skip @param when there is
  a @dataProvider, for the reasone listed.

Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349
2021-01-21 03:41:23 +00:00
Umherirrender
3aade9e40a Use expectWarning/Deprecation/Notice/Error() in phpunit tests
It is deprecated in newer phpunit versions

Bug: T271049
Change-Id: I3b2105cbd582ecc57ab8bc1bb1617300f15682ad
2021-01-04 00:16:51 +00:00
DannyS712
6a93b0ca93 More misc test cleanup
* parent::setUp() should be first, and ::tearDown()
  should be last
* Move tests that directly extend PHPUnit\Framework\TestCase
  to /unit

Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
2020-12-24 00:52:06 +00:00
Reedy
e5d91fe516 Correctly forwardport LogstashFormatter from monolog/monolog 1.25.3
Brings in code from:
https://github.com/Seldaek/monolog/blob/1.25.3/src/Monolog/Formatter/LogstashFormatter.php
https://github.com/wikimedia/mediawiki/blob/1b3bc28/includes/debug/logger/monolog/LogstashFormatter.php

Bug: T269286
Change-Id: I2e8e36579a8b6a6c52c888300f6ea2dfa19cf9db
2020-12-02 21:35:18 +00:00
Reedy
1fa599c377 Updating monolog/monolog (1.25.3 => 2.0.2)
https://github.com/Seldaek/monolog/releases/tag/2.0.2
https://github.com/Seldaek/monolog/releases/tag/2.0.1
https://github.com/Seldaek/monolog/releases/tag/2.0.0
https://github.com/Seldaek/monolog/blob/2.0.0/UPGRADE.md

https://github.com/Seldaek/monolog/compare/1.25.3...2.0.2

Import LogstashFormatter::formatV1 from monolog/monolog 1.25.3,
so that we don't change the format

Bug: T242751
Change-Id: I0198a28a5c39631d6989abf842d8a5153ccee17d
Depends-On: I31ad7dc288ceb35e042b2fef7248a0319016fbfc
2020-11-17 15:37:18 -08:00
Umherirrender
5d41326891 Use ::class together with createMock in unit tests
This makes it easier for IDEs to find usage
This works even for non-existing classes

Change-Id: I4a6389a9bc0b3c212633841d69bd4f48a7ed6f56
2020-10-30 14:45:37 +01:00
Seb35
069c81bfe5 Empty Monolog loggers are now real blackholes and add tests
Before this commit empty Monolog loggers (or at least when no handlers are
defined) were assigned (by Monolog 1.x) the stream handler php://stderr with
the level 'debug'. This whole behaviour from MediaWiki config to Monolog is
unexpected; in the outcomes, depending on the PHP execution program, stderr
is or is not saved somewhere by default, leading to very different behaviours.

The behaviour will change in Monolog 2.x and nothing will happen is such cases
(similar hence to a NullHandler). With this commit the behaviour is uniform
accross all environments and (future) Monolog version: nothing is logged if
no handler is defined.

Precisely, a NullHandler for a given logger/MediaWiki logging channel is
defined here either when there is no key 'handlers', either when this key is
an empty array or 'false'.

Bug: T196906
Change-Id: I124391cc7b4485081980c5015431404234f40073
2020-09-20 18:11:51 +00:00
Timo Tijhof
72fda163e2 debug: Assert native deprecation in DeprecatablePropertyArrayTest
Avoid the complexity of MWDebug added in 2704be7df8.

Motivated by I1d4a166b6dff8b, which makes the native deprecation happen
always, and would otherwise make this test fail since native warnings
become exceptions in PHPUnit.

Change-Id: I83f19c26bb69b8aa5d1a91f7aa286aad56f5e64d
2020-06-17 15:23:52 +00:00
Petr Pchelko
2704be7df8 Introduce DeprecatablePropertyArray and use it for PageUpdater
Bug: T250638
Change-Id: I53e39be59228ac5a57f34d51d733d1647331889c
2020-06-09 07:09:00 -07:00
Reedy
fe94d1b39a tests: Use ::class rather than string class name
Change-Id: I50cf50e93917ba81fa846a7ea50ac2883e3167e5
2020-03-14 02:00:55 +00:00
Daimona Eaytoy
f5529400cc Stop using assertContains with string haystack
This was done automatically by replacing every assertContains with
string *needle*. Then verifying the results.

Bug: T192167
Change-Id: Id8cbbf3b01e948f80046714183cc299f86be21fd
2019-12-15 00:22:44 +00:00
Daimona Eaytoy
7c9e3db1e6 Fixes for PHPUnit 8 compatibility
Bug: T192167
Change-Id: Ic14f5debc53e55d67146dc96279d26dfd52b4000
2019-12-10 17:02:06 +00:00
Max Semenik
e14fa40ecd More backwards compatible changes for PHPUnit
The change in XmlTest is because PHPUnit 8 messes with serialization
settings.

Bug: T192167
Change-Id: I5c9358d7cfc451845e01fca67c8d15add4039dae
2019-11-12 17:07:23 -08:00
Max Semenik
dd7026585c Backwards-compatible PHPUnit 8 preparations
This commit splits changes from Ic14f5debc53e55d6714 to reduce it to
only strictly needed things. It can be merged immediately.

Bug: T192167
Change-Id: I8c541a66ea13421dbe7fa51d197d5455cc4786eb
2019-11-02 12:40:07 -07:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Max Semenik
fb06e4cd85 Update tests to use PHPUnit 6 class names
Bug: T192167
Change-Id: I42b0c8908b4968b95b08f861a40af18dc79fa0a1
2019-10-06 01:01:28 -07:00
Max Semenik
b0a8b0d275 Cleanup of old PHPUnit usage, part 3
Bug: T192167
Bug: T234597
Change-Id: I88a1ced51d7b57bc683de4a58bbeaa1537762113
2019-10-05 00:00:45 -07: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
Amir Sarabadani
57261a926c Move unit tests, round III
Depends-On: I16691fc8ac063705ba0c2bc63b96c4534ca8660b
Bug: T87781
Change-Id: I5e1ab06e3decef6cc6090551d54dc4314ab9314a
2019-07-09 22:06:59 +02: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
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