MediaWiki
REL1_30
DatabaseIntegrationTest.php
Go to the documentation of this file.
1
<?php
2
3
use
Wikimedia\Rdbms\IDatabase
;
4
use
Wikimedia\Rdbms\Database
;
5
9
class
DatabaseIntegrationTest
extends
MediaWikiTestCase
{
13
protected
$db
;
14
15
private
$functionTest
=
false
;
16
17
protected
function
setUp
() {
18
parent::setUp();
19
$this->db =
wfGetDB
(
DB_MASTER
);
20
}
21
22
protected
function
tearDown
() {
23
parent::tearDown();
24
if
( $this->functionTest ) {
25
$this->
dropFunctions
();
26
$this->functionTest =
false
;
27
}
28
$this->db->restoreFlags( IDatabase::RESTORE_INITIAL );
29
}
30
31
public
function
testStoredFunctions
() {
32
if
( !in_array(
wfGetDB
(
DB_MASTER
)->getType(), [
'mysql'
,
'postgres'
] ) ) {
33
$this->markTestSkipped(
'MySQL or Postgres required'
);
34
}
35
global
$IP
;
36
$this->
dropFunctions
();
37
$this->functionTest =
true
;
38
$this->assertTrue(
39
$this->db->sourceFile(
"$IP/tests/phpunit/data/db/{$this->db->getType()}/functions.sql"
)
40
);
41
$res
= $this->db->query(
'SELECT mw_test_function() AS test'
, __METHOD__ );
42
$this->assertEquals( 42,
$res
->fetchObject()->test );
43
}
44
45
private
function
dropFunctions
() {
46
$this->db->query(
'DROP FUNCTION IF EXISTS mw_test_function'
47
. ( $this->db->getType() ==
'postgres'
?
'()'
:
''
)
48
);
49
}
50
51
public
function
testUnknownTableCorruptsResults
() {
52
$res
= $this->db->select(
'page'
,
'*'
, [
'page_id'
=> 1 ] );
53
$this->assertFalse( $this->db->tableExists(
'foobarbaz'
) );
54
$this->assertInternalType(
'int'
,
$res
->numRows() );
55
}
56
}
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition
GlobalFunctions.php:2857
DatabaseIntegrationTest
Database.
Definition
DatabaseIntegrationTest.php:9
DatabaseIntegrationTest\$db
Database $db
Definition
DatabaseIntegrationTest.php:13
DatabaseIntegrationTest\setUp
setUp()
Definition
DatabaseIntegrationTest.php:17
DatabaseIntegrationTest\testUnknownTableCorruptsResults
testUnknownTableCorruptsResults()
Definition
DatabaseIntegrationTest.php:51
DatabaseIntegrationTest\testStoredFunctions
testStoredFunctions()
Definition
DatabaseIntegrationTest.php:31
DatabaseIntegrationTest\dropFunctions
dropFunctions()
Definition
DatabaseIntegrationTest.php:45
DatabaseIntegrationTest\$functionTest
$functionTest
Definition
DatabaseIntegrationTest.php:15
DatabaseIntegrationTest\tearDown
tearDown()
Definition
DatabaseIntegrationTest.php:22
MediaWikiTestCase
Definition
MediaWikiTestCase.php:15
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition
Database.php:45
$res
$res
Definition
database.txt:21
$IP
$IP
Definition
update.php:3
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition
IDatabase.php:40
DB_MASTER
const DB_MASTER
Definition
defines.php:26
tests
phpunit
structure
DatabaseIntegrationTest.php
Generated on Mon Nov 25 2024 15:44:06 for MediaWiki by
1.10.0