MediaWiki REL1_30
DatabaseTestHelper.php
Go to the documentation of this file.
1<?php
2
5
10class DatabaseTestHelper extends Database {
11
16 protected $testName = [];
17
23 protected $lastSqls = [];
24
26 protected $nextResult = [];
27
32 protected $tablesExists;
33
38
39 public function __construct( $testName, array $opts = [] ) {
40 $this->testName = $testName;
41
42 $this->profiler = new ProfilerStub( [] );
43 $this->trxProfiler = new TransactionProfiler();
44 $this->cliMode = isset( $opts['cliMode'] ) ? $opts['cliMode'] : true;
45 $this->connLogger = new \Psr\Log\NullLogger();
46 $this->queryLogger = new \Psr\Log\NullLogger();
47 $this->errorLogger = function ( Exception $e ) {
48 wfWarn( get_class( $e ) . ": {$e->getMessage()}" );
49 };
50 $this->currentDomain = DatabaseDomain::newUnspecified();
51 }
52
58 public function getLastSqls() {
59 $lastSqls = implode( '; ', $this->lastSqls );
60 $this->lastSqls = [];
61
62 return $lastSqls;
63 }
64
65 public function setExistingTables( $tablesExists ) {
66 $this->tablesExists = (array)$tablesExists;
67 }
68
72 public function forceNextResult( $res ) {
73 $this->nextResult = $res;
74 }
75
76 protected function addSql( $sql ) {
77 // clean up spaces before and after some words and the whole string
78 $this->lastSqls[] = trim( preg_replace(
79 '/\s{2,}(?=FROM|WHERE|GROUP BY|ORDER BY|LIMIT)|(?<=SELECT|INSERT|UPDATE)\s{2,}/',
80 ' ', $sql
81 ) );
82 }
83
84 protected function checkFunctionName( $fname ) {
85 if ( substr( $fname, 0, strlen( $this->testName ) ) !== $this->testName ) {
86 throw new MWException( 'function name does not start with test class. ' .
87 $fname . ' vs. ' . $this->testName . '. ' .
88 'Please provide __METHOD__ to database methods.' );
89 }
90 }
91
92 function strencode( $s ) {
93 // Choose apos to avoid handling of escaping double quotes in quoted text
94 return str_replace( "'", "\'", $s );
95 }
96
97 public function addIdentifierQuotes( $s ) {
98 // no escaping to avoid handling of double quotes in quoted text
99 return $s;
100 }
101
102 public function query( $sql, $fname = '', $tempIgnore = false ) {
103 $this->checkFunctionName( $fname );
104 $this->addSql( $sql );
105
106 return parent::query( $sql, $fname, $tempIgnore );
107 }
108
109 public function tableExists( $table, $fname = __METHOD__ ) {
110 $tableRaw = $this->tableName( $table, 'raw' );
111 if ( isset( $this->mSessionTempTables[$tableRaw] ) ) {
112 return true; // already known to exist
113 }
114
115 $this->checkFunctionName( $fname );
116
117 return in_array( $table, (array)$this->tablesExists );
118 }
119
120 // Redeclare parent method to make it public
121 public function nativeReplace( $table, $rows, $fname ) {
122 return parent::nativeReplace( $table, $rows, $fname );
123 }
124
125 function getType() {
126 return 'test';
127 }
128
129 function open( $server, $user, $password, $dbName ) {
130 return false;
131 }
132
133 function fetchObject( $res ) {
134 return false;
135 }
136
137 function fetchRow( $res ) {
138 return false;
139 }
140
141 function numRows( $res ) {
142 return -1;
143 }
144
145 function numFields( $res ) {
146 return -1;
147 }
148
149 function fieldName( $res, $n ) {
150 return 'test';
151 }
152
153 function insertId() {
154 return -1;
155 }
156
157 function dataSeek( $res, $row ) {
158 /* nop */
159 }
160
161 function lastErrno() {
162 return -1;
163 }
164
165 function lastError() {
166 return 'test';
167 }
168
169 function fieldInfo( $table, $field ) {
170 return false;
171 }
172
173 function indexInfo( $table, $index, $fname = 'Database::indexInfo' ) {
174 return false;
175 }
176
177 function affectedRows() {
178 return -1;
179 }
180
181 function getSoftwareLink() {
182 return 'test';
183 }
184
185 function getServerVersion() {
186 return 'test';
187 }
188
189 function getServerInfo() {
190 return 'test';
191 }
192
193 function isOpen() {
194 return true;
195 }
196
197 function ping( &$rtt = null ) {
198 $rtt = 0.0;
199 return true;
200 }
201
202 protected function closeConnection() {
203 return false;
204 }
205
206 protected function doQuery( $sql ) {
208 $this->nextResult = [];
209
210 return new FakeResultWrapper( $res );
211 }
212
216
217 public function setUnionSupportsOrderAndLimit( $v ) {
218 $this->unionSupportsOrderAndLimit = (bool)$v;
219 }
220}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition Setup.php:36
Helper for testing the methods from the Database class.
array $nextResult
List of row arrays.
indexInfo( $table, $index, $fname='Database::indexInfo')
nativeReplace( $table, $rows, $fname)
setExistingTables( $tablesExists)
query( $sql, $fname='', $tempIgnore=false)
__construct( $testName, array $opts=[])
getLastSqls()
Returns SQL queries grouped by '; ' Clear the list of queries that have been done so far.
tableExists( $table, $fname=__METHOD__)
$unionSupportsOrderAndLimit
Value to return from unionSupportsOrderAndLimit()
$testName
CLASS of the test suite, used to determine, if the function name is passed every time to query()
open( $server, $user, $password, $dbName)
$tablesExists
Array of tables to be considered as existing by tableExist() Use setExistingTables() to alter.
fieldInfo( $table, $field)
$lastSqls
Array of lastSqls passed to query(), This is an array since some methods in Database can do more than...
MediaWiki exception.
Stub profiler that does nothing.
Class to handle database/prefix specification for IDatabase domains.
Helper class that detects high-contention DB queries via profiling calls.
$res
Definition database.txt:21
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for tableName() and addQuotes(). You will need both of them. ------------------------------------------------------------------------ Basic query optimisation ------------------------------------------------------------------------ MediaWiki developers who need to write DB queries should have some understanding of databases and the performance issues associated with them. Patches containing unacceptably slow features will not be accepted. Unindexed queries are generally not welcome in MediaWiki
the array() calling protocol came about after MediaWiki 1.4rc1.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition hooks.txt:2746
returning false will NOT prevent logging $e
Definition hooks.txt:2146
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