aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/libs
Commit message (Collapse)AuthorAgeFilesLines
* Stats: Fix "MediaWiki.PHPUnit.AssertEquals.Int" in UnitTestingHelperTestTimo Tijhof2025-04-031-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Follows-up I1b9435dcdacd952b, which introduced this and silenced the warning, but it appears this warning is spot-on: > $ composer phpcs > … > assertEquals accepts many non-zero values, please use strict alternatives like > assertSame (MediaWiki.PHPUnit.AssertEquals.Int) We don't want to tolerate something like this: ``` var_dump(1 == true); class Foo{} var_dump(1 == new Foo()); var_dump(1 == (object)[]); var_dump(1 == new stdClass); var_dump(1 == '01.0'); var_dump(1 == '01.'); var_dump(1 == '01'); var_dump(1 == '1'); ``` Bug: T368740 Change-Id: Ib3966b96f65d41b1d320ae043dcbea1a445a55f5
* tests: Use type declaration on undocumented private functionsUmherirrender2025-03-301-1/+1
| | | | Change-Id: I56b31870ce9be46d15fcd9095f9a12e0f2488ed9
* objectcache: Remove internal StorageAwareness, now unusedTimo Tijhof2025-03-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Update a few remnant references inside the library while at it. * WANObjectCache: Didn't use ATTR/QOS directly, and getQoS test already implemnented as BagOStuff const. Update getQoS() docs to match. * WANObjectCache: Already documented ERR_ as BagOStuff::ERR_. And Codesearch confirms no use of `WANObjectCache::(ERR|ATTR|QOS)`. * MemcachedClient: Switch from referencing one to the other. The class is not directly used outside core, only via BagOStuff. * Implicitly remove unused ATTR_EMULATION by not carrying over. Follows-up: * e8275758fe (I20fde9fa5c) Split IExpiringStore from BagOStuff, and re-use in WANObjectCache. * 74be3a0150 (I4377fc3f53) Move ERR_ from BagOStuff to IExpiringStore. * 69950da666 (Ia862c5111a) Replace IExpiringStore with StorageAwareness. * 59b002b866 (I9885f53f00) Remove StorageAwareness::QOS_LOCALITY_. * ec90b543ab (I8dec3f73fa) Remove StorageAwareness::QOS_EMULATION_SQL. * 62bdd78817 (I5649a29310) Adopt ERR_ in MemcachedClient. * e5a3e36bd1 (I836735b1fe) Mark StorageAwareness as internal. Bug: T353529 Bug: T364652 Change-Id: I1dfde995e29d5264611cf3500d61fe4d8631a7d7
* rdbms: Use real type hints for objects instead of doc blocksBartosz Dziewoński2025-03-2311-40/+18
| | | | | | | | | | | | | | | | Mostly used find-and-replace: Find: /\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?)[\s\*]+/\s*(private|protected|public) (\$[a-z]\w+;\n)((?=\s*/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?))\n|) Replace with: \3 \1 \4 More could be done, but to keep this patch reasonably sized, I only changed the most obvious and unambiguously correct cases. I made some bonus corrections to the type hints too. Change-Id: Ic900d0a7c552ea3535276c1b47d87dcce66ec3d9
* Fix uses of TempFSFileFactory's old class aliasJames D. Forrester2025-03-172-3/+3
| | | | | | | Follow-up to 0fe5cc829ecfc7b0476d69821c446516483d24fe. Bug: T382910 Change-Id: I8bd2e5d5815f37944ec4bfc5f586701a1116069b
* Merge "Remove inline @var docs that aren't needed"jenkins-bot2025-03-141-2/+0
|\
| * Remove inline @var docs that aren't neededthiemowmde2024-11-051-2/+0
| | | | | | | | | | | | | | Not needed (any more) because the code already contains enough @return docs and such. Change-Id: If461fa035d2c646878540565b3087a74c6628552
* | rdbms: Don't forward DB connection handle to transaction callbacksMáté Szabó2025-02-122-10/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - When a transaction lifecycle callback such as onTransactionPreCommitOrIdle() is invoked by rdbms, rdbms passes in the DB connection handle the callback was scheduled on. - However, the DB connection handle may have since been reset to a different DB domain on the same physical cluster due to connection reuse. - We could implement bookkeeping to keep track of the expected DB domain for each pending callback and ensure the passed-in DB handle matches that before invoking the callback, but nobody seems to be making use of the passed-in DB handle except for two call sites in core. - As such, it seems more prudent to remove this functionality. What: - Stop passing the DB connection handle to rdbms transaction lifecycle callbacks. Bug: T386190 Change-Id: I9125bfb8b5e2cac4aab3525ffd229ea49beccc17
* | Merge "Stats: add UnitTestingHelper"jenkins-bot2025-02-051-0/+123
|\ \
| * | Stats: add UnitTestingHelperCole White2025-01-301-0/+123
| | | | | | | | | | | | | | | Bug: T368740 Change-Id: I1b9435dcdacd952b2bc703b3d5f7083406ebbed6
* | | Merge "Replace wfDeprecatedMsg with trigger_error in ScalarParam.php"jenkins-bot2025-02-031-3/+26
|\ \ \
| * | | Replace wfDeprecatedMsg with trigger_error in ScalarParam.phpDoğu Abaris2025-02-021-3/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | wfDeprecatedMsg was replaced with trigger_error for better alignment with non-MediaWiki environments. Change-Id: Icc5a58cb2eccf26def393a9715ab5089cf4b7951
* | | | Merge "build: Updating mediawiki/mediawiki-codesniffer to 46.0.0"jenkins-bot2025-02-021-3/+3
|\ \ \ \ | |/ / / |/| | |
| * | | build: Updating mediawiki/mediawiki-codesniffer to 46.0.0libraryupgrader2025-01-311-3/+3
| | | | | | | | | | | | | | | | Change-Id: I0f8a8cac36015bba52aea3ee2affd92f83d3574a
* | | | Add TransactionProfiler::getExpectationDreamy Jazz2025-01-311-0/+19
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: * Code in the CheckUser extension needs to know when the expectations of a request are defined as POST-nonwrite. ** This is because CheckUser may need to make writes to the DB as a result of an auto-creation of an account made during a POST-nonwrite API request. * This code cannot currently query the TransactionProfiler to see the expectations for a request, and cannot also easily see if the API request is non-writing. ** Allowing the CheckUser code to see the expectations for the number of writes in the request will allow it to instead insert the data using a job when writes are not expected but still insert in the usual way when in a POST request that allows writes. What: * Add TransactionProfiler::getExpectation which returns the TransactionProfiler::FLD_LIMIT value for a given event name ** The method throws an InvalidArgumentException if the event name provided is not recognised. * Add tests for the new method. Bug: T384915 Change-Id: I54dc388557c3b0cb4fd73625132fb64b14f4ddd0
* | | Stats: Add support for chaining TimingMetric->start()Timo Tijhof2025-01-301-3/+6
| | | | | | | | | | | | | | | | | | Bug: T240685 Bug: T364240 Change-Id: Id1fe4ac6127894c9861b0d904c7a55f21deb7455
* | | tracing: lowercase headers before processing themChris Danis2025-01-231-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | This seems the cleaner fix, since we do want to emit output headers in lowercase, as that's what the rest of mediawiki/core emits nowadays, as well as basically the rest of the world. Bug: T384629 Change-Id: I8ea568e316c6e06b8c3d6f370b04be57dcbddc0a
* | | ParamValidator: reject expiry dates that don't fit in 14 charsTim Starling2025-01-221-0/+4
|/ / | | | | | | | | | | | | | | | | | | In ExpiryDef::normalizeExpiry(), throw an InvalidArgumentException if the expiry string indicates a date outside of the years 0 - 9999. Such timestamps fail in various exotic ways, so it's best to reject them early. Bug: T384241 Change-Id: Ic2110421e8ff1a8892d02b600a0dce965b36c82d
* | Remove 2-line PHPDocs that just repeat the types from the codethiemowmde2025-01-175-28/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Same as Ia294bf4 did for 1-line comments. This patch removes slightly more complex 2-line PHPDoc comments that don't add any new information to the code, but literally repeat what the code already says. They say "don't document the code, code the documentation", and we are doing this more and more. We just tend to forget to remove the obsolete comments. Note I'm also removing a line of text in a few cases when it's very short and literally says the same as the method name. Again, such comments add zero new information. Change-Id: I01535404bab458c6c47e48e5456403b7a64198ed
* | Merge "Remove trivial 1-line PHPDocs that just repeat the code"jenkins-bot2025-01-161-1/+0
|\ \
| * | Remove trivial 1-line PHPDocs that just repeat the codethiemowmde2025-01-161-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I assume these are all either auto-generated by an IDE or the language-level type declarations have been added later. In any case the comments don't add any new information to what the code already says. This is just extra clutter that makes the code harder to read, I would argue. There are many, many more comments like this. In this patch I intentionally focus on the most trivial 1-line comments. Change-Id: Ia294bf4ce0d8a77036842fe25884bc175c2b0e7d
* | | telemetry: Add propagator testsMáté Szabó2025-01-154-0/+199
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - Some of the newly implemented propagator functionality is missing unit tests. What: - Add relevant test cases. Bug: T340552 Change-Id: I63333310f7ca49321768958c6be7a0da1fb73916
* | telemetry: Factor out context propagationChris Danis2025-01-102-8/+50
| | | | | | | | | | | | | | | | Also condition using incoming span context upon $wgAllowExternalReqID Bug: T340552 Change-Id: Ib1cf361dd800c81a7943231441d58c790191ef5a
* | Merge "objectcache: Move internal StorageAwareness to ObjectCache namespace"jenkins-bot2025-01-091-12/+12
|\ \
| * | objectcache: Move internal StorageAwareness to ObjectCache namespaceTimo Tijhof2025-01-031-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * The LightweightObjectStore namespace was experimentally adopted for two classes in 2020 with change Ia862c5111a3daf10a34fc78163301629, however in 2024 when we namespaced the BagOStuff component as a whole, we went with ObjectCache namespace in change Ie01962517e. * The StorageAwareness class is internal since I836735b1fec8dfd, so it can be freely renamed. * Similar to I836735b1fec8dfd, further reduce direct use of it, keeping it only as effectively an internal trait for adding a consistent set of constants to 3 classes (Bag, Wan, MemcClient). Bug: T353529 Bug: T364652 Change-Id: Ib10db39a91274e84a51a2eead94560b8d9137019
* | | Merge "rdbms: Check for duplicate and conflicting fields in SelectQueryBuilder"jenkins-bot2025-01-091-2/+2
|\ \ \
| * | | rdbms: Check for duplicate and conflicting fields in SelectQueryBuilderBartosz Dziewoński2025-01-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Avoids weird-looking queries when the same field(+alias) is provided twice, and throws an exception for potentially incorrect queries when the provided fields(+aliases) conflict. Change-Id: I03ba16fc3fce3f1468e518fb08dd65e705ca461f
* | | | Merge "rdbms: Add more tests for adding SelectQueryBuilder fields"jenkins-bot2025-01-091-0/+24
|\| | |
| * | | rdbms: Add more tests for adding SelectQueryBuilder fieldsBartosz Dziewoński2025-01-071-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When you add the same field to the query builder more than once, weird things happen. Change-Id: I5cb51b262ec954624f531943ff011091102295ae
* | | | Merge "stats: add getCacheCount function to expose the size of the cache"jenkins-bot2025-01-081-0/+12
|\ \ \ \
| * | | | stats: add getCacheCount function to expose the size of the cacheCole White2025-01-071-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | Bug: T381042 Change-Id: I9ac5e2f9a4dd003bb4c67a19a391100dd86aef96
* | | | | Tracing: span statuses for root spansChris Danis2025-01-071-1/+4
| |/ / / |/| | | | | | | | | | | | | | | Bug: T340552 Change-Id: I18ffd0e36efbabe82313de685ca8c6c99341c6f3
* | | | mime: Add missing `@group` to ZipDirectoryReaderTestTimo Tijhof2025-01-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Matching other tests in /tests/phpunit/unit/includes/libs/mime. Follows-up Iccdade8dcd3211b7e2df2e50694da8d97c82b59e. Bug: T382910 Change-Id: Ib83243a4f86dd4d8b56a9d300e69c6c2caaf3bb7
* | | | MimeAnalyzer: move ZipDirectoryReader to librarydaniel2025-01-031-0/+138
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - MimeAnalyzer needs ZipDirectoryReader, but it was not part of libs. This was a problem because libs code must note depend on MediaWiki code. Since there seem to be no other users of ZipDirectoryReader, the simplest solution seems to be to move ZipDirectoryReader into the Wikimedia\Mime library. What: - Moved ZipDirectoryReader and ZipDirectoryReaderError into the Wikimedia\Mime namespace under includes/libs/mime. Bug: T382910 Bug: T364652 Change-Id: Iccdade8dcd3211b7e2df2e50694da8d97c82b59e
* | | Setup: parse incoming traceparent headerChris Danis2024-12-201-0/+66
| | | | | | | | | | | | | | | | | | | | | | | | If present and valid, connect our root span to the input parent span. Bug: T340552 Change-Id: I3530c3b6be95c7b4a8960ad25929f795c4514db0
* | | tracing: Merge span attributes on consequent setAttribute() callsMáté Szabó2024-12-202-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - SpanContext::setAttributes() currently overwrites existing attributes on each call, instead of merging them. - This behavior isn't documented and is confusing, especially since official OTEL clients usually merge attributes. What: - Have SpanContext::setAttributes() merge attributes instead of overwriting the existing ones and add a test for this. - Document the behavior on the public-facing SpanInterface::setAttributes() API. Change-Id: Ib2995c492b503ad84104deab9c227cfb62bffc55
* | | Rdbms\Database: export OTel spans for db operationsChris Danis2024-12-201-0/+2
| | | | | | | | | | | | | | | Bug: T340552 Change-Id: I7896f6ebee151d7da1d88e04bb4d05dc007d67e8
* | | rdbms: fix table prefixing in "FOR UPDATE" clause generation in PostgresAaron Schulz2024-12-111-1/+15
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make SqlPlatform::tableNameWithAlias() include the unqualified table name as an alias if doing so is not redundant. This assures that the default alias from JoinGroupBase::addJoin(), equal to the unqualified table name, will be usable in SQL (regardless of table prefixes). Clean up use of identifier quotes for sqlite_master tables. The called methods expect unqualified names and a passthrough exception already exists for sqlite_* tables. Use "block_target.bt_user" directly in ApiQueryBlocks and BlockPager, instead of using addIdentifierQuotes(). The "block_target" alias is automatically added to the SQL by the rdbms layer when it's not clearly redundant, so it is always safe to use block_target.bt_user. Also, there is no reason for aliases to include quote characters. They are supposed to be simple alphanumerics like column names. This makes it easy for tableNameWithAlias() to avoid redundant aliases by checking tableName(). Avoid unneeded quotes around pg_catalog.* table names in the Postgres installer. The relevant documentation of methods like selectField() is that the table names be unqualified (no quotes nor dots), though dots are still supported internally for compatibility reasons and ease of querying schemas like pg_catalog and information_schema. Change-Id: Ic7d7826da31f49915141692cb3bd84ed1e872e96
* | Stats: Add test coverage for dogstatsd labelsTimo Tijhof2024-11-271-16/+34
| | | | | | | | | | | | | | | | | | The label formatting logic was not yet covered by tests. https://doc.wikimedia.org/cover/mediawiki-core/includes/libs/Stats/Formatters/DogStatsdFormatter.php.html Bug: T240685 Change-Id: Ie37c4df13acb3631865fc017f6af2cc87b75d28e
* | Add request-level OpenTelemetry instrumentationMáté Szabó2024-11-261-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - Now that we have a basic OpenTelemetry library available in MediaWiki, we would like to start instrumenting code and propagating the trace context. What: - Start a root span in early setup code once the service container is available, so that subsequent setup logic (e.g. session initialization) can already be instrumented. - End the root span in restInPeace() after the main transaction round ended, so that the normal LBFactory shutdown process can be instrumented. - Have TracerSharedState hold the root span throughout. Bug: T340552 Change-Id: I0785204a6989787a492a08b78c40c6df91106f23
* | tests: Disable flaky test ClockTest::testShouldReturnCurrentTimeMáté Szabó2024-11-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why: - The test ClockTest::testShouldReturnCurrentTime is flaky. - Ie48d9400cf3bb99467a16b9ea0cce6172e2e2568 recently augmented the ConvertibleTimestamp library to allow faking hrtime(), which will be a better solution for this class and test than the current assertion. What: - Skip the test until core is updated to the latest version of ConvertibleTimestamp. Bug: T379562 Change-Id: Iae502ed0344f45f89da575f1c5d1e0fb9c1e4dfa
* | Merge "mediawiki.deflate: Add mw.deflateAsync which can use CompressionStream"jenkins-bot2024-11-211-0/+10
|\ \
| * | mediawiki.deflate: Add mw.deflateAsync which can use CompressionStreamEd Sanders2024-11-211-0/+10
| |/ | | | | | | | | | | | | | | | | | | | | To avoid a breaking change, introduce a new function name as CompressionStream is asynchronous. Once mw.deflate can be removed, we can add skip function for pako based on the availability of CompressionStream. Bug: T235237 Change-Id: I722ebb03c0db7c7b3ee16cc8881e41909142cee9
* | tests: Use MediaWikiCoversValidator when extends PHPUnit's TestCaseUmherirrender2024-11-1930-0/+70
| | | | | | | | | | | | | | | | | | | | | | 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
* | rdbms: Remove handling of cancel callbacksAmir Sarabadani2024-11-141-233/+1
|/ | | | | | | | | | These cancel callbacks are not used at all. It is adding a lot of complexity to the transaction management of rdbms making it quite harder to understand and reason about. Bug: T363839 Change-Id: I3cb1e30611b83c03535ea87a216bbedd4a911f4e
* Message: Downgrade exception on bool/null param to warningBartosz Dziewoński2024-11-021-3/+2
| | | | | Bug: T378876 Change-Id: Iecbf83dd060b2a1dc30bd33bfc4f2a42cfbd2a1f
* Remove Message::objectParams() and related codeBartosz Dziewoński2024-10-271-14/+0
| | | | | | | Deprecated in I492edabb7ea1d75774b45eb9fd18261b39963f9f. Bug: T278482 Change-Id: Ie9350ed0d7b2604fb4d2f440dee66964fe198c0e
* SECURITY: Message: Don’t call is_callable() on stringsLucas Werkmeister2024-10-242-0/+32
| | | | | | | | | This can cause PHP to try to load the param value as a class, with potentailly disastrous results (though it’s not quite clear if this can actually cause attacker-supplied code execution or not). Bug: T377912 Change-Id: I0239b3e65cf516c6fdf287882f05e47a01f963c1
* Merge "Use ++ and -- rather than += 1 and -= 1"jenkins-bot2024-10-231-19/+19
|\
| * Use ++ and -- rather than += 1 and -= 1Reedy2024-10-171-19/+19
| | | | | | | | Change-Id: I27b9a19ab952ede1267921bd042af0fe1c89e228