3 use Wikimedia\Rdbms\IDatabase
;
4 use Wikimedia\Rdbms\Database
;
9 class DatabaseIntegrationTest
extends MediaWikiTestCase
{
15 private $functionTest = false;
17 protected function setUp() {
19 $this->db
= wfGetDB( DB_MASTER
);
22 protected function tearDown() {
24 if ( $this->functionTest
) {
25 $this->dropFunctions();
26 $this->functionTest
= false;
28 $this->db
->restoreFlags( IDatabase
::RESTORE_INITIAL
);
31 public function testStoredFunctions() {
32 if ( !in_array( wfGetDB( DB_MASTER
)->getType(), [ 'mysql', 'postgres' ] ) ) {
33 $this->markTestSkipped( 'MySQL or Postgres required' );
36 $this->dropFunctions();
37 $this->functionTest
= true;
39 $this->db
->sourceFile( "$IP/tests/phpunit/data/db/{$this->db->getType()}/functions.sql" )
41 $res = $this->db
->query( 'SELECT mw_test_function() AS test', __METHOD__
);
42 $this->assertEquals( 42, $res->fetchObject()->test
);
45 private function dropFunctions() {
46 $this->db
->query( 'DROP FUNCTION IF EXISTS mw_test_function'
47 . ( $this->db
->getType() == 'postgres' ?
'()' : '' )
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() );