Commit graph

59 commits

Author SHA1 Message Date
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
Wandji69
c257e2276c Replace db with getDb for Tests
Bug: T316841
Change-Id: I29e535e8ee9b5641a4546d53b98cd5060d39681d
2024-06-23 23:47:56 +01:00
Timo Tijhof
9153336c7b rdbms: Widen @covers tags in phpunit tests
> Given all called methods are de-facto and liberally claimed, and
> that we keep the coverage limited to the subject class, it maintains
> the spirit and intent by listing the class explicitly instead.
>
> PHPUnit offers a more precise tool when you need it (i.e. when testing
> legacy monster/god classes), but for well-written code, the
> class-wide tag is exactly what you want.
>
> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors (or worse, forget to do so).
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".

Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

Change-Id: I0fcbdb2936130b725000a899d733ec306e93b273
2024-06-11 22:47:42 +00:00
Aaron Schulz
da3ecd42b3 rdbms: clean up indexExists() and indexUnique() in Database
Make these methods handle table names the same way as other methods,
expecting unqualified table names.

Make indexExists() consistently return a boolean for all classes.

Make indexUnique() return null when the index does not exist.
This is more consistent with the naming of the method.

Bug: T361078
Change-Id: I4dc1eb5dfc67be09927cc669e9a588dc66c80f56
2024-06-03 08:36:50 -07:00
thiemowmde
37e4c52e00 Replace a few manually crafted assertTrue assertions
… replace them with the named convenience methods provided by
PHPUnit.

Change-Id: Ib46dbc3ab7926cf176477254f466b9bdd3be7c46
2023-11-23 09:38:48 +01:00
James D. Forrester
447400b423 rdbms: Drop old class aliases
Bug: T344536
Depends-On: I565541d781caaf564ae0c1877f5cb086e3650f22
Depends-On: Ia5fdf3242f9510e4f21670f3746d9364ae2935c6
Depends-On: I6f4b158bdc3ef20a1660e66accca0ffc17104f49
Change-Id: Ia87f1be7e0e68eb7cf792cb1f5ae64ecdfa2c015
2023-08-24 15:18:13 -04:00
Amir Sarabadani
95746494bf tests: Switch to SelectQueryBuilder in Sqlite and PG integration tests
Bug: T311866
Change-Id: Icd803be5d9e5408ceb180b11fd44b8be45a89c44
2023-07-20 13:01:37 +02:00
jenkins-bot
fd260306ee Merge "rdbms: make IDatabase::insertId() less fragile and more consistent" 2023-05-29 03:18:38 +00:00
Aaron Schulz
ac1819cc32 Remove uses Database::update()/Database::insert() return values
Change-Id: I527ea0900cc76faac9506b2a43a2b1522b35dfbd
2023-05-27 02:19:55 +00:00
Aaron Schulz
924d1f0374 rdbms: make IDatabase::insertId() less fragile and more consistent
Track the insert ID value in Database, similar to the affected rows.
This makes it possible for subclasses to stash or override the value,
which is useful when emulating a write operation using multiple queries.
This includes the case of internal use of atomic sections, where the
COMMIT/RELEASE can reset the last_insert_id tracked in the PECL driver
itself.

Use separate methods and fields for "last query statement" information
and "last query method" information.

Make insertId() for SQLite and Postgres better match MySQL:
* Return 0 if the last query statement did not change any rows.
  This helps protect against callers that fail to check affectedRows().
* Make it return the existing ROWID/SERIAL column when upsert() updates
  an existing row. This adds a new getInsertIdColumnForUpsert() helper
  function.

Directly use query() in doReplace() and doInsertSelectGeneric() to make
the affected row/ID logic easier to follow.

Improve insertId() and affectedRows() documentation.

Add more integration tests of row insertion methods.

Bug: T314100
Change-Id: I7d43a2e52260e66acb713554bb883f5f4a14d010
2023-05-26 19:01:45 -07:00
Amir Sarabadani
9e6fa0d225 rdbms: Introduce Query object
An interesting portion of rdbms is building SQL and then trying to
reverse engineer what tf the given SQL is doing, whether it's a write
query or not, whether it's writing to temp tables, etc.

Let's just pass around the actual data instead.

Bug: T326181
Change-Id: I4d7c72c08c98b884de51b46abf6460229055dcc9
2023-04-28 23:44:38 +02:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
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
2023-03-24 02:53:57 +00:00
Amir Sarabadani
7ffd35ecc6 rdbms: Remove Database::attributesFromType and hard-deprecate ::factory
They have been soft-deprecated since 1.39 and the first one is not used
anywhere, ::factory is used in some third party code but not in
Wikimedia-deployed ones

Change-Id: Icd0f743d9c76554dd02471485ee732e25b9fb932
2023-02-23 17:59:54 +00:00
Timo Tijhof
4ef0891994 rdbms: Consolidate logger channels into one
Notable changes:

* In SqlBagOStuff::getConnectionFromServerInfo, only two loggers were
  injected. The rest implicitly got a NullLogger due to being absent.
  These are now effectively unsilenced.

* Database::__construct() required almost all parameters, even the
  loggers. I've wanted to move some of DatabaseFactory into the ctor
  here for a while. In order to make this change not a breaking
  change, the new 'logger' parameter is optional with NullLogger as
  default. This allowed some of the test cases, which were simply
  passing NullLogger, to be fixed by passing nothing instead of
  passing the new option name.

  The Database class is behind a dozen layers of indirection for
  real use, so this will still be injected just fine (DBF, LB, LBF,
  MWLBF, etc.).

* In LegacyLogger, the handling for $wgDBerrorLog was previously
  limited to DBConnection and DBQuery. This now includes errors
  from other (generally, newer) parts of Rdbms as well, which were
  previously missing.

  This only affects sites (typically CI and dev setup) where
  $wgDBerrorLog is used, as opposed to the more common
  $wgDebugLogGroups by-channel configuration.

* TransactionProfiler gets its logger injected in a rather odd way,
  via entrypoints (MediaWiki.php, ApiMain.php, and MaintenanceRunner)
  as opposed to service wiring. This is kept as-is for now.

* In LBFactoryTest, in particular testInvalidSelectDBIndependent2,
  there are cases that intentionally produce failures of which
  the result is then observed. In CI we assert that dberror.log is
  empty so instead of adding the missing logger fields to that
  LBFactory instance, the only one set (replLogger) is removed.
  The alternative is to set 'logger' now, which would naturally
  cause CI failures due to unexpected entries coming through to
  non-mocked error log.

Bug: T320873
Change-Id: I7ca996618e41b93f488cb5c4de82000bb36e0dd3
2023-01-03 22:46:38 +00:00
Aaron Schulz
23eab3ec39 rdbms: make SqlitePlatform::tableName() apply double quotes
The RDBMs classes treat table names as application-supplied rather
than user-supplied, since it does not make sense for the user to be
able to blindly pick the schema (likely causing query errors). Table
names are generally non-problematic [a-zA-Z0-9_]+ strings. However,
they still should be escaped as identifiers, since they might have
problematic characters. Fix the SQLite backend to apply escaping
here, similar to MySQL and Postgres.

Fix incorrect use of tableName() in DatabaseSqlite::fieldInfo().
It should work the same as in tableExists().

Bug: T72510
Change-Id: I3713f81e6e1eca84cc51c12c9307d4c5dc737043
2022-11-23 00:17:40 +00:00
Aaron Schulz
fe7301c9ba rdbms: remove getTopologyRootPrimary() and clean up related fields/parameters
This method is unused and the naming is not very clear in terms of what
it returns (server name vs config map). Removing it reduces externally
exposed complexity.

Optimize DBConnRef::getServerName() when the server index is known.
Use this to eliminate the "topologicalMaster" parameter from Database.

Rename internal fields and paramters in Database to use "primary"
instead of "master", for consistency.

Add some additional clarifying comments.

Bug: T299691
Change-Id: I98515fa02a58a4c72a06f1ff283b249b1617c886
2022-08-26 12:26:10 -07:00
Amir Sarabadani
2eb242f40a rdbms: Drastically simplify Sqlite db tests
Now that we moved considerable chunk of DatabaseSqlite to
SqlitePlatform, it's easier to mock and test without actually needing a
live db connection.

This allows moving a lot of tests from integration to unit tests making
them much faster.

Change-Id: I8ce7c470abed5144ba456a000c733e5d739c5c4e
2022-08-08 14:38:20 +02:00
jenkins-bot
26a8cd5bd3 Merge "Cast results of Sqlite test to string [php 8.1]" 2022-08-03 12:44:52 +00:00
Amir Sarabadani
9bb6189a30 rdbms: Migrate SchemaVar and replaceVars from Database to SQLPlatform
Bug: T307616
Change-Id: I0975dd0328236c34b4e6c6df846e2465da31b750
2022-08-02 10:14:54 +02:00
Brian Wolff
1e50e2e538 Cast results of Sqlite test to string [php 8.1]
It seems that on php 8.1, the data fetching from sqlite will
fetch integers for integer fields instead of strings. Cast
everything to strings so the test works on both php 8.1 and 7.x.

Bug: T313663
Change-Id: I0a2c2ab95b84565186ac7417f6cfdef2215f6bf1
2022-07-29 22:17:41 -07:00
Umherirrender
b0398654c5 tests: Do not use class alias in @covers
Also fix case for the XMLTypeCheck test

Change-Id: I809510c8085a36e20fd0eefb5e77d2671b3148f2
2022-05-28 00:37:43 +02:00
Aryeh Gregor
4851f512b3 IResultWrapper::next() now returns void
As required by the Iterator interface. In PHP 8.1 we can suppress the
warning with #[\ReturnTypeWillChange], but it's wrong and should change
anyway.

Depends-On: I576109808755b054e7876556f244ee8eafd12f9d
Change-Id: Ibaa7b4c81d8f114783db45c9100200ba14547c8f
2022-05-02 10:43:51 +03:00
Aaron Schulz
277d34818b tests: Split out DatabaseSqliteUpgradeTest class
The testUpgrades() method is slow and is easier to
parallelize via paratest if it lies in a separate class/file

Also make the test use a data provider

Bug: T50217
Change-Id: I5c8df6ae0ff34941f4cf7275680b309e79565925
2022-03-10 23:29:29 -08:00
Ammarpad
e9e3c4a75f Fix broken SQLite test and simplify.
This is not testing anything since tables.sql was emptied
in I9f33132

It's probably also no longer necessary, since the schema
is now generated by Doctrine per platform, but I am not sure
about that, so I am just fixing the test and simplifying it.

Change-Id: Icb4d04e6057958771eb00a31b967a42cc948d6a1
2022-03-02 22:39:53 +01:00
Amir Sarabadani
050fbbec8f rdbms: Remove IDatabase::numFields() method
Soft-deprecated since 1.37.

Unused https://codesearch.wmcloud.org/search/?q=numFields&i=nope&files=&excludeFiles=&repos=

Bug: T286694
Bug: T296960
Change-Id: I722602c8b11dcfc5cab70593876a4fb336e9684a
2021-12-21 23:10:49 +00:00
Amir Sarabadani
c3fff36540 Add 1.36 and 1.37 snapshots to sqlite db tests
To make sure upgrades from those versions work properly

Change-Id: I570cf965286bc5358a43c9601217b8781bb09b0e
2021-09-29 20:13:38 +02:00
Amir Sarabadani
753a4ecdd3 Bump minimum required version for upgrade to 1.29
Since the branch cut has happened, we can bump and get rid of legacy
cruft. According to the policy we can go up to 1.31 but let's keep it
that way to avoid major distruptions.

Change-Id: I9d697445a3bb5047726c8b2a7f808edb8403cdda
2021-09-28 17:57:57 +02: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
Aaron Schulz
99d5d2e8cc rdbms: cleanup getServer() and connection parameter fields in Database
Make getServer() always return a string, as documented, even with new
Database::NEW_UNCONNECTED handles that have yet to call open(). If the
'host' parameter to __construct() is ''/null, getServer() now returns
'localhost' instead of null. This avoids problems like fatal errors in
calls to TransactionProfiler::recordConnection().

Use Database constants for "connectionParams" field keys for better
static analysis.

Also:
* Add Database::getServerName() method that returns "readable" server
  names in the style of LoadBalancer::getServerName(). Note that the
  "hostName" field is already passed in from LoadBalancer.
* Migrate most getServer() callers to getServerName() for easier
  debugging and more readable logging.
* Also, normalize Database/LoadBalancer SPI logging context to use
  "db_server" and reduce logging code duplication in LoadBalancer.

Bug: T277056
Change-Id: I00ed4049ebb45edab1ea07561c47e226a423ea3b
2021-05-05 19:44:02 +00:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Amir Sarabadani
ba4a80facc Remove old exceptions from DatabaseSqliteTest
Follow up to Ib5251f7ae3814

Change-Id: I5e1503506cb55673c9283dcbe1d38a46cb7e1edd
2021-02-05 23:29:33 +00:00
Amir Sarabadani
78e6c48156 Rework sqlite schema changes tests
We don't support upgrading from below 1.31 officially and from below 1.27, the
upgrade system doesn't work at all.

The files are copied from the release branches.

Bug: T259771
Change-Id: Ib5251f7ae38148e00ac2dccb7bde76529c9d5076
2021-02-05 16:21:24 +00:00
Thiemo Kreuz
ac205fa84c Fix incomplete/bogus PHPDoc tags in various tests
Most of these are found by the not yet released I10559d8.

I remove the type MockObject in some cases when the calling
code really does not need to know if he get's a mock or the
real thing. However, I do this only in places that are very
closely related to the fixes.

Change-Id: I26a4c3c5a8ae141bf56161b52b54bce7e68f2e30
2021-01-14 19:02:00 +00:00
Daimona Eaytoy
2b37cfaf18 build: Bump mediawiki-codesniffer to 31.0.0
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
2020-05-30 14:56:28 +00:00
Amir Sarabadani
11f241589b Wire empty abstract schema into installer
For more information on schema changes see:
https://www.mediawiki.org/wiki/Manual:Schema_changes

Bug: T191231
Bug: T230428
Change-Id: I779b9c61e388e998738a2ed41b0b8e2afdecd232
2020-05-09 20:42:11 +02:00
Amir Sarabadani
6319ffa1b7 Do not assume case in checking NULL in DatabaseSqliteTest
Currently, when trying to automatically generate the schema, it
majestically explodes because "NULL" is not equal to "null".

Change-Id: I0facf313525eee1af31fdb307368ecf3bdda895b
2020-05-09 14:10:08 +00:00
Aaron Schulz
86533ae590 Drop DEFAULT from *_actor columns for SQLite tables that still have it
These were left out by mistake (made easier by a bug where some phpunit
tests never run). Fixing the test bug is blocked on fixing the SQLite
schema so that DatabaseSqliteTest.php passes when it actually runs.

Bug: T246077
Change-Id: I75d7a7fb56a07c2984e987b6136e1fd00615c421
2020-03-19 21:17:56 -07:00
Aaron Schulz
f13b3c8521 Fix obsolete version-based tests in DatabaseSqliteTest
These failed and servered no use after 6cf729838f

Change-Id: I29f5e761b977c1c831afd75da901b5e58a4bbde1
2020-03-18 14:32:26 -07:00
Aaron Schulz
13b11a946e rdbms: reduce duplication in Database via helper methods
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
2020-03-10 22:26:04 +00:00
jenkins-bot
44354f45eb Merge "rdbms: inject replLogger into Database and consolidate duplicated logging" 2020-03-04 21:29:23 +00:00
Aaron Schulz
a14a1f39a1 rdbms: support native batched replace() in DatabaseSqlite
Change-Id: Icc6d6ff7412d6a686b200e7d8432840b46377d10
2020-03-02 15:10:15 +00:00
Peter Ovchyn
9b34f6786a sqlite: Fix broken integration tests for SQLite db driver
Bug: T245995
Change-Id: I280487bf27e4864eba8c0f02f408306061b948b2
2020-02-26 21:57:09 +02:00
Timo Tijhof
f575721a06 Update all use of $wgVersion to MW_VERSION
Follows-up I04628de4152dd5.

Bug: T212738
Change-Id: I718474ec0d9fd29ac2c05477f0f2493615d8aff5
2020-02-25 02:16:12 +00:00
Aaron Schulz
6c5d937adb rdbms: inject replLogger into Database and consolidate duplicated logging
Bug: T235244
Change-Id: I9397f6f74f703a395ef1be4713702247060d8bd4
2020-02-23 00:33:33 +00:00
jenkins-bot
9b1067846d Merge "Coding style: Auto-fix MediaWiki.Usage.PHPUnit*" 2020-01-10 16:59:11 +00:00
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
Aaron Schulz
3c1c9b5098 rdbms: support native batched insert() in DatabaseSqlite
This was added in 4bd1b4b455 but reverted due to a bug in other
changes within that patch, namely, the replace() method changes.

Change-Id: Id73c3fed9e1862daeeecbf47bcfa53d1719c59bb
2020-01-06 18:17:46 +00:00
Daimona Eaytoy
f5529400cc Stop using assertContains with string haystack
This was done automatically by replacing every assertContains with
string *needle*. Then verifying the results.

Bug: T192167
Change-Id: Id8cbbf3b01e948f80046714183cc299f86be21fd
2019-12-15 00:22:44 +00:00
Daimona Eaytoy
6365eaab8d Autofix 94 PHPUnit 8 compat issues
Done automatically using the master version of MW codesniffer and
running composer fix.

Bug: T192167
Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
2019-12-13 15:29:10 +01:00