aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/libs/rdbms/database
Commit message (Collapse)AuthorAgeFilesLines
* rdbms: move DatabaseFactoryTest to unit/ directoryTimo Tijhof2023-04-101-42/+0
| | | | | | | | | | | This was the last remaining test file for libs/rdbms/ outside either phpunit/integration or phpunit/unit. Move it to where it belongs to reduce the number of places to look and avoid mistakes where running a directory appears to result in meaningful tests but actually runs just this one test. Change-Id: I8cada26b51bc191dc9b7be4dad7c8abbe107629e
* rdbms: Fix test to not rely on deprecated class aliasesTimo Tijhof2022-11-041-3/+3
| | | | | | | | | | | | | | | | Restore unrelated test fix from 46eabe275c, which got reverted in 0b43c49465. The DatabaseFactory::create() function takes $type which is either a built-in type (mysql, sqlite, postgres) or theoretically the suffix of a database extension class for a custom type. "mysqli" is not a valid type, the type is "mysql". This was passing because DatabaseMysqli still exists as a class alias for the namespaced Rdbms class. Bug: T309418 Change-Id: Ic05a4b3d4cfe539e11df3dc83dfe459c184d1332
* rdbms: Move Database::factory() to DatabaseFactory serviceKunal Mehta2022-08-311-0/+42
| | | | | | | | | | | | | We also bring along Database::attributesFromType(), which relied on the private ::getClass(). This requires us to inject DatabaseFactory through the LBFactory/LoadBalancer hierarchy. Database::factory() is now soft deprecated. All callers outside of includes/installer/ still need migration. Bug: T299691 Bug: T315270 Change-Id: I7d057a9438f1b097554679975e4e9b2fc99e7c2b
* Move libs/rdbms/database tests to unit testsDannyS7122021-04-072-100/+0
| | | | | | | No integration is needed Also switch to extending MediaWikiUnitTestCase Change-Id: I5d91e2de223a8dff9d61e8888778994d73e604df
* Use MWMySQLPlatform class in testAmmarpad2021-03-211-4/+2
| | | | Change-Id: I6adfd11378eefad3782760bd2586e763f530513a
* More misc test cleanupDannyS7122020-12-246-4732/+0
| | | | | | | | | * parent::setUp() should be first, and ::tearDown() should be last * Move tests that directly extend PHPUnit\Framework\TestCase to /unit Change-Id: I1172855c58f4f52a8f624e6d596ec43beb8c93ff
* Upgrade doctrine/dbal from 2.10.4 to 3.0.0 for PHP 8.0 supportReedy2020-12-231-2/+4
| | | | | | | | | Some irritating breaking changes, including dropping PHP 7.2 support and renaming the classes we care about. For now, hack in via || and some back-compatibility class aliases. Bug: T270732 Change-Id: I685f099584d2f0e5fa17f1f4275eab5289c7bfee
* Start generateSchemaChangeSql.phpAmir Sarabadani2020-11-011-0/+47
| | | | | | | | Creating schema changes from abstract schema and even abstracting a schema change. Bug: T230420 Change-Id: If626e866642af820dd70c5f9b0fe7c6a951e0a25
* Expand DoctrineSchemaBuilderTestAmmar Abdulhamid2020-10-171-8/+32
| | | | | | | | | * Test the generated table for each platform * Use the handy dirname() function instead of full raw string path Bug: T191231 Depends-On: If344395615087c360597a5b3d66ea03e930b7d9b Change-Id: I936c5d10924a46743c7f76df8526105eec7ff48d
* Permit temporary table writes on replica DB connectionsMáté Szabó2020-07-311-0/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | In I8e17644d1b447416adee18e42cf0122b52a80b22, MediaWiki's DBAL was adjusted to reject any write query on read-only DB replica connections. This poses a problem for extensions that use temporary tables in their queries, as such queries now have to be executed on the source DB rather than a replica to work around this fact. An example of such an extension is Semantic MediaWiki, whose QueryEngine uses temporary tables extensively in serving reads. The current situation, where all writes, including non-persistent ones, must be executed on a source DB connection, causes scalability issues since it's no longer possible to distribute these queries between multiple replicas. An old code comment in the DBAL cited MySQL bug 33669 as a potential blocker to permitting temporary table operations on read-only connections. However, that bug was closed a decade ago, and Fandom's Semantic MediaWiki cluster has been permitting such operations on its MySQL 5.7 replica nodes (running with --read-only) for several years now, without observing any adverse side-effect. This patch accordingly relaxes the restrictions placed by the MediaWiki DBAL on temporary table operations to enable executing them even on read-only replica DB connections. Several unit tests were added to verify the conditions under which a given write query may be allowed to execute on a connection. Bug: T259362 Change-Id: I90a1427a15d0aee07e7b24ba4248b7ef4475c227
* Fix Database::getTempTableWrites for multi table DDLsUmherirrender2020-07-281-0/+2
| | | | | | | | Capture group with * does not return a array, only the last match. Match all and split on the delimiter instead Bug: T252183 Change-Id: I39701dd367bf2914e7c6fb24b3f14f09a059e483
* Revert "Add a new type of database to the installer from extension"Kunal Mehta2020-07-221-3/+3
| | | | | | | | | | | | | | | It caused a 20% latency regression by unconditionally parsing extension.json files on every single load instead of using the existing caching infrastructure. There are further problems with the use of parsing/loading extension.json files in a method that is incompatible with the existing architecture. This primarily reverts commit 46eabe275c923ca7827435a36d6576150cea8899. Also needed to revert 16381261ae and 7c72347ec1. Bug: T258664 Change-Id: I34a783c3f0df0447876a26441bb2d12e02368871
* Add a new type of database to the installer from extensionArtBaltai2020-06-261-3/+3
| | | | | | | | | | | | | Decouple Installer services Implement injection class Autoloader and i18n messages from extension.json Implement extension selector by type Add i18n message key `version-database` Extensions for testing: - https://github.com/MWStake/PerconaDB - real Percona extension - https://github.com/killev/mediawiki-dbext2 - fake extension for test Bug: T226857, T255151 Change-Id: I9ec8a18ad19283f6be67ac000110ac370afc0815
* Replace all call_user_func(_array) in all testsThiemo Kreuz2020-06-061-6/+6
| | | | | | | | | | | | | There is native support for all of this now in PHP, thanks to changes and additions that have been made in later versions. There should be no need any more to ever use call_user_func() or call_user_func_array(). Reviewing this should be fairly easy: Because this patch touches exclusivly tests, but no production code, there is no such thing as "insufficent test coverage". As long as CI goes green, this should be fine. Change-Id: Ib9690103687734bb5a85d3dab0e5642a07087bbc
* build: Bump mediawiki-codesniffer to 31.0.0Daimona Eaytoy2020-05-302-17/+17
| | | | | | | | | Done with `composer fix` and suppressing the rest (i.e. sniffs for global variables, which for core should be suppressed anyway). Additionally, add `-p` to `phpcbf`, as otherwise it just seems stuck. Change-Id: Ide8d6cdd083655891b6d654e78440fbda81ab2bc
* Fix a plethora of class and function call case mismatchesReedy2020-05-261-7/+7
| | | | | Bug: T231412 Change-Id: I597a25de3294a6673424f30475760280ef209a8a
* database: Disallow db->update() without conditionPeter Ovchyn2020-04-291-0/+140
| | | | | | | | | In order to prevent possible performance or replication issues, empty condition for 'update' queries shouldn't be allowed Bug: T243619 Depends-On: Ica5f4719c7c927a4e33ba818c40c9f6fc1a5ee7b Change-Id: Ib728b639ec0c1b079046ac0f8492449def36f2a0
* rdbms: add IDatabase::QUERY_* flags to obviate isWriteQuery()Aaron Schulz2020-04-281-1/+1
| | | | | | | | | | This reduces regex overhead and reliance on brittle assumptions. This will also be useful for complex write queries involving WITH. Some RDBMS types allow writes with in the WITH aliases themselves, in addition to the main query itself. Checking raw SQL strings for such things would get fairly complex. Change-Id: I8ac4bc4d671abf02f97e82c5daf7b21271b85e5e
* rbms: optimize and rename truncateTable() to truncate()Aaron Schulz2020-04-211-1/+1
| | | | | | | | | | | | | | | | Allow truncation of multiple tables. This also provides for a way to avoid risky keywords like CASCADE for Postgres. For Postgres, use RESTART IDENTITY, which has been supported since Postgres 8.4. Avoid TRUNCATE/DELETE queries for empty temp tables, which is useful for integrations tests that frequently call this method. Reorganize and tweak the regexes in Database::getTempWrites(). It now recognizes multi-table DROP/TRUNCATE (Postgres-style). Change-Id: Idd49f118b20ea5a0f7a3e8c00369aabcd45dd44e
* rdbms: reduce duplication in Database via helper methodsAaron Schulz2020-03-101-37/+43
| | | | | | | | | | | | | | Add several new internal methods to help with wrangling the various formats that rows, conditions, options, and unique key lists can come in. Remove now unused method isMultiRowArray(). Add various sanity checks and logging for parameters to upsert(), replace(), insert(), and insertSelect(). Move DatabasePostgresTest to the integration/ directory. Change-Id: If5988a6f0816e8da2cbf2fd612e1a3e3a2e9c52f
* rdbms: inject replLogger into Database and consolidate duplicated loggingAaron Schulz2020-02-231-0/+1
| | | | | Bug: T235244 Change-Id: I9397f6f74f703a395ef1be4713702247060d8bd4
* rdbms: make Database::build(Greatest|Least) support expressionsAaron Schulz2020-02-152-0/+20
| | | | | | | | This makes it possible to use with counter UPDATE queries. Also add some extra sanity checks for input types. Change-Id: Ibc2b7173e28022b5ba7bb04d11c594313a47a101
* Add SelectQueryBuilderTim Starling2020-02-071-4/+2
| | | | | | | | | | | Add a query builder class which encapsulates the parameters to IDatabase::select() and related functions. Override useIndexClause() and ignoreIndexClause() in DatabaseTestHelper so that index hints can be tested. Bug: T243051 Change-Id: I58eec4eeb23bd7fb05b8b77d0a748f1026afee52
* In Database::select() allow an empty array for $tableTim Starling2020-02-071-0/+7
| | | | | | | | | Previously it would give FROM followed by nothing which is always a syntax error. Easier to fix it here than to convert empty arrays to empty strings in SelectQueryBuilder. Bug: T243051 Change-Id: I95a9b6a34cfb5c1ca4cf243c4226b5ed4f968035
* rdbms: add GREATEST/LEAST wrappers to IDatabaseAaron Schulz2020-01-172-2/+135
| | | | Change-Id: I9de931123b03ce10713a3a9bbb34e1332dd5965b
* Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUseJames D. Forrester2020-01-103-9/+9
| | | | Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
* Coding style: Auto-fix MediaWiki.Usage.PHPUnit*James D. Forrester2020-01-101-8/+8
| | | | Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
* DatabaseTest: fix provider for testIsWriteQuerydaniel2020-01-071-2/+3
| | | | | | | | testIsWriteQuery() never worked. It was using a non-existing provider, which caused the test to be skipped with a warning. Access to the protected method under test also needed fixing. Change-Id: If35789027f2d6c44a7079e68a1c07c86be72d42b
* Merge "Improve tests in DoctrineSchemaBuilder"jenkins-bot2020-01-061-37/+10
|\
| * Improve tests in DoctrineSchemaBuilderAmir Sarabadani2019-11-221-37/+10
| | | | | | | | | | | | | | | | | | | | Also changing its structure to be more readable and more like https://w.wiki/CXo My plan is to add more tables to this test. Bug: T230428 Change-Id: Ia19d5c875cc95238f7fd7cd9adbed1ddb92af078
* | rdbms: Account for leading spaces in isWriteQueryDaimona Eaytoy2019-12-301-0/+29
| | | | | | | | | | Bug: T241034 Change-Id: I313e81dddeb9faef1780c9780fb575a5f8376bf4
* | Fixes for PHPUnit 8 compatibilityDaimona Eaytoy2019-12-102-6/+7
|/ | | | | Bug: T192167 Change-Id: Ic14f5debc53e55d67146dc96279d26dfd52b4000
* Merge "Have Database::addQuotes() pass through bare integers without quoting"jenkins-bot2019-11-182-46/+46
|\
| * Have Database::addQuotes() pass through bare integers without quotingTim Starling2019-11-182-46/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Quotes started being added to integers in r4984 (August 2004). Before that, is_numeric() was used to determine whether to add quotes, so quotes were omitted from numeric strings, which is obviously wrong. The idea here is to use the type of the variable to hint to the database as to whether quotes are needed. The results are somewhat inconsistent, since some callers do not convert numeric strings obtained from user input to integers. That makes it a more conservative change. Callers can opt out of unquoted integers by casting them to string. The reason for doing this is that quoting integers turns out to be not as harmless as originally assumed. We found a case of it confusing the MariaDB query planner, causing inappropriate indexes to be used. I also made addQuotes() consistently return a string, instead of returning an integer for boolean values. This was already the case for MySQL, but it seems like a good idea everywhere. Bug: T238378 Change-Id: I70473280f542ee5ecd79e187f580807410fbd548
* | Merge "rdbms: Fix DatabaseMysqlBase::streamStatementEnd() possibly failing"jenkins-bot2019-11-181-0/+19
|\ \ | |/ |/|
| * rdbms: Fix DatabaseMysqlBase::streamStatementEnd() possibly failingThiemo Kreuz2019-11-081-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a string starts with "DELIMITER" but the word is *not* followed by a space, the code will set $this->delimiter to null, possibly resulting in all kinds of hard to track errors. Even more problematic: the preg_match was *not* case-insensitive, but the condition was. Which means that all non-uppercase "delimiter …" would result in the same error. I'm not sure if it's worth keeping the additional string comparison for performance reasons. Probably not. That comparison is slow as well, and preg_match is surprisingly fast (when the pattern is properly written, which it is). Change-Id: I33944b7a2410f77e67ce7450af0359a88d39f1aa
* | Start of DoctrineSchemaBuilderAmir Sarabadani2019-11-091-0/+56
|/ | | | | | | This allows us to abstract away schemas into one json file. Bug: T230419 Change-Id: Ic8a658c97150e4c248bdbc9a5cf5d947b8c71036
* tests: Add explicit return type void to setUp() and tearDown()Max Semenik2019-10-302-2/+2
| | | | | | Bug: T192167 Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43 Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
* phpcs: Enable ↵James D. Forrester2019-10-144-13/+8
| | | | | | MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedException* and make pass Change-Id: I63f97497714a32236268be6965c5e181dade6c58
* rdbms: various cleanups to LoadBalancer::reallyOpenConnection()Aaron Schulz2019-10-111-0/+2
| | | | | | | | | | | | | | | | | | Move the DBO_TRX init logic out of Database::__construct() and into LoadBalancer since the later already handles setting and clearing this flag based on transaction rounds starting and ending. Add 'lazyMasterHandle', 'topologyRole', and 'topologicalMaster' parameters to Database::factory() and inject them via LoadBalancer all at once in order to avoid worrying about call order. Move some type casting code to Database::__construct(). Add IDatabase::getTopologyRole()/getTopologicalMaster(). Use constants for getLBInfo()/setLBInfo() for better usage tracking and typo resistance. Change-Id: I437ce434326601e6ba36d9aedc55db396dfe4452
* Add public as visibility in tests folderUmherirrender2019-10-101-1/+1
| | | | | | | Add public, protected or private to function missing a visibility Enable the tests folder for the phpcs sniff Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
* Merge "rdbms: Add (soft) type hints to DatabaseMysqlBaseTest"jenkins-bot2019-10-071-16/+26
|\
| * rdbms: Add (soft) type hints to DatabaseMysqlBaseTestThiemo Kreuz2019-09-231-16/+26
| | | | | | | | | | | | | | | | | | | | | | | | These type hints make it easier to follow the code paths and understand what code is actually under test here. A few of these tests appear to be misplaced, as they don't cover any code in the DatabaseMysqlBase class. This also makes all @covers tags absolute so more tools can understand them (e.g. PHPStorm doesn't). Change-Id: I43c69be994d6094239954ea662801c1e7e8e2e41
* | Update tests to use PHPUnit 6 class namesMax Semenik2019-10-061-1/+2
| | | | | | | | | | Bug: T192167 Change-Id: I42b0c8908b4968b95b08f861a40af18dc79fa0a1
* | Begin cleaning up PHPUnit 4 code from testsMax Semenik2019-10-045-13/+8
| | | | | | | | | | | | | | This process will be broken up into several parts for reviewability. Bug: T192167 Change-Id: Ie415fd3308384a5ca2b3de24ba037785f8a3a714
* | tests: Replace PHPUnit's loose assertEquals(false) with assertFalse()Thiemo Kreuz2019-10-042-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | assertEquals( false, … ) still succeeds when the actual value is 0, null, an empty string, even an empty array. All these should be reported as a failure, I would argue. Note this patch previously also touched assertSame( false ). I reverted these. The only benefit would have been consistency within this codebase, but there is no strict reason to prefer one over the other. assertFalse() and assertSame( false ) are functionally identical. Change-Id: Ic5f1c7d504e7249002d3184520012e03313137b4
* | rdbms: fix active GTID filtering in DatabaseMysqlBaseAaron Schulz2019-09-251-2/+8
|/ | | | | | | | | | | | | | | In masterPosWait(), only $pos will have the known active domain/server set since it usually comes from getMasterPos(). However, the reference position, from getReplicaDB(), does not have the active domains set since querying gtid_domain_id on the replica would be incorrect and getting a connection to the master could be expensive. Remove obsolete hacks for jobs that used to store master positions. Also, use the regular Database::query() method for stylistic consistency. Bug: T224422 Change-Id: I41bbb9f337e46451aa17788dbd446db4a213a5a7
* tests: Prefer assertSame() when comparing the integer 0Thiemo Kreuz2019-09-192-15/+15
| | | | | | | assertSame() is guaranteed to not do any type conversion. This can be critical when acciden tially comparing, for example, 0 to 0.0. Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
* rdbms: expand on LoadBalancer ownership conceptAaron Schulz2019-09-051-1/+1
| | | | | | | | | | | | | | | | | | | | Enforce this pattern for the remaining LoadBalancer methods. Carry this over into Database::close() to decide how loud the error handling should be. In LBFactory, clean up ownership of newMainLB()/newExternalLB(). The should have a null owner if called from outside the class since the LBFactory does not track nor care about them anymore in that case. Disable newMainLB() for LBFactorySingle as it makes no sense and was broken. Also remove some redundant abstract LBFactory methods that just duplciate ILBFactory. Bug: T231443 Bug: T217819 Depends-On: I7ed5c799320430c196a9a8e81af901999e2de7d0 Change-Id: I90b30a79754cfcc290277d302052e60df4fbc649
* Revert "rdbms: make LoadBalancer::reallyOpenConnection() handle setting DBO_TRX"Urbanecm2019-08-251-2/+0
| | | | | | | | | This reverts commit 45831e619c5e667ae1201bcdacfb8d4dcce10b41. Reason for revert: Caused beta not work at all. Bug: T231162 Change-Id: Icc5c1fa0dc01082a622641ad96c22c939cd56d48