MediaWiki REL1_31
DatabaseTest.php
Go to the documentation of this file.
1<?php
2
8use Wikimedia\TestingAccessWrapper;
12
13class DatabaseTest extends PHPUnit\Framework\TestCase {
14
15 use MediaWikiCoversValidator;
16
17 protected function setUp() {
18 $this->db = new DatabaseTestHelper( __CLASS__ . '::' . $this->getName() );
19 }
20
25 public function testFactory() {
26 $m = Database::NEW_UNCONNECTED; // no-connect mode
27 $p = [ 'host' => 'localhost', 'user' => 'me', 'password' => 'myself', 'dbname' => 'i' ];
28
29 $this->assertInstanceOf( DatabaseMysqli::class, Database::factory( 'mysqli', $p, $m ) );
30 $this->assertInstanceOf( DatabaseMysqli::class, Database::factory( 'MySqli', $p, $m ) );
31 $this->assertInstanceOf( DatabaseMysqli::class, Database::factory( 'MySQLi', $p, $m ) );
32 $this->assertInstanceOf( DatabasePostgres::class, Database::factory( 'postgres', $p, $m ) );
33 $this->assertInstanceOf( DatabasePostgres::class, Database::factory( 'Postgres', $p, $m ) );
34
35 $x = $p + [ 'port' => 10000, 'UseWindowsAuth' => false ];
36 $this->assertInstanceOf( DatabaseMssql::class, Database::factory( 'mssql', $x, $m ) );
37
38 $x = $p + [ 'dbFilePath' => 'some/file.sqlite' ];
39 $this->assertInstanceOf( DatabaseSqlite::class, Database::factory( 'sqlite', $x, $m ) );
40 $x = $p + [ 'dbDirectory' => 'some/file' ];
41 $this->assertInstanceOf( DatabaseSqlite::class, Database::factory( 'sqlite', $x, $m ) );
42 }
43
44 public static function provideAddQuotes() {
45 return [
46 [ null, 'NULL' ],
47 [ 1234, "'1234'" ],
48 [ 1234.5678, "'1234.5678'" ],
49 [ 'string', "'string'" ],
50 [ 'string\'s cause trouble', "'string\'s cause trouble'" ],
51 ];
52 }
53
58 public function testAddQuotes( $input, $expected ) {
59 $this->assertEquals( $expected, $this->db->addQuotes( $input ) );
60 }
61
62 public static function provideTableName() {
63 // Formatting is mostly ignored since addIdentifierQuotes is abstract.
64 // For testing of addIdentifierQuotes, see actual Database subclas tests.
65 return [
66 'local' => [
67 'tablename',
68 'tablename',
69 'quoted',
70 ],
71 'local-raw' => [
72 'tablename',
73 'tablename',
74 'raw',
75 ],
76 'shared' => [
77 'sharedb.tablename',
78 'tablename',
79 'quoted',
80 [ 'dbname' => 'sharedb', 'schema' => null, 'prefix' => '' ],
81 ],
82 'shared-raw' => [
83 'sharedb.tablename',
84 'tablename',
85 'raw',
86 [ 'dbname' => 'sharedb', 'schema' => null, 'prefix' => '' ],
87 ],
88 'shared-prefix' => [
89 'sharedb.sh_tablename',
90 'tablename',
91 'quoted',
92 [ 'dbname' => 'sharedb', 'schema' => null, 'prefix' => 'sh_' ],
93 ],
94 'shared-prefix-raw' => [
95 'sharedb.sh_tablename',
96 'tablename',
97 'raw',
98 [ 'dbname' => 'sharedb', 'schema' => null, 'prefix' => 'sh_' ],
99 ],
100 'foreign' => [
101 'databasename.tablename',
102 'databasename.tablename',
103 'quoted',
104 ],
105 'foreign-raw' => [
106 'databasename.tablename',
107 'databasename.tablename',
108 'raw',
109 ],
110 ];
111 }
112
117 public function testTableName( $expected, $table, $format, array $alias = null ) {
118 if ( $alias ) {
119 $this->db->setTableAliases( [ $table => $alias ] );
120 }
121 $this->assertEquals(
122 $expected,
123 $this->db->tableName( $table, $format ?: 'quoted' )
124 );
125 }
126
128 return [
129 'one-element array' => [
130 [ 'table' ], [], 'table '
131 ],
132 'comma join' => [
133 [ 'table1', 'table2' ], [], 'table1,table2 '
134 ],
135 'real join' => [
136 [ 'table1', 'table2' ],
137 [ 'table2' => [ 'LEFT JOIN', 't1_id = t2_id' ] ],
138 'table1 LEFT JOIN table2 ON ((t1_id = t2_id))'
139 ],
140 'real join with multiple conditionals' => [
141 [ 'table1', 'table2' ],
142 [ 'table2' => [ 'LEFT JOIN', [ 't1_id = t2_id', 't2_x = \'X\'' ] ] ],
143 'table1 LEFT JOIN table2 ON ((t1_id = t2_id) AND (t2_x = \'X\'))'
144 ],
145 'join with parenthesized group' => [
146 [ 'table1', 'n' => [ 'table2', 'table3' ] ],
147 [
148 'table3' => [ 'JOIN', 't2_id = t3_id' ],
149 'n' => [ 'LEFT JOIN', 't1_id = t2_id' ],
150 ],
151 'table1 LEFT JOIN (table2 JOIN table3 ON ((t2_id = t3_id))) ON ((t1_id = t2_id))'
152 ],
153 'join with degenerate parenthesized group' => [
154 [ 'table1', 'n' => [ 't2' => 'table2' ] ],
155 [
156 'n' => [ 'LEFT JOIN', 't1_id = t2_id' ],
157 ],
158 'table1 LEFT JOIN table2 t2 ON ((t1_id = t2_id))'
159 ],
160 ];
161 }
162
167 public function testTableNamesWithIndexClauseOrJOIN( $tables, $join_conds, $expect ) {
168 $clause = TestingAccessWrapper::newFromObject( $this->db )
169 ->tableNamesWithIndexClauseOrJOIN( $tables, [], [], $join_conds );
170 $this->assertSame( $expect, $clause );
171 }
172
177 public function testTransactionIdle() {
178 $db = $this->db;
179
180 $db->clearFlag( DBO_TRX );
181 $called = false;
182 $flagSet = null;
183 $callback = function () use ( $db, &$flagSet, &$called ) {
184 $called = true;
185 $flagSet = $db->getFlag( DBO_TRX );
186 };
187
188 $db->onTransactionIdle( $callback, __METHOD__ );
189 $this->assertTrue( $called, 'Callback reached' );
190 $this->assertFalse( $flagSet, 'DBO_TRX off in callback' );
191 $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX still default' );
192
193 $flagSet = null;
194 $called = false;
195 $db->startAtomic( __METHOD__ );
196 $db->onTransactionIdle( $callback, __METHOD__ );
197 $this->assertFalse( $called, 'Callback not reached during TRX' );
198 $db->endAtomic( __METHOD__ );
199
200 $this->assertTrue( $called, 'Callback reached after COMMIT' );
201 $this->assertFalse( $flagSet, 'DBO_TRX off in callback' );
202 $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX restored to default' );
203
204 $db->clearFlag( DBO_TRX );
205 $db->onTransactionIdle(
206 function () use ( $db ) {
207 $db->setFlag( DBO_TRX );
208 },
209 __METHOD__
210 );
211 $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX restored to default' );
212 }
213
218 public function testTransactionIdle_TRX() {
219 $db = $this->getMockDB( [ 'isOpen', 'ping' ] );
220 $db->method( 'isOpen' )->willReturn( true );
221 $db->method( 'ping' )->willReturn( true );
222 $db->setFlag( DBO_TRX );
223
224 $lbFactory = LBFactorySingle::newFromConnection( $db );
225 // Ask for the connection so that LB sets internal state
226 // about this connection being the master connection
227 $lb = $lbFactory->getMainLB();
228 $conn = $lb->openConnection( $lb->getWriterIndex() );
229 $this->assertSame( $db, $conn, 'Same DB instance' );
230 $this->assertTrue( $db->getFlag( DBO_TRX ), 'DBO_TRX is set' );
231
232 $called = false;
233 $flagSet = null;
234 $callback = function () use ( $db, &$flagSet, &$called ) {
235 $called = true;
236 $flagSet = $db->getFlag( DBO_TRX );
237 };
238
239 $db->onTransactionIdle( $callback, __METHOD__ );
240 $this->assertTrue( $called, 'Called when idle if DBO_TRX is set' );
241 $this->assertFalse( $flagSet, 'DBO_TRX off in callback' );
242 $this->assertTrue( $db->getFlag( DBO_TRX ), 'DBO_TRX still default' );
243
244 $called = false;
245 $lbFactory->beginMasterChanges( __METHOD__ );
246 $db->onTransactionIdle( $callback, __METHOD__ );
247 $this->assertFalse( $called, 'Not called when lb-transaction is active' );
248
249 $lbFactory->commitMasterChanges( __METHOD__ );
250 $this->assertTrue( $called, 'Called when lb-transaction is committed' );
251
252 $called = false;
253 $lbFactory->beginMasterChanges( __METHOD__ );
254 $db->onTransactionIdle( $callback, __METHOD__ );
255 $this->assertFalse( $called, 'Not called when lb-transaction is active' );
256
257 $lbFactory->rollbackMasterChanges( __METHOD__ );
258 $this->assertFalse( $called, 'Not called when lb-transaction is rolled back' );
259
260 $lbFactory->commitMasterChanges( __METHOD__ );
261 $this->assertFalse( $called, 'Not called in next round commit' );
262 }
263
269 $db = $this->getMockDB( [ 'isOpen' ] );
270 $db->method( 'isOpen' )->willReturn( true );
271 $db->clearFlag( DBO_TRX );
272
273 $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX is not set' );
274
275 $called = false;
276 $db->onTransactionPreCommitOrIdle(
277 function () use ( &$called ) {
278 $called = true;
279 },
280 __METHOD__
281 );
282 $this->assertTrue( $called, 'Called when idle' );
283
284 $db->begin( __METHOD__ );
285 $called = false;
286 $db->onTransactionPreCommitOrIdle(
287 function () use ( &$called ) {
288 $called = true;
289 },
290 __METHOD__
291 );
292 $this->assertFalse( $called, 'Not called when transaction is active' );
293 $db->commit( __METHOD__ );
294 $this->assertTrue( $called, 'Called when transaction is committed' );
295 }
296
302 $db = $this->getMockDB( [ 'isOpen', 'ping' ] );
303 $db->method( 'isOpen' )->willReturn( true );
304 $db->method( 'ping' )->willReturn( true );
305 $db->setFlag( DBO_TRX );
306
307 $lbFactory = LBFactorySingle::newFromConnection( $db );
308 // Ask for the connection so that LB sets internal state
309 // about this connection being the master connection
310 $lb = $lbFactory->getMainLB();
311 $conn = $lb->openConnection( $lb->getWriterIndex() );
312 $this->assertSame( $db, $conn, 'Same DB instance' );
313
314 $this->assertFalse( $lb->hasMasterChanges() );
315 $this->assertTrue( $db->getFlag( DBO_TRX ), 'DBO_TRX is set' );
316 $called = false;
317 $callback = function () use ( &$called ) {
318 $called = true;
319 };
320 $db->onTransactionPreCommitOrIdle( $callback, __METHOD__ );
321 $this->assertTrue( $called, 'Called when idle if DBO_TRX is set' );
322 $called = false;
323 $lbFactory->commitMasterChanges();
324 $this->assertFalse( $called );
325
326 $called = false;
327 $lbFactory->beginMasterChanges( __METHOD__ );
328 $db->onTransactionPreCommitOrIdle( $callback, __METHOD__ );
329 $this->assertFalse( $called, 'Not called when lb-transaction is active' );
330 $lbFactory->commitMasterChanges( __METHOD__ );
331 $this->assertTrue( $called, 'Called when lb-transaction is committed' );
332
333 $called = false;
334 $lbFactory->beginMasterChanges( __METHOD__ );
335 $db->onTransactionPreCommitOrIdle( $callback, __METHOD__ );
336 $this->assertFalse( $called, 'Not called when lb-transaction is active' );
337
338 $lbFactory->rollbackMasterChanges( __METHOD__ );
339 $this->assertFalse( $called, 'Not called when lb-transaction is rolled back' );
340
341 $lbFactory->commitMasterChanges( __METHOD__ );
342 $this->assertFalse( $called, 'Not called in next round commit' );
343 }
344
349 public function testTransactionResolution() {
350 $db = $this->db;
351
352 $db->clearFlag( DBO_TRX );
353 $db->begin( __METHOD__ );
354 $called = false;
355 $db->onTransactionResolution( function () use ( $db, &$called ) {
356 $called = true;
357 $db->setFlag( DBO_TRX );
358 } );
359 $db->commit( __METHOD__ );
360 $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX restored to default' );
361 $this->assertTrue( $called, 'Callback reached' );
362
363 $db->clearFlag( DBO_TRX );
364 $db->begin( __METHOD__ );
365 $called = false;
366 $db->onTransactionResolution( function () use ( $db, &$called ) {
367 $called = true;
368 $db->setFlag( DBO_TRX );
369 } );
370 $db->rollback( __METHOD__, IDatabase::FLUSHING_ALL_PEERS );
371 $this->assertFalse( $db->getFlag( DBO_TRX ), 'DBO_TRX restored to default' );
372 $this->assertTrue( $called, 'Callback reached' );
373 }
374
378 public function testTransactionListener() {
379 $db = $this->db;
380
381 $db->setTransactionListener( 'ping', function () use ( $db, &$called ) {
382 $called = true;
383 } );
384
385 $called = false;
386 $db->begin( __METHOD__ );
387 $db->commit( __METHOD__ );
388 $this->assertTrue( $called, 'Callback reached' );
389
390 $called = false;
391 $db->begin( __METHOD__ );
392 $db->commit( __METHOD__ );
393 $this->assertTrue( $called, 'Callback still reached' );
394
395 $called = false;
396 $db->begin( __METHOD__ );
397 $db->rollback( __METHOD__ );
398 $this->assertTrue( $called, 'Callback reached' );
399
400 $db->setTransactionListener( 'ping', null );
401 $called = false;
402 $db->begin( __METHOD__ );
403 $db->commit( __METHOD__ );
404 $this->assertFalse( $called, 'Callback not reached' );
405 }
406
416 private function getMockDB( $methods = [] ) {
417 static $abstractMethods = [
418 'fetchAffectedRowCount',
419 'closeConnection',
420 'dataSeek',
421 'doQuery',
422 'fetchObject', 'fetchRow',
423 'fieldInfo', 'fieldName',
424 'getSoftwareLink', 'getServerVersion',
425 'getType',
426 'indexInfo',
427 'insertId',
428 'lastError', 'lastErrno',
429 'numFields', 'numRows',
430 'open',
431 'strencode',
432 ];
433 $db = $this->getMockBuilder( Database::class )
434 ->disableOriginalConstructor()
435 ->setMethods( array_values( array_unique( array_merge(
436 $abstractMethods,
437 $methods
438 ) ) ) )
439 ->getMock();
440 $wdb = TestingAccessWrapper::newFromObject( $db );
441 $wdb->trxProfiler = new TransactionProfiler();
442 $wdb->connLogger = new \Psr\Log\NullLogger();
443 $wdb->queryLogger = new \Psr\Log\NullLogger();
444 return $db;
445 }
446
450 public function testFlushSnapshot() {
451 $db = $this->getMockDB( [ 'isOpen' ] );
452 $db->method( 'isOpen' )->willReturn( true );
453
454 $db->flushSnapshot( __METHOD__ ); // ok
455 $db->flushSnapshot( __METHOD__ ); // ok
456
457 $db->setFlag( DBO_TRX, $db::REMEMBER_PRIOR );
458 $db->query( 'SELECT 1', __METHOD__ );
459 $this->assertTrue( (bool)$db->trxLevel(), "Transaction started." );
460 $db->flushSnapshot( __METHOD__ ); // ok
461 $db->restoreFlags( $db::RESTORE_PRIOR );
462
463 $this->assertFalse( (bool)$db->trxLevel(), "Transaction cleared." );
464 }
465
472 public function testGetScopedLock() {
473 $db = $this->getMockDB( [ 'isOpen' ] );
474 $db->method( 'isOpen' )->willReturn( true );
475
476 $this->assertEquals( 0, $db->trxLevel() );
477 $this->assertEquals( true, $db->lockIsFree( 'x', __METHOD__ ) );
478 $this->assertEquals( true, $db->lock( 'x', __METHOD__ ) );
479 $this->assertEquals( false, $db->lockIsFree( 'x', __METHOD__ ) );
480 $this->assertEquals( true, $db->unlock( 'x', __METHOD__ ) );
481 $this->assertEquals( true, $db->lockIsFree( 'x', __METHOD__ ) );
482 $this->assertEquals( 0, $db->trxLevel() );
483
484 $db->setFlag( DBO_TRX );
485 $this->assertEquals( true, $db->lockIsFree( 'x', __METHOD__ ) );
486 $this->assertEquals( true, $db->lock( 'x', __METHOD__ ) );
487 $this->assertEquals( false, $db->lockIsFree( 'x', __METHOD__ ) );
488 $this->assertEquals( true, $db->unlock( 'x', __METHOD__ ) );
489 $this->assertEquals( true, $db->lockIsFree( 'x', __METHOD__ ) );
490 $db->clearFlag( DBO_TRX );
491
492 $this->assertEquals( 0, $db->trxLevel() );
493
494 $db->setFlag( DBO_TRX );
495 try {
496 $this->badLockingMethodImplicit( $db );
497 } catch ( RunTimeException $e ) {
498 $this->assertTrue( $db->trxLevel() > 0, "Transaction not committed." );
499 }
500 $db->clearFlag( DBO_TRX );
501 $db->rollback( __METHOD__, IDatabase::FLUSHING_ALL_PEERS );
502 $this->assertTrue( $db->lockIsFree( 'meow', __METHOD__ ) );
503
504 try {
505 $this->badLockingMethodExplicit( $db );
506 } catch ( RunTimeException $e ) {
507 $this->assertTrue( $db->trxLevel() > 0, "Transaction not committed." );
508 }
509 $db->rollback( __METHOD__, IDatabase::FLUSHING_ALL_PEERS );
510 $this->assertTrue( $db->lockIsFree( 'meow', __METHOD__ ) );
511 }
512
513 private function badLockingMethodImplicit( IDatabase $db ) {
514 $lock = $db->getScopedLockAndFlush( 'meow', __METHOD__, 1 );
515 $db->query( "SELECT 1" ); // trigger DBO_TRX
516 throw new RunTimeException( "Uh oh!" );
517 }
518
519 private function badLockingMethodExplicit( IDatabase $db ) {
520 $lock = $db->getScopedLockAndFlush( 'meow', __METHOD__, 1 );
521 $db->begin( __METHOD__ );
522 throw new RunTimeException( "Uh oh!" );
523 }
524
530 public function testFlagSetting() {
531 $db = $this->db;
532 $origTrx = $db->getFlag( DBO_TRX );
533 $origSsl = $db->getFlag( DBO_SSL );
534
535 $origTrx
536 ? $db->clearFlag( DBO_TRX, $db::REMEMBER_PRIOR )
537 : $db->setFlag( DBO_TRX, $db::REMEMBER_PRIOR );
538 $this->assertEquals( !$origTrx, $db->getFlag( DBO_TRX ) );
539
540 $origSsl
541 ? $db->clearFlag( DBO_SSL, $db::REMEMBER_PRIOR )
542 : $db->setFlag( DBO_SSL, $db::REMEMBER_PRIOR );
543 $this->assertEquals( !$origSsl, $db->getFlag( DBO_SSL ) );
544
545 $db->restoreFlags( $db::RESTORE_INITIAL );
546 $this->assertEquals( $origTrx, $db->getFlag( DBO_TRX ) );
547 $this->assertEquals( $origSsl, $db->getFlag( DBO_SSL ) );
548
549 $origTrx
550 ? $db->clearFlag( DBO_TRX, $db::REMEMBER_PRIOR )
551 : $db->setFlag( DBO_TRX, $db::REMEMBER_PRIOR );
552 $origSsl
553 ? $db->clearFlag( DBO_SSL, $db::REMEMBER_PRIOR )
554 : $db->setFlag( DBO_SSL, $db::REMEMBER_PRIOR );
555
556 $db->restoreFlags();
557 $this->assertEquals( $origSsl, $db->getFlag( DBO_SSL ) );
558 $this->assertEquals( !$origTrx, $db->getFlag( DBO_TRX ) );
559
560 $db->restoreFlags();
561 $this->assertEquals( $origSsl, $db->getFlag( DBO_SSL ) );
562 $this->assertEquals( $origTrx, $db->getFlag( DBO_TRX ) );
563 }
564
569 public function testDBOIgnoreSet() {
570 $db = $this->getMockBuilder( DatabaseMysqli::class )
571 ->disableOriginalConstructor()
572 ->setMethods( null )
573 ->getMock();
574
575 $db->setFlag( Database::DBO_IGNORE );
576 }
577
582 public function testDBOIgnoreClear() {
583 $db = $this->getMockBuilder( DatabaseMysqli::class )
584 ->disableOriginalConstructor()
585 ->setMethods( null )
586 ->getMock();
587
588 $db->clearFlag( Database::DBO_IGNORE );
589 }
590
595 public function testMutators() {
596 $old = $this->db->tablePrefix();
597 $this->assertInternalType( 'string', $old, 'Prefix is string' );
598 $this->assertEquals( $old, $this->db->tablePrefix(), "Prefix unchanged" );
599 $this->assertEquals( $old, $this->db->tablePrefix( 'xxx' ) );
600 $this->assertEquals( 'xxx', $this->db->tablePrefix(), "Prefix set" );
601 $this->db->tablePrefix( $old );
602 $this->assertNotEquals( 'xxx', $this->db->tablePrefix() );
603
604 $old = $this->db->dbSchema();
605 $this->assertInternalType( 'string', $old, 'Schema is string' );
606 $this->assertEquals( $old, $this->db->dbSchema(), "Schema unchanged" );
607 $this->assertEquals( $old, $this->db->dbSchema( 'xxx' ) );
608 $this->assertEquals( 'xxx', $this->db->dbSchema(), "Schema set" );
609 $this->db->dbSchema( $old );
610 $this->assertNotEquals( 'xxx', $this->db->dbSchema() );
611 }
612
613}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Helper for testing the methods from the Database class.
testTransactionPreCommitOrIdle_TRX()
Wikimedia\Rdbms\Database::onTransactionPreCommitOrIdle Wikimedia\Rdbms\Database::runOnTransactionPreC...
badLockingMethodImplicit(IDatabase $db)
testTransactionIdle()
Wikimedia\Rdbms\Database::onTransactionIdle Wikimedia\Rdbms\Database::runOnTransactionIdleCallbacks.
badLockingMethodExplicit(IDatabase $db)
testTableName( $expected, $table, $format, array $alias=null)
provideTableName Wikimedia\Rdbms\Database::tableName
provideTableNamesWithIndexClauseOrJOIN()
testTransactionListener()
Wikimedia\Rdbms\Database::setTransactionListener.
testMutators()
Wikimedia\Rdbms\Database::tablePrefix Wikimedia\Rdbms\Database::dbSchema.
testFlagSetting()
Wikimedia\Rdbms\Database::getFlag Wikimedia\Rdbms\Database::setFlag Wikimedia\Rdbms\Database::restore...
testTableNamesWithIndexClauseOrJOIN( $tables, $join_conds, $expect)
provideTableNamesWithIndexClauseOrJOIN Wikimedia\Rdbms\Database::tableNamesWithIndexClauseOrJOIN
testGetScopedLock()
Wikimedia\Rdbms\Database::getScopedLockAndFlush Wikimedia\Rdbms\Database::lock Wikimedia\Rdbms\Databa...
static provideAddQuotes()
testFlushSnapshot()
Wikimedia\Rdbms\Database::flushSnapshot.
testTransactionResolution()
Wikimedia\Rdbms\Database::onTransactionResolution Wikimedia\Rdbms\Database::runOnTransactionIdleCallb...
static provideTableName()
testTransactionPreCommitOrIdle()
Wikimedia\Rdbms\Database::onTransactionPreCommitOrIdle Wikimedia\Rdbms\Database::runOnTransactionPreC...
testDBOIgnoreClear()
UnexpectedValueException Wikimedia\Rdbms\Database::clearFlag.
testAddQuotes( $input, $expected)
provideAddQuotes Wikimedia\Rdbms\Database::addQuotes
getMockDB( $methods=[])
Use this mock instead of DatabaseTestHelper for cases where DatabaseTestHelper is too inflexibile due...
testDBOIgnoreSet()
UnexpectedValueException Wikimedia\Rdbms\Database::setFlag.
testTransactionIdle_TRX()
Wikimedia\Rdbms\Database::onTransactionIdle Wikimedia\Rdbms\Database::runOnTransactionIdleCallbacks.
testFactory()
provideAddQuotes Wikimedia\Rdbms\Database::factory
Database abstraction object for PHP extension mysqli.
Relational database abstraction object.
Definition Database.php:48
An LBFactory class that always returns a single database object.
Helper class that detects high-contention DB queries via profiling calls.
the array() calling protocol came about after MediaWiki 1.4rc1.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1015
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
returning false will NOT prevent logging $e
Definition hooks.txt:2176
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
query( $sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
getScopedLockAndFlush( $lockKey, $fname, $timeout)
Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
begin( $fname=__METHOD__, $mode=self::TRANSACTION_EXPLICIT)
Begin a transaction.
if(is_array($mode)) switch( $mode) $input
const DBO_SSL
Definition defines.php:17
const DBO_TRX
Definition defines.php:12