* Test the generated table for each platform * Use the handy dirname() function instead of full raw string path Bug: T191231 Depends-On: If344395615087c360597a5b3d66ea03e930b7d9b Change-Id: I936c5d10924a46743c7f76df8526105eec7ff48d
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
|
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
|
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
|
use Wikimedia\Rdbms\DoctrineSchemaBuilder;
|
|
use Wikimedia\Rdbms\MWPostgreSqlPlatform;
|
|
|
|
class DoctrineSchemaBuilderTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
/**
|
|
* @dataProvider provideTestGetResultAllTables
|
|
* @covers \Wikimedia\Rdbms\DoctrineSchemaBuilder
|
|
*
|
|
* @param AbstractPlatform $platform
|
|
* @param string $expectedFile path fragment
|
|
*/
|
|
public function testGetResultAllTables( $platform, $expectedFile ) {
|
|
$basePath = dirname( __DIR__, 4 );
|
|
$builder = new DoctrineSchemaBuilder( $platform );
|
|
$json = file_get_contents( $basePath . '/data/db/tables.json' );
|
|
$tables = json_decode( $json, true );
|
|
|
|
foreach ( $tables as $table ) {
|
|
$builder->addTable( $table );
|
|
}
|
|
|
|
$actual = implode( "\n", $builder->getSql() );
|
|
$actual = preg_replace( "/\s*?(\n|$)/m", "", $actual );
|
|
|
|
$expected = file_get_contents( $basePath . $expectedFile );
|
|
$expected = preg_replace( "/\s*?(\n|$)/m", "", $expected );
|
|
|
|
$this->assertSame( $expected, $actual );
|
|
}
|
|
|
|
public function provideTestGetResultAllTables() {
|
|
yield 'MySQL schema tables' => [
|
|
new MySqlPlatform,
|
|
'/data/db/mysql/tables.sql',
|
|
];
|
|
|
|
yield 'PostgreSQL schema tables' => [
|
|
new MWPostgreSqlPlatform,
|
|
'/data/db/postgres/tables.sql'
|
|
];
|
|
|
|
yield 'SQLite schema tables' => [
|
|
new SqlitePlatform,
|
|
'/data/db/sqlite/tables.sql'
|
|
];
|
|
}
|
|
}
|