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