aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/suites
Commit message (Collapse)AuthorAgeFilesLines
* tests: Use namespaced classesUmherirrender2024-10-211-9/+9
| | | | | | | | Changes to the use statements and some additions are done automatically via script This also updates @covers tag for the namespaced classes Change-Id: I859ba6d05018c99710b744e2becab432410d3bca
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-163-3/+3
| | | | | | | | | | | Implicitly marking parameter $... as nullable is deprecated in php8.4, the explicit nullable type must be used instead Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a Break one long line in SpecialPage.php Bug: T376276 Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
* tests: Make use of ??= and ?? operators in various teststhiemowmde2024-08-151-3/+1
| | | | | | | The main benefit is that this syntax avoids repeating the variable name. It does the same as before. Change-Id: I2040be889c749f4e2416ca9948ba261345858af2
* Add MediaWiki\Registration namespace to registration classesEbrahim Byagowi2024-08-101-0/+1
| | | | | Bug: T353458 Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
* tests: Use namespaced classes (@covers)Umherirrender2024-06-141-1/+1
| | | | | | Some fixes done via codesniffer fix (Ibd0f48e14e) Change-Id: I0404ceca7c5abe8d32ef9a8fce404c7b89ffbaae
* parsertests: Misc cleanupDaimona Eaytoy2024-03-153-18/+18
| | | | Change-Id: Id1b073d80e896a26493206141bddfcf65c171d0b
* tests: Fix @covers and @coversDefaultClass to have leading \Reedy2024-02-161-11/+11
| | | | Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
* Clean up testsMatěj Suchánek2024-02-121-2/+2
| | | | | | | Replace strpos with str_contains, str_starts_with, etc. Fix spelling of "cannot" and other typos. Change-Id: Ie52900b323f46d1978a9dd9ea3b17619b8942160
* Merge "tests: Use namespaced class names in @covers annotations"jenkins-bot2024-01-271-1/+1
|\
| * tests: Use namespaced class names in @covers annotationsUmherirrender2024-01-271-1/+1
| | | | | | | | | | | | Assist from 8c9cb701e56226cac43fee2fa24b0d0e586f1733 Change-Id: I47897c499028d9e24c00ad0bc6ba7fd8002d9bc1
* | ParsoidTestFileSuite: Fix use of undefined $runnerOpts variableSubramanya Sastry2024-01-261-2/+2
|/ | | | | | | | | | | | | * be3018b2 removed the definition of local variable $runnerOpts from a closure since it was unused within the closure. It was referenced outside the closure but that was clearly buggy. Some other refactoring before be3018b2 likely broke this. * Looks like this bug has no real impact in typical test runs because of the "?? null" which hid the undefined access to $runnerOpts from when $runnerOpts is defined but 'selser' is not set there. Change-Id: I0df36653de4c70c7a4669b874f43385a18ac5e9d
* phpunit: Make getPHPUnitExtensionsAndSkins run the UnitTestsList hookDaimona Eaytoy2023-11-131-7/+12
| | | | | | | | | | | | | | | | | | | | | In a future with a single bootstrap and config, we won't be able to run hooks as early as in ExtensionTestSuite::suite. On top of that, if the config file does not fully load the MW config (as is the case with bootstrap.php), it won't even be possible to run hooks at all. So move the relevant code from ExtensionsTestSuite to getPHPUnitExtensionsAndSkins, collect the output in bootstrap.php and pass it to ExtensionsTestSuite. This hack wouldn't be necessary if the UnitTestList hook didn't exist, but fortunately there are plans to get rid of it (T298509). Keep the old code in place when entering from an entry point that doesn't load bootstrap.php (i.e., phpunit.php and composer phpunit:entrypoint). Bug: T227900 Change-Id: Idf72db24dbd66bb66baf51564a7504d2bc035e8c
* phpunit: Determine what extensions to load in unit tests via configDaimona Eaytoy2023-09-252-0/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When running unit tests, the bootstrap would previously load all extensions and skins in the filesystem. This was OK for an initial implementation, but is not acceptable if we want to eventually do that for all PHPUnit entry points (once we'll have a single config and bootstrap). Instead, it's desirable to only load the extensions specified in LocalSettings.php. The problem is that it's pretty much impossible to load LocalSettings.php without also loading the rest of MediaWiki, with all the side effects this might have. This patch introduces a helper script that loads all the config, then prints what extensions and skins were loaded. The bootstrap file runs this script via proc_open and then reads the list of extensions to load. Because the script is run in a separate process, any side effects only affect the spawned process, not the one where PHPUnit is running. Currently, there doesn't seem to be a better way to obtain the list of extensions loaded in LocalSettings.php without all the other side effects. YAML settings (https://www.mediawiki.org/wiki/Manual:YAML_settings_file_format) would probably help, but that's very far from becoming the only supported config format (if it will ever be). Also add two TestSuite implementations to replace the '*' wildcard in the extensions:unit and skins:unit suites. These use the same list of loaded extensions to determine where to look for tests. And last but not least: my most sincere apologies to you if the hack you're seeing here has ruined your day. If you think a better approach exists, please tell me and I'll be so relieved! Bug: T227900 Change-Id: Ib578644b8a4c0b64dca607afb9eb8204ca7fc660
* Namespace Sanitizer under \MediaWiki\ParserJames D. Forrester2023-09-211-1/+1
| | | | | Bug: T166010 Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
* phpunit: Delete DummyExtensionsTestDaimona Eaytoy2023-07-171-16/+0
| | | | | | | | | | | | | | | | | | | A code comment says that this code is necessary to avoid warnings like "No tests in class ...", but I wasn't able to reproduce the warning in question. This code was added in https://w.wiki/73Wv, in 2010. I guess PHPUnit might have changed enough over the last 13 years to no longer emit this warning. A quick look at the TestSuite class suggests that the warning is not emitted when the constructor is called with a string, which is what we're doing. Things might change in PHPUnit 10, but TestSuite::__construct was made private, so I think we may have to rewrite our suites anyway. Change-Id: Ie044900ffcffca9c8f0d96b425271a2eda90a5cd
* Replace usages of deprecated MWExceptionDaimona Eaytoy2023-06-062-2/+2
| | | | | | | Use SPL exceptions instead when the exception is unchecked. Bug: T328220 Change-Id: Ia1e5edc2ef3269a44b670262b78b305d07559829
* Replace internal Hooks::runnerUmherirrender2023-05-111-1/+3
| | | | | | | | | The Hooks class contains deprecated functions and the whole class is going to get removed, so remove the convenience function and inline the code. Bug: T335536 Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
* Remove LessFileCompilationTestTim Starling2023-05-021-37/+0
| | | | | | It's redundant with ResourcesTest::testRespond. Change-Id: Ibfe15821c3fb8d3ff4ca03bc5b9150d5bd2f32ce
* ParserTestRunner: Additional refactoring and cleanupSubramanya Sastry2023-04-111-4/+1
| | | | | | | | | Clean up to bypass skipped tests early in both legacy and parsoid test runs without duplicating the skipped test check. Also got rid of two FIXMEs with this refactoring. Change-Id: I854f89bd823aab297efe29cd4fdee675afd77752
* Just another 80 or so PHPStorm inspection fixes (#4)Tim Starling2023-03-251-2/+1
| | | | | | | | | | | | | * Unnecessary regex modifier. I agree with this inspection which flags /s modifiers on regexes that don't use a dot. * Property declared dynamically. * Unused local variable. But it's acceptable for an unused local variable to take the return value of a method under test, when it is being tested for its side-effects. And it's acceptable for an unused local variable to document unused list expansion elements, or the nature of array keys in a foreach. Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
* Followup to 02d13afa: Respect parsoid-compatible options in CLI runsSubramanya Sastry2022-10-251-10/+2
| | | | | | | | It was possible to run non-compatible tests via the CLI which, among other things, would have caused a "--parsoid --updateKnownFailures" test run to add bogus entries to the knownFailures json file. Change-Id: Ie3c51b97edb9839f775301670018bb4ba3290fbe
* Auto-discover core parser test filesC. Scott Ananian2022-10-131-1/+0
| | | | | | | | | | | | | | Make parser test discover in core work the same way as it does in extensions: any file ending with *.txt under tests/parser is run as a parser test file. This search is recursive, which is motivation to also move some unrelated files under tests/parser/preprocess over to tests/phpunit/data/preprocess where they belong; they are used by tests/phpunit/includes/parser/PreprocessorTest.php and are unrelated to the parser test infrastructure. Change-Id: I8c84b4b853e1309929dceb700aab1e79a598d8ab
* Remove $wgParserTestFiles, deprecated in MW 1.30C. Scott Ananian2022-10-131-5/+13
| | | | | | | This global variable was replaced by auto-discovery of parser test files in extensions and is no longer needed (or used). Change-Id: Ib616e60f36db32ffd8bc69c71a096f23c0a27910
* Followup on 02d13afa: Unbreak Parsoid parser test runsSubramanya Sastry2022-08-251-3/+6
| | | | Change-Id: I226b145eb20440d068f92a0c99d11cbced4cf64d
* Merge "Set skipMode to something other than legacy"jenkins-bot2022-08-191-1/+3
|\
| * Set skipMode to something other than legacyArlo Breault2022-08-191-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | At present, $validTestModes[0] is 'legacy' when running `composer phpunit -- --testsuite=parsertests` It seems like any other value would be preferable since we're in ParsoidTestFileSuite.php and we want the isLegacy check in getTestSkipMessage to be false. Introduced in a5a04f5 Change-Id: I94699e5cc6dcc7e371c4020faa4dfbf2fa335704
* | Merge "Allow parsoid-compatible parser tests to select a subset of parsoid ↵jenkins-bot2022-08-191-0/+8
|\| | | | | | | modes"
| * Allow parsoid-compatible parser tests to select a subset of parsoid modesC. Scott Ananian2022-08-181-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This lets you tag a parser test file with: !! options parsoid-compatible=wt2html !! end to indicate that you want to run only the parsoid wt2html tests on this file. This is especially useful when gradually adding integrated-mode parsoid output clauses to an existing test file. Change-Id: Id870d23da3c127fea61d6b8ab98200c0e4c661e2
* | tests/parser/TestMode: move parser test helper class to parsoid libraryC. Scott Ananian2022-08-163-3/+3
|/ | | | | | Depends-On: I6a653889afd42fefb61daefd8ac842107dce8759 Depends-On: I73f320dfb03e5c26971a7bc36564021d2c9f3695 Change-Id: Id3e44a5b419d7f6917819e72c046f94a3a2286fe
* phpunit: Fix trivial dynamic property usages in testsMáté Szabó2022-07-292-3/+6
| | | | | | | | | | | | | | Dynamic property creation is deprecated in PHP 8.2 (E_DEPRECATED). Migrate some trivial cases in tests to use explicitly declared fields instead, and remove the unused lastLog field from MediaWikiLoggerPHPUnitExtension. Notably this does not yet address MediaWikiIntegrationTestCase using dynamic properties to associate ephemeral data with DB connections used for tests. Bug: T314099 Change-Id: I55453c0d254012b69c6843c54cfa8345fa5744fa
* Clean up line indent with mixed tabs and whitespacesUmherirrender2022-07-091-1/+1
| | | | Change-Id: Ifcd15ecc4212d4ebfc26b2e18d6f1da47abf2a86
* Pass <Test,TestMode> as argument pair, deprecate old TestFileReaderC. Scott Ananian2022-06-033-60/+73
| | | | | | | | | | | | | | | | | | | | | We introduced a new type for "ParserTestMode" and then uniformly pass this around alongside the ParserTest object itself. (We started by using a string for the $mode but the "explicit changetree" mode requires more structured data. We *could* encode this in JSON just to keep the string type around, but it seems cleaner and more future proof to wrap this in a proper class type.) Removed the old TestFileReader wrapper class, which served only as a thunk to convert the new Test class into the same sort of array which the legacy parser test runner code expected. There's still some remaining ::testToArray() usage here for the TestRecorder framework, but that will be cleaned up in a future patch. Also updated the TestRecorder with stronger types: use the same <Test,TestMode> pair when invoking the TestRecorder, instead of the loosely typed array we'd used previously. Change-Id: Iec4c0c7972a655b4faccacc67bdc3ca66d4c163d
* ResourceLoader namespace (attempt 2)Tim Starling2022-05-241-3/+3
| | | | | | | | | | | | | | | | | | Move ResourceLoader classes to their own namespace. Strip the "ResourceLoader" prefix from all except ResourceLoader itself. Move the tests by analogy. I used a namespace alias "RL" in some callers since RL\Module is less ambiguous at the call site than just "Module". I did not address DependencyStore which continues to have a non-standard location and namespace. Revert of a241d83e0a6dabedf. Bug: T308718 Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
* Add Parsoid capabilities to parserTests.php scriptSubramanya Sastry2022-05-202-51/+13
| | | | | | | | | | | | | * This adds all of Parsoid's abilities to the parserTests.php script * Parsoid testing mode requires a "--parsoid" CLI option. * This supports "--wt2html" and the other testing modes, "--updateKnownFailures", "--knownFailures", and "--changetree" options that are part of the Parsoid's parserTests.php script. * Verified that the output of parserTests.php test run matches the output of the PHPUnit test run on the Cite extensions' citeParserTests.txt file. Change-Id: I87a1f621d0a2579ac47fa80d34cf74d4456bcf62
* ParserTest runner improvements (improve feature parity with Parsoid)Subramanya Sastry2022-05-203-32/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch improves the parser test runner in the following ways: 1. Adds Parsoid selser auto-edit test support Since it isn't possible to dynamically add tests in PHPUnit (unlike the home-grown parser test runners), to support selser auto-edit tests, we create a single composite test that includes all the individual edits. If a single test fails, the whole test is considering failing. The test output from all the individual tests are combined into composite expected / actual strings and test failure diffs reveals diffs for individual tests. Future patches could enhance output further. 2. Ensure that we skip HTML-based Parsoid test modes without appropriate input HTML 3. Pass additional options to the parser test runner via the ParserTestTopLevelSuite constructor. These support extended functionality of the Parsoid parser test runner which are being made available to core. At the moment the constructor will attempt to JSON-decode the PARSERTEST_FLAGS environment variable to supply defaults for these flags, which provides a hacky sort of way to pass arguments on the command line. This will be integrated with the existing $flags passed to ParserTestTopLevelSuite in the future (T308367). 4. Add support for running tests in specific modes as well as ability to update the known failures json file. This includes some missing code to run per-test teardown functions in runParsoidTest. Unlike the Parsoid parser test runner, you can combine updateKnownFailures with --filter as well as with subset of test modes, including possibly specific selser changetrees. If `{"updateKnownFailures": true}` is set in the PARSERTEST_FLAGS var, you can also update the knownFailures result for only the tests that are run. However, note that this could change the sort order in the *-knownFailures.json file. This leads to dirty (git) diffs when a full updateKnownFailures is run on the file. I am not going to tackle this issue for now since this is an obscure use case that is unlikely to be used much, if at all. Overall, if I copy over the -knownFailures.json file from the Parsoid repo into the Cite repo and update it with a phpunit.php run in core, it updates the known failures to reflect changes to test results from an integrated test run. A second run doesn't lead to any additional changes to the knownFailures.json file or to any test failures. I had to fix some bugs (referenced in the previous paragraph) to ensure this idempotence beyond the first run. This patch also cleans up some function signatures to use Test object It maps the Test object from the Parsoid repo to an associative array that a bunch of (legacy) parser test functions expect. This patch squashes the following previous patches: I2f46b4b94b44aec76e33403455eb466899376a6b Ib01991089ec410dd45f77a20b136c8e05d855fa4 Id0ef01e333580892aa6d415b8f66c4393b06870d Change-Id: I9952ab5ee3edef8e2f00b0e65cbffc42f46c2ea7
* Revert "ResourceLoader namespace"Lucas Werkmeister (WMDE)2022-05-161-3/+3
| | | | | | | | | | | | This reverts commit e08ea8ccb9932f9924a613056afcb2d01c8c7b39. Reason for revert: Breaks Phan in extensions, and as far as I’m aware, this change isn’t urgently needed for anything, so the simplest fix is to revert it again for now. After PHP 7.4 it should be safer to try this again (we hopefully won’t need the two “hack” classes by then). Bug: T308443 Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
* ResourceLoader namespaceTim Starling2022-05-161-3/+3
| | | | | | | | | | | | | | | | Move ResourceLoader classes to their own namespace. Strip the "ResourceLoader" prefix from all except ResourceLoader and ResourceLoaderContext. Move the tests by analogy. I used a namespace alias "RL" in some callers since RL\Module is less ambiguous at the call site than just "Module". I did not address DependencyStore which continues to have a non-standard location and namespace. Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
* Add partial support for running Parsoid selser testsSubramanya Sastry2022-04-211-2/+8
| | | | | | | | | | | | | | | | | | * This patch only adds support for - selser manual edits tests - selser changetree [5] tests Both these types of selser tests are known statically. * This doesn't yet add support for selser auto-edit tests since they cannot be determined statically. There is some code already in place in the test runner to apply change trees, but it will all likely get refactored in a future patch. Bug: T270311 Depends-On: I3be7826e08be120043f3bcd9151bade930b65fb7 Change-Id: Ic824dae6ee49867c766d40c11acfda117c7e2689
* Add support for Parsoid html2wt & html2html testing modesSubramanya Sastry2022-04-211-1/+1
| | | | | | | | | | | | | * Did a bunch of DRYing out and extracted helper functions. * The actual wt2html, wt2wt, html2wt, and html2html functions are much simpler to grok. * Fix handling of knownFailures. Bug: T270311 Depends-On: Iff4a45bf35e35f6980e73567538b164e3f0b03bc Depends-On: If083275fe8ca0beb2ba8ddb883297b6f221cc466 Depends-On: I1e7d61e9d0fd9d7d3aa7f2f55ea718d808c985cb Change-Id: I904b22c44bf5a7522d92cf761d5a0a82713b834e
* Add wt2wt test mode to ParsoidTestRunnerSubramanya Sastry2022-04-061-4/+3
| | | | | | | * Make use of caching support in the (Parsoid)Test object. Bug: T270311 Change-Id: I76894c6633dc37fb08af089ea852862ca6a5e90f
* Refactor Parsoid test runner to simplify testing non-wt2html modesSubramanya Sastry2022-04-062-14/+28
| | | | | | | | | | | | | | * This creates a fresh PHPUnit test for every test mode of a test. Parsoid's native test runner does this a lot more efficiently by reusing pipelines, env objects, and also intermediate test results. That way of running tests is trickier in the PHPUnit test setup. * Non-wt2html test modes will come in future patches. Bug: T270311 Depends-On: Iacdff9e47e0d98ac3aa3a61757935d6ea3e91096 Change-Id: I58f63ebd53939b358cefe60ac34f26cded52697d
* SuiteEventsTrait: don't call setUp() for an empty suiteTim Starling2022-03-171-0/+6
| | | | | | | | | | | | | | SuiteEventsTrait is a hack to support the parser test suite classes. If the suite is empty due to e.g. group filters, doing setUp() and tearDown() is unnecessary and expensive (requiring DB cloning). Also, errors from setUp() or tearDown() on an empty suite were not properly handled. So if the suite is empty, do the same thing as TestSuite::run(), leave the result unmodified. Bug: T292239 Change-Id: I0828257d6dd0bbc5b1633afde5ff162e96169675
* phpunit: Use is_file/is_dir instead of file_existsKosta Harlan2022-01-031-1/+1
| | | | | | | | 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
* build: Updating dependencieslibraryupgrader2021-07-224-7/+7
| | | | | | | | | | | | | | 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
* Remove unused default values from class propertiesThiemo Kreuz2021-05-121-1/+1
| | | | | | | | In all these cases the property is unconditionally set in the constructor. The extra initialisation is effectively dead code and an extra source of errors and confusion. Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4
* Fix typo in ParserTestTopLevelSuiteThiemo Kreuz2021-02-191-1/+1
| | | | Change-Id: I7384e010a0602967a21c6590e2f2bfd884c61b1b
* Tests: Mark more more closures as staticUmherirrender2021-02-091-1/+1
| | | | | | | Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208 Bug: T274036 Change-Id: I695873737167a75f0d94901fa40383a33984ca55
* ParserTestRunner: share more code w/ MediaWikiIntegrationTestCaseC. Scott Ananian2021-01-071-24/+9
| | | | | | | | | | | | | | | | | | | | Refactor the database setup code to share more code between ParserTestRunner and MediaWikiIntegrationTestCase. Made `::setupAllTestDBs` static so it can be reused from ParserTestRunner. Made ParserTestRunner::addArticle more like MediaWikiIntegrationTestCase::addCoreDBData(). Some additional refactoring work could be done here in the future to share more code. After the refactoring the ParserTestTables hook is no longer necessary and so has been (soft) deprecated. MediaWikiIntegrationTestCase clones all database tables, so ParserTestRunner no longer needs to ask extensions for a list of specific tables it should clone. Cleaning up the handful of extensions which define this hook will be left to a future patch set. Change-Id: I5124789fac333a664b73b4b4a1e801ecc0a618ca
* Don't silently discard exceptions in test suite setUp/tearDown methodsC. Scott Ananian2021-01-041-8/+58
| | | | | | | | | | | | This implementation is based on the upstream code in \PHPUnit\Framework\TestSuite -- but upstream only calls the beforeClass/afterClass methods. Bug: T192167 Bug: T270777 Followup-To: Ia12658554c94497a204b7f65f1a6f7b1fa0310ac Depends-On: I9eee817abb35f5bd3650d93a11ca208b1e3d8bf0 Change-Id: I9c4d89f9f54808b0415c9af7e7b0ac9df69c2389
* Add support for running parsertests with Parsoid in integrated modeC. Scott Ananian2020-12-234-4/+101
| | | | | | | | | | | | | | | This allows us to move Parsoid-specific extension code from the Parsoid repo into the extension's own repository and still have Parsoid parser tests run on it via core's mechanism for running extension tests. Factored out some common ParserOptions setup into a common helper function. There are a number of features still missing from the Parsoid test runner, which are marked with @todo comments and phab task numbers. Bug: T254181 Change-Id: Ifaf53862b96e9127d8f375ad8dd0cc362cba9f5b