aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/maintenance
Commit message (Collapse)AuthorAgeFilesLines
* maintenance: Fix incorrect error message for missing short valueTimo Tijhof2024-12-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The logic bug pre-existed, but the concrete issue here was introduced last year in Ib67667fea (a9f47fd5ad), which changed "$option parameter" to "--$option parameter" for both long and short option messages. Refer to the option given rather than the mapped name. Like I7ab1206e3, this is also due to a re-used variable name where $option is changed in order to look up the metadata about the option, but this was then re-used for the message output. It is fairly okay in the common case of `--value (-v)` where --value if you used -v actually, is at least something you can find in the help. But, in the case of an option that only has a short name, it was mis-calling the short option as a long option. Either way it's an improvement to refer to what the user actually did. Before: ``` $ php maintenance/eval.php -d ERROR: Option --d needs a value after it! ``` Fixed: ``` $ php maintenance/eval.php -d ERROR: Option -d needs a value after it! ``` Change-Id: I3419a831e71c63bc64ba3d7f517fb2cd00707136
* maintenance: Fix broken `--help` line for short option with valuesTimo Tijhof2024-12-241-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without this change, the added test case produces "--thing (-t) <THING (-T)>: Words here" instead of "--thing (-t) <THING>: Words here". Note how the description of the "value" oddly repeats the short name again, because the code accidentally re-used the `$name` var. This bug was introduced last year in Idb2f309ee4 (963ef5d645). While at it, improve the test by using assertStringContainsString. Without this change, the added test case failed like so: ``` There was 1 failure: 1) MaintenanceParametersTest::testHelp Failed asserting that false is not false. ``` ... which has no detail about what actually happened and thus what problem exists, or what possibly-correct-but-different result I could have the test expect instead. Now, with my test changes it would fail more helpfully as: ``` There was 1 failure: 1) MaintenanceParametersTest::testHelp Failed asserting that ' Script specific options:\n --thing (-t) <THING (-T)>: Words here\n \n ' contains "--thing (-t) <THING>: Words here". ``` Change-Id: I7ab1206e3396b5c1a967e941bfa077013fae6d6a
* tests: Use MediaWikiCoversValidator when extends PHPUnit's TestCaseUmherirrender2024-11-193-0/+3
| | | | | | | | | | | Validate the @covers annotation to be valid on CI runs. This is done for mosts tests via MediaWikiCoversValidator in base class MediaWikiIntegrationTestCase or MediaWikiUnitTestCase Only omitted when @coversNothing is used. This is already used in other library-related test cases. Change-Id: Ib31db02b4c623e80049a5f4645c77824244b6d6d
* tests: Fix namespace in @covers for MWDoxygenFilterKevin Israel2024-11-171-1/+1
| | | | | | | Follows-up 9f02d18eac2134a8. Bug: T353458 Change-Id: Ic6c2713cb921b5b9292615a2aa3791a82d214eeb
* tests: Use namespaced classesUmherirrender2024-10-211-0/+2
| | | | | | | | 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
* Add namespace to maintenance/includes classesJames D. Forrester2024-10-091-1/+1
| | | | | | | Also a few other fixes of PHP class aliases spotted by phan. Bug: T353458 Change-Id: Ie79d65722c47c24f8f20f1293355cfd3c2e8c2ad
* maintenance: Add missing documentation to class propertiesUmherirrender2024-09-131-0/+1
| | | | | | | | | | Add doc-typehints to class properties found by the PropertyDocumentation sniff to improve the documentation. Once the sniff is enabled it avoids that new code is missing type declarations. This is focused on documentation and does not change code. Change-Id: I7dec01892a987a87b1b79374a1c28f97d055e8fa
* Use fake maintenance scripts in MaintenanceRunnerTest where necessaryDreamy Jazz2024-08-082-27/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: * The MaintenanceRunnerTest class tests using real maintenance scripts and the code being tested can include the maintenance script files. * However, if running all tests together (such as when generating test coverage) the maintenance scripts may have already been loaded by integration tests that exist for those scripts. * Instead of fixing the specific instances, we should instead ensure that (where necessary) the MaintenanceRunnerTest tests using fake maintenance scripts only loaded by that test class. * Doing this prevents the files from being loaded anywhere else and ensures that the tests should not fail in this way again. What: * Update MaintenanceRunner::expandScriptFile to move the use of MS_INSTALL_PATH to a protected method that can then be mocked in MaintenanceRunnerTest. * Update MaintenanceRunnerTest to use fake maintenance scripts where necessary. This includes: ** No longer setting the current working directory as the MW_INSTALL_PATH, but instead set it as __DIR__. ** Creating several fake maintenance scripts to replace the uses of the real ones. ** Updating the data providers to reflect the changes. Bug: T371188 Change-Id: Ifacdcb8de5af53d2d5f4ed354af0d209384d7325
* TempUserConfig: Deduplicate code generating match conditionsBartosz Dziewoński2024-03-061-1/+1
| | | | | | | The idea is similar to the one behind TempUser\Pattern::toLikeValue(), which has been effectively deprecated by allowing multiple patterns. Change-Id: Iddb284bff21355deb8ceaa6925d3c2aea34d727e
* tests: Fix @covers and @coversDefaultClass to have leading \Reedy2024-02-162-2/+2
| | | | Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
* Clean up testsMatěj Suchánek2024-02-121-1/+1
| | | | | | | Replace strpos with str_contains, str_starts_with, etc. Fix spelling of "cannot" and other typos. Change-Id: Ie52900b323f46d1978a9dd9ea3b17619b8942160
* Add a maintenance script to populate user_is_temp columnDreamy Jazz2024-01-241-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | Why: * The user_is_temp column exists in the user table to allow finding temporary users when reading from the DB directly. * This column was added in f283c0e99068259ea70e8926dc4792a461414264, but this was not written to until 6e68107b3a56964e5b23cf575b905f8a6ed696d9 which was several months later and after a release version was branched. * As such, we need a maintenance script to populate the user_is_temp column for wikis that have enabled temporary account creation. What: * Add a maintenance script named populateUserIsTemp.php which populates the user_is_temp column by looking for rows in the user table that have user_is_temp as 0 and have user_name match at least one temporary account match pattern. These rows are then updated to have user_is_temp as 1. * This script will be added to update.php in a future commit, so that betawikis can have this run manually. * Create unit tests and an integration test for this maintenance script. Bug: T355181 Change-Id: I6223496d7aee65e3ab207fe86e386b01bef8b388
* maintenance/version: Namespace and renameKosta Harlan2023-12-211-2/+3
| | | | | | | | | | | | | | | Why: - PHPUnit errors when running locally (T353873) What: - Add Maintenance namespace to script - Make uppercase to match convention for other classes Bug: T353458 Bug: T353873 Change-Id: I3d2200ee9b53f45d39e7f7b143f1128b2d855849
* Switch to run.php in documentationAmir Sarabadani2023-04-131-2/+2
| | | | | | | Currently, running --help on maint scripts recommends running them directly. With this change, it'll recommend using run.php instead. Change-Id: Idec3958aacee8d8ef14ef1033f6c5d7c281bb750
* Merge "tests: Fix @covers for MaintenanceParametersTest"jenkins-bot2023-03-271-1/+1
|\
| * tests: Fix @covers for MaintenanceParametersTestUmherirrender2023-03-231-1/+1
| | | | | | | | | | Follow-Up: Ib67667fead8350e0a539323fb05b160f4c2d882e Change-Id: Ib3f0dfb578a31c31d38023b5590cf2119a1fe57e
* | tests: Make some PHPUnit data providers staticTim Starling2023-03-242-6/+6
|/ | | | | | | | | | | | | Just methods where adding "static" to the declaration was enough, I didn't do anything with providers that used $this. Initially by search and replace. There were many mistakes which I found mostly by running the PHPStorm inspection which searches for $this usage in a static method. Later I used the PHPStorm "make static" action which avoids the more obvious mistakes. Bug: T332865 Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
* MaintenanceRunner: keep track of script class explicitly.daniel2023-03-151-3/+8
| | | | | | | Reduce potential for confusion between file names and class names in MaintenanceRunner. Change-Id: I8be566925beced6ef6f1075e430d6afc38dbae6b
* MaintenanceRunner: load script file early if possibleKevin Israel2023-03-141-0/+32
| | | | | | | | | | | | | | | | | | | | If possible, load the script file before running Setup.php. This way, script files can control the setup process by defining constants. This is needed by scome scripts, namely: - instal.php, to override config loading by defining MW_CONFIG_CALLBACK - generateConfigSchema.php, for setting MW_USE_CONFIG_SCHEMA_CLASS - mergeMessageFileList.php, for setting MW_NO_EXTENSION_MESSAGES - shell.php, for setting MW_NO_SESSION Note that this will not work for scripts defined in extensions. In order to allow script files to be loaded based on class name, AutoLoader.php is included before Setup.php is run. This is a modified version of I638f99c3cc6f8ab8216bd65ada959a6a11ff454b. Co-authored-by: PleaseStand <pleasestand@live.com> Change-Id: I2bf3b91c0a7162413cd1392252cb4f29a0d3d594
* Maintenance: Add support for documenting multi-argsdaniel2023-01-281-7/+96
| | | | | | | | | Add suppor for documenting multi-value positional args. Also fixes an issue with errors about missing args being shown even when --help is given. Change-Id: I6e07115aaa0f557614979adcd3f0423dd37fe8bc
* Merge "Maintenance: find file by name in maintenance dir"jenkins-bot2023-01-292-0/+125
|\
| * Maintenance: find file by name in maintenance dirdaniel2023-01-272-0/+125
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows a file in the maintenance dir to be specified without the path but with the .php extension. Previously, the file would be expected to be found in the local directory if it had no path but a .php extension. This effectively makes it so that the maintenance directory is used as the default location for maintenance script files, which can be specified with or without .php extension. The extension is no longer significant for how the file is located. Only paths that start with "./" or "../" are treated as relative to the cwd. Depends-On: Ic1ca796a52a0c5d7095e607fdc2e320b086229c7 Bug: T326800 Change-Id: Id334d2b3ccd4be1443d95eb40b028f25c47f94c0
* | Maintenance: improve option helpdaniel2023-01-231-3/+9
|/ | | | | | | | | | | | Refer to "options" consistently, instead of sometimes using the term "parameters". Only list required options synopsis, and include option value placeholders. The synopsis will now look simething lieke this: USAGE: php foo [OPTION]... --param <PARAM> --something <SOMETHING> <X> [y] Change-Id: Idb2f309ee442f0e5f597e0fc15537f90944f28b0
* Introduce run.php for running maintenance scriptsdaniel2022-12-211-0/+16
| | | | | | | | | | | | | Maintenance scripts can now be run like this: maintenance/run.php <class> NOTE: This introduces a new callback into Setup.php, MW_FINAL_SETUP_CALLBACK. In contrast to MW_SETUP_CALLBACK, it is called after extensions have been initialized. Bug: T99268 Change-Id: Ia221f72d6b7d23df74623d60ade7fe3e5d913074
* Merge "Make use of the ?? and ??= operators where it makes sense"jenkins-bot2022-12-161-4/+5
|\
| * Make use of the ?? and ??= operators where it makes sensethiemowmde2022-11-101-4/+5
| | | | | | | | | | | | | | ?? is an older PHP 7.0 feature. ??= was added in PHP 7.4, which we can finally use. Change-Id: I85921f1db9670987e173e905e8206bdf46659457
* | tests: Replace assertEmpty with assertSameUmherirrender2022-11-251-1/+1
|/ | | | | | | assertSame avoids use of loose comparisons and allows to check the expected type Change-Id: If821d1be2bc1ff9f8b70968a339f33c7a8e8880a
* Runner: Handle more params in runner.daniel2022-06-131-9/+3
| | | | | | | | This moves the handling for the following parameters fully into the MaintenanceRunner class: --conf, --wiki, --globlas, --memory-limit, --server, --profiler Change-Id: I63624ba1fcbcf446630eba1b81b2c84b1a943932
* Extract parameter handling from Maintenance base class.daniel2022-05-251-0/+380
| | | | | | | We will need parameter handling in the runner as well as in the actual maintenance script. So pull it out, so we can re-use it. Change-Id: Ib67667fead8350e0a539323fb05b160f4c2d882e
* Move MWDoxygenFilterTest to unit testsDannyS7122021-03-281-0/+145
Extends PHPUnit\Framework\TestCase and does not require any integration logic Start new /tests/phpunit/unit/maintenance/ directory Change-Id: I126dba699e829544a571bf795de6536a0ed9b977