MediaWiki REL1_30
DatabaseIntegrationTest.php
Go to the documentation of this file.
1<?php
2
5
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
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( $db, $groups=[], $wiki=false)
Get a Database object.
Relational database abstraction object.
Definition Database.php:45
$res
Definition database.txt:21
$IP
Definition update.php:3
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
const DB_MASTER
Definition defines.php:26