| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\Tests\Rdbms; |
| 4 |
|
| 5 |
use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 6 |
use Doctrine\DBAL\Platforms\MySQLPlatform; |
| 7 |
use Doctrine\DBAL\Platforms\SqlitePlatform; |
| 8 |
use MediaWikiUnitTestCase; |
| 9 |
use Wikimedia\Rdbms\DoctrineSchemaChangeBuilder; |
| 10 |
use Wikimedia\Rdbms\MWPostgreSqlPlatform; |
| 11 |
|
| 12 |
class DoctrineSchemaChangeBuilderTest extends MediaWikiUnitTestCase { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function testGetResultAllTables( $platform, $expectedFile ) { |
| 22 |
$basePath = dirname( __DIR__, 5 ); |
| 23 |
$builder = new DoctrineSchemaChangeBuilder( $platform ); |
| 24 |
$json = file_get_contents( $basePath . '/data/db/patch-drop-ct_tag.json' ); |
| 25 |
$schemaChange = json_decode( $json, true ); |
| 26 |
|
| 27 |
$actual = implode( ";\n", $builder->getSchemaChangeSql( $schemaChange ) ) . ";\n"; |
| 28 |
|
| 29 |
|
| 30 |
if ( $platform instanceof SqlitePlatform ) { |
| 31 |
|
| 32 |
|
| 33 |
$actual = preg_replace( '/__temp__\s*\/\*_\*\//', '/*_*/__temp__', $actual ); |
| 34 |
} |
| 35 |
|
| 36 |
$expected = file_get_contents( $basePath . $expectedFile ); |
| 37 |
|
| 38 |
$this->assertSame( $expected, $actual ); |
| 39 |
} |
| 40 |
|
| 41 |
public static function provideTestGetResultAllTables() { |
| 42 |
yield 'MySQL schema tables' => [ |
| 43 |
new MySQLPlatform, |
| 44 |
'/data/db/mysql/patch-drop-ct_tag.sql' |
| 45 |
]; |
| 46 |
|
| 47 |
yield 'PostgreSQL schema tables' => [ |
| 48 |
new MWPostgreSqlPlatform, |
| 49 |
'/data/db/postgres/patch-drop-ct_tag.sql' |
| 50 |
]; |
| 51 |
|
| 52 |
yield 'SQLite schema tables' => [ |
| 53 |
new SqlitePlatform, |
| 54 |
'/data/db/sqlite/patch-drop-ct_tag.sql' |
| 55 |
]; |
| 56 |
} |
| 57 |
} |