wiki.techinc.nl/tests/phpunit/structure/DatabaseIntegrationTest.php
Tim Starling b9907ca9b6 Remove DatabaseIntegrationTest::testStoredFunctions()
As was pointed out in CR on the original change from December 2011, the
test requires elevated privileges when it is run against a database with
binlogging enabled, which is a nuisance when I'm trying to test replication-
related code. The author commented that the test was to support GeoData,
but that was only true until the "schema revamp" of February 2012.

I considered mocking the database and making it into a test of
streamStatementEnd, since that code was introduced at the same time, but
we already have DatabaseMysqlBaseTest::testStreamStatementEnd().

I also removed the restoreFlags() call since that was apparently left
over from testFlagSetting(), which has been moved to DatabaseTest.

Refs:

* https://www.mediawiki.org/wiki/Special:Code/MediaWiki/107376
* https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108603
* https://www.mediawiki.org/wiki/Special:Code/MediaWiki/110649
* 67f08d6990

Change-Id: I1a6b9d0cd91c8539ac1080a423b519743088733e
2020-06-02 10:47:29 +10:00

57 lines
1.3 KiB
PHP

<?php
use Wikimedia\Rdbms\Database;
/**
* @group Database
*/
class DatabaseIntegrationTest extends MediaWikiTestCase {
/**
* @var Database
*/
protected $db;
protected function setUp() : void {
parent::setUp();
$this->db = wfGetDB( DB_MASTER );
}
public function testUnknownTableCorruptsResults() {
$res = $this->db->select( 'page', '*', [ 'page_id' => 1 ] );
$this->assertFalse( $this->db->tableExists( 'foobarbaz' ) );
$this->assertIsInt( $res->numRows() );
}
public function automaticSqlGenerationParams() {
return [
[ 'mysql' ],
[ 'sqlite' ],
[ 'postgres' ],
];
}
/**
* @dataProvider automaticSqlGenerationParams
*/
public function testAutomaticSqlGeneration( $type ) {
global $IP;
$abstractSchemaPath = "$IP/maintenance/tables.json";
if ( $type === 'mysql' ) {
$oldPath = "$IP/maintenance/tables-generated.sql";
} else {
$oldPath = "$IP/maintenance/$type/tables-generated.sql";
}
$oldContent = file_get_contents( $oldPath );
$newPath = $this->getNewTempFile();
$maintenanceScript = new GenerateSchemaSql();
$maintenanceScript->loadWithArgv(
[ '--json=' . $abstractSchemaPath, '--sql=' . $newPath, '--type=' . $type ]
);
$maintenanceScript->execute();
$this->assertEquals(
$oldContent,
file_get_contents( $newPath ),
"The generated schema in '$type' type has to be the same"
);
}
}