Make cache object mandatory for MessageCache
[mediawiki.git] / tests / phpunit / includes / installer / DatabaseUpdaterTest.php
blob2a75cf402010f64f0f3ea60e134a358ac70a6fa9
1 <?php
3 class DatabaseUpdaterTest extends MediaWikiTestCase {
5 public function testSetAppliedUpdates() {
6 $db = new FakeDatabase();
7 $dbu = new FakeDatabaseUpdater( $db );
8 $dbu->setAppliedUpdates( "test", [] );
9 $expected = "updatelist-test-" . time() . "0";
10 $actual = $db->lastInsertData['ul_key'];
11 $this->assertEquals( $expected, $actual, var_export( $db->lastInsertData, true ) );
12 $dbu->setAppliedUpdates( "test", [] );
13 $expected = "updatelist-test-" . time() . "1";
14 $actual = $db->lastInsertData['ul_key'];
15 $this->assertEquals( $expected, $actual, var_export( $db->lastInsertData, true ) );
19 class FakeDatabase extends Database {
20 public $lastInsertTable;
21 public $lastInsertData;
23 function __construct() {
24 $this->cliMode = true;
25 $this->connLogger = new \Psr\Log\NullLogger();
26 $this->queryLogger = new \Psr\Log\NullLogger();
27 $this->errorLogger = function ( Exception $e ) {
28 wfWarn( get_class( $e ) . ": {$e->getMessage()}" );
30 $this->currentDomain = DatabaseDomain::newUnspecified();
33 function clearFlag( $arg, $remember = self::REMEMBER_NOTHING ) {
36 function setFlag( $arg, $remember = self::REMEMBER_NOTHING ) {
39 public function insert( $table, $a, $fname = __METHOD__, $options = [] ) {
40 $this->lastInsertTable = $table;
41 $this->lastInsertData = $a;
44 /**
45 * Get the type of the DBMS, as it appears in $wgDBtype.
47 * @return string
49 function getType() {
50 // TODO: Implement getType() method.
53 /**
54 * Open a connection to the database. Usually aborts on failure
56 * @param string $server Database server host
57 * @param string $user Database user name
58 * @param string $password Database user password
59 * @param string $dbName Database name
60 * @return bool
61 * @throws DBConnectionError
63 function open( $server, $user, $password, $dbName ) {
64 // TODO: Implement open() method.
67 /**
68 * Fetch the next row from the given result object, in object form.
69 * Fields can be retrieved with $row->fieldname, with fields acting like
70 * member variables.
71 * If no more rows are available, false is returned.
73 * @param ResultWrapper|stdClass $res Object as returned from Database::query(), etc.
74 * @return stdClass|bool
75 * @throws DBUnexpectedError Thrown if the database returns an error
77 function fetchObject( $res ) {
78 // TODO: Implement fetchObject() method.
81 /**
82 * Fetch the next row from the given result object, in associative array
83 * form. Fields are retrieved with $row['fieldname'].
84 * If no more rows are available, false is returned.
86 * @param ResultWrapper $res Result object as returned from Database::query(), etc.
87 * @return array|bool
88 * @throws DBUnexpectedError Thrown if the database returns an error
90 function fetchRow( $res ) {
91 // TODO: Implement fetchRow() method.
94 /**
95 * Get the number of rows in a result object
97 * @param mixed $res A SQL result
98 * @return int
100 function numRows( $res ) {
101 // TODO: Implement numRows() method.
105 * Get the number of fields in a result object
106 * @see https://secure.php.net/mysql_num_fields
108 * @param mixed $res A SQL result
109 * @return int
111 function numFields( $res ) {
112 // TODO: Implement numFields() method.
116 * Get a field name in a result object
117 * @see https://secure.php.net/mysql_field_name
119 * @param mixed $res A SQL result
120 * @param int $n
121 * @return string
123 function fieldName( $res, $n ) {
124 // TODO: Implement fieldName() method.
128 * Get the inserted value of an auto-increment row
130 * The value inserted should be fetched from nextSequenceValue()
132 * Example:
133 * $id = $dbw->nextSequenceValue( 'page_page_id_seq' );
134 * $dbw->insert( 'page', [ 'page_id' => $id ] );
135 * $id = $dbw->insertId();
137 * @return int
139 function insertId() {
140 // TODO: Implement insertId() method.
144 * Change the position of the cursor in a result object
145 * @see https://secure.php.net/mysql_data_seek
147 * @param mixed $res A SQL result
148 * @param int $row
150 function dataSeek( $res, $row ) {
151 // TODO: Implement dataSeek() method.
155 * Get the last error number
156 * @see https://secure.php.net/mysql_errno
158 * @return int
160 function lastErrno() {
161 // TODO: Implement lastErrno() method.
165 * Get a description of the last error
166 * @see https://secure.php.net/mysql_error
168 * @return string
170 function lastError() {
171 // TODO: Implement lastError() method.
175 * mysql_fetch_field() wrapper
176 * Returns false if the field doesn't exist
178 * @param string $table Table name
179 * @param string $field Field name
181 * @return Field
183 function fieldInfo( $table, $field ) {
184 // TODO: Implement fieldInfo() method.
188 * Get information about an index into an object
189 * @param string $table Table name
190 * @param string $index Index name
191 * @param string $fname Calling function name
192 * @return mixed Database-specific index description class or false if the index does not exist
194 function indexInfo( $table, $index, $fname = __METHOD__ ) {
195 // TODO: Implement indexInfo() method.
199 * Get the number of rows affected by the last write query
200 * @see https://secure.php.net/mysql_affected_rows
202 * @return int
204 function affectedRows() {
205 // TODO: Implement affectedRows() method.
209 * Wrapper for addslashes()
211 * @param string $s String to be slashed.
212 * @return string Slashed string.
214 function strencode( $s ) {
215 // TODO: Implement strencode() method.
219 * Returns a wikitext link to the DB's website, e.g.,
220 * return "[https://www.mysql.com/ MySQL]";
221 * Should at least contain plain text, if for some reason
222 * your database has no website.
224 * @return string Wikitext of a link to the server software's web site
226 function getSoftwareLink() {
227 // TODO: Implement getSoftwareLink() method.
231 * A string describing the current software version, like from
232 * mysql_get_server_info().
234 * @return string Version information from the database server.
236 function getServerVersion() {
237 // TODO: Implement getServerVersion() method.
241 * Closes underlying database connection
242 * @since 1.20
243 * @return bool Whether connection was closed successfully
245 protected function closeConnection() {
246 // TODO: Implement closeConnection() method.
250 * The DBMS-dependent part of query()
252 * @param string $sql SQL query.
253 * @return ResultWrapper|bool Result object to feed to fetchObject,
254 * fetchRow, ...; or false on failure
256 protected function doQuery( $sql ) {
257 // TODO: Implement doQuery() method.
261 class FakeDatabaseUpdater extends DatabaseUpdater {
262 function __construct( $db ) {
263 $this->db = $db;
264 self::$updateCounter = 0;
268 * Get an array of updates to perform on the database. Should return a
269 * multi-dimensional array. The main key is the MediaWiki version (1.12,
270 * 1.13...) with the values being arrays of updates, identical to how
271 * updaters.inc did it (for now)
273 * @return array
275 protected function getCoreUpdateList() {
276 return [];
279 public function canUseNewUpdatelog() {
280 return true;
283 public function setAppliedUpdates( $version, $updates = [] ) {
284 parent::setAppliedUpdates( $version, $updates );