3 use Wikimedia\Rdbms\IDatabase
;
4 use Wikimedia\Rdbms\Database
;
10 class DatabaseIntegrationTest
extends MediaWikiTestCase
{
16 private $functionTest = false;
18 protected function setUp() {
20 $this->db
= wfGetDB( DB_MASTER
);
23 protected function tearDown() {
25 if ( $this->functionTest
) {
26 $this->dropFunctions();
27 $this->functionTest
= false;
29 $this->db
->restoreFlags( IDatabase
::RESTORE_INITIAL
);
32 public function testStoredFunctions() {
33 if ( !in_array( wfGetDB( DB_MASTER
)->getType(), [ 'mysql', 'postgres' ] ) ) {
34 $this->markTestSkipped( 'MySQL or Postgres required' );
37 $this->dropFunctions();
38 $this->functionTest
= true;
40 $this->db
->sourceFile( "$IP/tests/phpunit/data/db/{$this->db->getType()}/functions.sql" )
42 $res = $this->db
->query( 'SELECT mw_test_function() AS test', __METHOD__
);
43 $this->assertEquals( 42, $res->fetchObject()->test
);
46 private function dropFunctions() {
47 $this->db
->query( 'DROP FUNCTION IF EXISTS mw_test_function'
48 . ( $this->db
->getType() == 'postgres' ?
'()' : '' )
52 public function testUnknownTableCorruptsResults() {
53 $res = $this->db
->select( 'page', '*', [ 'page_id' => 1 ] );
54 $this->assertFalse( $this->db
->tableExists( 'foobarbaz' ) );
55 $this->assertInternalType( 'int', $res->numRows() );