2017-07-20 20:17:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use Wikimedia\Rdbms\Database;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
|
|
|
|
class DatabaseIntegrationTest extends MediaWikiTestCase {
|
|
|
|
|
/**
|
|
|
|
|
* @var Database
|
|
|
|
|
*/
|
|
|
|
|
protected $db;
|
|
|
|
|
|
2019-10-20 18:11:08 +00:00
|
|
|
protected function setUp() : void {
|
2017-07-20 20:17:11 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
$this->db = wfGetDB( DB_MASTER );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testUnknownTableCorruptsResults() {
|
|
|
|
|
$res = $this->db->select( 'page', '*', [ 'page_id' => 1 ] );
|
|
|
|
|
$this->assertFalse( $this->db->tableExists( 'foobarbaz' ) );
|
2019-12-13 14:29:10 +00:00
|
|
|
$this->assertIsInt( $res->numRows() );
|
2017-07-20 20:17:11 +00:00
|
|
|
}
|
2020-05-15 22:57:27 +00:00
|
|
|
|
|
|
|
|
public function automaticSqlGenerationParams() {
|
|
|
|
|
return [
|
2020-05-18 02:29:18 +00:00
|
|
|
[ 'mysql' ],
|
|
|
|
|
[ 'sqlite' ],
|
|
|
|
|
[ 'postgres' ],
|
2020-05-15 22:57:27 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider automaticSqlGenerationParams
|
|
|
|
|
*/
|
2020-05-18 02:29:18 +00:00
|
|
|
public function testAutomaticSqlGeneration( $type ) {
|
2020-05-15 22:57:27 +00:00
|
|
|
global $IP;
|
|
|
|
|
$abstractSchemaPath = "$IP/maintenance/tables.json";
|
2020-05-18 02:29:18 +00:00
|
|
|
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();
|
2020-05-15 22:57:27 +00:00
|
|
|
$maintenanceScript = new GenerateSchemaSql();
|
|
|
|
|
$maintenanceScript->loadWithArgv(
|
2020-05-18 02:29:18 +00:00
|
|
|
[ '--json=' . $abstractSchemaPath, '--sql=' . $newPath, '--type=' . $type ]
|
2020-05-15 22:57:27 +00:00
|
|
|
);
|
|
|
|
|
$maintenanceScript->execute();
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$oldContent,
|
2020-05-18 02:29:18 +00:00
|
|
|
file_get_contents( $newPath ),
|
2020-05-15 22:57:27 +00:00
|
|
|
"The generated schema in '$type' type has to be the same"
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-07-20 20:17:11 +00:00
|
|
|
}
|