Commit graph

39 commits

Author SHA1 Message Date
Umherirrender
792981fea5 tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Iddefe62c3d85281642f17e60cbc27aff47b85a67
2023-06-19 21:54:57 +02:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Umherirrender
89b2d11a0d tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ie240eb42479d19714e64cc4606e26073fadc2e13
2022-09-23 21:53:11 +02:00
Derick Alangi
9899846d10
tests: Use overrideConfigValue(s) where necessary
The files in `tests/phpunit/includes/` directory are now all
covered. Will do sub-directories of `/includes/` next.

Change-Id: I8d5655ce267b6d32cf3c7ee40dc5d2992631b5a6
2022-07-16 23:45:52 +01:00
Timo Tijhof
8d406bbcd6 phpcs: Disable Generic.Files.LineLength for test files
There is a common and reasonable need for longer lines in tests.
The nudge for shorter lines doesn't seem valuable here. The natural
breaks will likely still fall in 80-100 given the enforced practice
for non-test code, e.g. whether through habit, or 80-100 column markers
in text editors, or the finite width of diff and code review
interfaces.

Change-Id: I879479e13551789a67624ce66f0946d2f185e6ee
2022-02-18 18:32:05 +00: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
Tim Starling
8212527dfe Fix hang of ApiMainTest
If I try to run ApiMainTest with GlobalPreferences enabled, it takes
forever (or at least some number of minutes) to run. This is because
when @depends is used to transfer data from one test to another via
the return value, PHPUnit runs Enumerator::enumerate() on the data. When
it contains a reference to the active TestCase, PHPUnit ends up
iterating through its internal data structures, which takes a long time.

My conclusion is that @depends with a return value should be considered
harmful. Stop doing it in ApiMainTest. Stop recommending it in
SampleTest.

Change-Id: I63e94f2886a4ee4b3fd0ea6b19cd2fb67ba912de
2020-12-16 15:39:19 +11: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
b0a8b0d275 Cleanup of old PHPUnit usage, part 3
Bug: T192167
Bug: T234597
Change-Id: I88a1ced51d7b57bc683de4a58bbeaa1537762113
2019-10-05 00:00:45 -07:00
Thalia
ff168c8cd7 Replace old URLs in SampleTest
Update URLs to point to documentation for version 6.5, and fix a
couple of broken URLs.

Change-Id: I25211d4da19a40837d7fb7fc6219486f1a7a7c0e
2019-07-10 15:00:12 +01:00
Alangi Derick
cbdff71add Fix typo in tests/includes/SampleTest.php in core
Minor typo fix in comments for setUp() and provideTitles()
methods in SampleTests.php file.

Change-Id: I09e0fb041d6809509e780d22bf8419497cd50ee7
2018-11-02 12:55:09 +00:00
Aryeh Gregor
355e21590a Use setContentLang() instead of setMwGlobals()
This changes behavior in some tests by making them set $wgLanguageCode
as well as $wgContLang, but that seems like a good thing.

Bug: T200246
Change-Id: I936888f46ff9fefe2707efba837e2ce3a7ca5e3f
2018-07-26 11:35:58 +00:00
Kunal Mehta
38129123f2 tests: Add some more @covers tags
Change-Id: I84b66879773d97593152b683ff69d034ed67aa3d
2018-05-07 17:49:01 +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
Umherirrender
255d76f2a1 build: Updating mediawiki/mediawiki-codesniffer to 15.0.0
Clean up use of @codingStandardsIgnore
- @codingStandardsIgnoreFile -> phpcs:ignoreFile
- @codingStandardsIgnoreLine -> phpcs:ignore
- @codingStandardsIgnoreStart -> phpcs:disable
- @codingStandardsIgnoreEnd -> phpcs:enable

For phpcs:disable always the necessary sniffs are provided.
Some start/end pairs are changed to line ignore

Change-Id: I92ef235849bcc349c69e53504e664a155dd162c8
2018-01-01 14:10:16 +01:00
Umherirrender
29323f5622 Fix test class names to match convention
The test class should have Test at end
and same name as the testing class

Change-Id: Id0c90994d257fb325834e123b462f7f0849ac556
2017-12-10 11:41:59 +01:00
Fomafix
202f695f67 Update weblinks in comments from HTTP to HTTPS
Use HTTPS instead of HTTP where the HTTP link is a redirect to the HTTPS link.

Also update some defect links.

Change-Id: Ic3a5eac910d098ed5c2a21e9f47c9b6ee06b2643
2016-11-07 15:24:46 +01:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Amir E. Aharoni
4490b5b5ec Fix the last Generic.Files.LineLength phpcs failures
In both cases the long lines are inside method documentation,
and because @codingStandardsIgnoreStart comments only
work with // and not /*, they have to be outside the method comment.

Bug: T102614
Bug: T114213
Change-Id: I7343e1cf662c5bf12a5e4385646c5c2c4a798260
2015-10-03 18:08:49 +00:00
Mark A. Hershberger
372ded2fea Verify parameter for MapCacheLRU::has() can be passed to array_key_exists()
This prevents warnings from PHP from array_key_exists().

Also make sure Title::newFromText throws an exception before it can trigger this.

Bug: T76305
Change-Id: I2b36b7a3b96b37e29fe06f69c13a185b3ec592a7
2015-03-23 15:26:59 -07:00
Timo Tijhof
96771e3a65 test: Clean up data providers that should be static
Follows-up b36d883.

By far most data providers are static (and PHPUnit expects them
to be static and calls them that way).

Most of these classes already had their data providers static
but additional commits sloppily introduced non-static ones.

* ResourceLoaderWikiModuleTest, 8968d8787f.
* TitleTest, 545f1d3a73.
  Odd unused method 'dataTestIsValidMoveOperation' was introduced
  in 550b878e63.
* GlobalVarConfigTest, a3e18c3670.

Change-Id: I5da99f7cd3da68c550ae507ffe1f725d31e7666f
2014-09-18 12:52:44 -07:00
umherirrender
8a49ed2e17 Move @codingStandardsIgnoreStart into doc comment
No need to have a own comment here, because phpcs support this.

Change-Id: I7ec0ed4d174417d054eb8578519ae15eda4055ac
2014-08-19 21:55:22 +02:00
Chad Horohoe
f129b1baf9 Limit test leakage, $wgCapitalLinks expected to be true
Change-Id: I0f837d29595abefaebeb67d6cc62ea48838d626a
2014-07-07 16:54:35 -07:00
Siebrand Mazeland
d5df012a13 Pass phpcs-strict on some test files (3/x)
Change-Id: I44172b512cd9b6c43806dad697e449bf06897305
2014-04-24 18:51:39 +02:00
addshore
909c3e33c0 Cleanup SampleTest.php
Removes stuff which isnt true

Change-Id: I9696fa2e7f969e1d4bcf234a05031fc9ed784227
2014-03-07 20:58:10 +01:00
addshore
de7af7ac2c Fix scope on all /phpunit test methods
Change-Id: I3ce92463d485a0fb23e464e9a8059330f32d79af
2013-10-24 10:31:32 +02:00
Siebrand Mazeland
7a24666935 Update formatting
2 of n.

Change-Id: I5406673e99ed53e4e330ed47f022a17177544daa
2013-02-14 12:36:35 +01:00
Antoine Musso
0fd05285d7 pass codesniffer on tests/
Fix almost all occurences of the following sniffs:

Generic.CodeAnalysis.UselessOverridingMethod.Found
Generic.Formatting.NoSpaceAfterCast.SpaceFound
Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma
Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine
Generic.PHP.LowerCaseConstant.Found
PSR2.Classes.PropertyDeclaration.ScopeMissing
PSR2.Files.EndFileNewline.TooMany
PSR2.Methods.MethodDeclaration.StaticBeforeVisibility

Change-Id: I96aacef5bafe5a2bca659744fba1380999cfc37d
2013-01-28 12:14:26 +01:00
Antoine Musso
92b4b7340b worthwhile tests in testTitleObjectStringConversion
The previous tests were not reflecting their comment, I have tweaked the
assertions a bit to actually test something that reflect the comments.

Change-Id: Ie1764ee1a218ead0169958704ba8625ab8d56445
2012-12-07 16:39:39 +01:00
Ori Livneh
237207bf0e Fix typo (sentances => sentences)
Change-Id: Ifaec0d0bd24703dbe80ab1869366b404aa001cce
2012-11-27 15:27:45 -08:00
Alexandre Emsenhuber
07818096df (bug 35204) set wgLanguageCode in unit tests
Setting $wgContLang without changing $wgLanguageCode accordingly is a
very bad idea.

This caused about 20 exceptions when using LanguageCode set to 'fr'
on my installation:

"MWException: Error in MediaWikiLangTestCase::setUp(): $wgLanguageCode
('fr') is different from $wgContLang->getCode() (en)"

Follow-up of I2987db68 (2b0edc8).

Change-Id: I56d3f1bfc78d6a2e40460533524e82f360490206
2012-11-17 09:53:34 +01:00
Timo Tijhof
181c7cdc8e Clean and repair many phpunit tests (+ fix implied configuration)
This commit depends on the introduction of
MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4.

Various tests already set their globals, but forgot to restore
them afterwards, or forgot to call the parent setUp, tearDown...

Either way they won't have to anymore with setMwGlobals.

Consistent use of function characteristics:
* protected function setUp
* protected function tearDown
* public static function (provide..)

(Matching the function signature with PHPUnit/Framework/TestCase.php)

Replaces:
 * public function (setUp|tearDown)\(
 * protected function $1(

 * \tfunction (setUp|tearDown)\(
 * \tprotected function $1(

 * \tfunction (data|provide)\(
 * \tpublic static function $1\(

Also renamed a few "data#", "provider#" and "provides#" functions
to "provide#" for consistency. This also removes confusion where
the /media tests had a few private methods called dataFile(),
which were sometimes expected to be data providers.

Fixes:

TimestampTest often failed due to a previous test setting a
different language (it tests "1 hour ago" so need to make sure
it is set to English).

MWNamespaceTest became a lot cleaner now that it executes with
a known context. Though the now-redundant code that was removed
didn't work anyway because wgContentNamespaces isn't keyed by
namespace id, it had them was values...

FileBackendTest:
* Fixed: "PHP Fatal: Using $this when not in object context"

HttpTest
* Added comment about:
  "PHP Fatal: Call to protected MWHttpRequest::__construct()"
  (too much unrelated code to fix in this commit)

ExternalStoreTest
* Add an assertTrue as well, without it the test is useless
  because regardless of whether wgExternalStores is true or false
  it only uses it if it is an array.

Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-09 03:01:51 +02:00
umherirrender
a9a71011ff Change some NS_IMAGE to NS_FILE
Change-Id: Id530c88d24df1a47a2f6565911184008b67fe04d
2012-06-24 21:50:10 +02:00
Platonides
f927b699af Follow-up r90150, another parent::setUp missing. 2011-06-15 21:03:08 +00:00
Platonides
de2cdf3fc5 Thou shall call parent::tearDown(), MediaWikiLangTestCase child.
Follow up r87210. This has been hurting my tests for weeks.

Made TimeAdjustTest extend MediaWikiLangTestCase.
2011-06-14 21:21:26 +00:00
Platonides
10cd6f1b6a Fix the old XmlTest.php test bug in the dateMenu() when the wiki is configured for a languange other than English
Other tests were running before and messing with the Language objects.
2011-05-01 19:32:49 +00:00
Sam Reed
0bf458ec62 Apply phase3 related Title fixes. With one minor addition, Title constructor marked as protected, "just in case"...
Patches by Yuvi Panda

From (bug 28583) Remove all /* private */ declarations in MediaWiki core
2011-04-18 23:20:21 +00:00
Chad Horohoe
447529064b * verbose and color default output from phpunit
* Make a bunch of tests subclass MediaWikiTestCase
* Parser tests and ResourceLoaderTest can't subclass it yet due to various issues
2010-12-28 18:17:16 +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