File: DoctrineSchemaChangeBuilderTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (57 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace Wikimedia\Tests\Rdbms;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use MediaWikiUnitTestCase;
use Wikimedia\Rdbms\DoctrineSchemaChangeBuilder;
use Wikimedia\Rdbms\MWPostgreSqlPlatform;

class DoctrineSchemaChangeBuilderTest extends MediaWikiUnitTestCase {

	/**
	 * @dataProvider provideTestGetResultAllTables
	 * @covers \Wikimedia\Rdbms\DoctrineSchemaBuilder
	 *
	 * @param AbstractPlatform $platform
	 * @param string $expectedFile path fragment
	 */
	public function testGetResultAllTables( $platform, $expectedFile ) {
		$basePath = dirname( __DIR__, 5 );
		$builder = new DoctrineSchemaChangeBuilder( $platform );
		$json = file_get_contents( $basePath . '/data/db/patch-drop-ct_tag.json' );
		$schemaChange = json_decode( $json, true );

		$actual = implode( ";\n", $builder->getSchemaChangeSql( $schemaChange ) ) . ";\n";

		// sqlite hacks
		if ( $platform instanceof SqlitePlatform ) {
			// Doctrine prepends __temp__ to the table name and we set the table with
			// the schema prefix causing invalid sqlite.
			$actual = preg_replace( '/__temp__\s*\/\*_\*\//', '/*_*/__temp__', $actual );
		}

		$expected = file_get_contents( $basePath . $expectedFile );

		$this->assertSame( $expected, $actual );
	}

	public static function provideTestGetResultAllTables() {
		yield 'MySQL schema tables' => [
			new MySQLPlatform,
			'/data/db/mysql/patch-drop-ct_tag.sql'
		];

		yield 'PostgreSQL schema tables' => [
			new MWPostgreSqlPlatform,
			'/data/db/postgres/patch-drop-ct_tag.sql'
		];

		yield 'SQLite schema tables' => [
			new SqlitePlatform,
			'/data/db/sqlite/patch-drop-ct_tag.sql'
		];
	}
}