Debian Codegraph @

tests/phpunit/unit/includes/libs/rdbms/database/DoctrineSchemaChangeBuilderTest.php

raw symbols SCIP
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 * @dataProvider provideTestGetResultAllTables
16 * @covers \Wikimedia\Rdbms\DoctrineSchemaBuilder
17 *
18 * @param AbstractPlatform $platform
19 * @param string $expectedFile path fragment
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 // sqlite hacks
30 if ( $platform instanceof SqlitePlatform ) {
31 // Doctrine prepends __temp__ to the table name and we set the table with
32 // the schema prefix causing invalid sqlite.
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 }