Debian Codegraph @

tests/phpunit/unit/includes/db/AbstractSchemaValidatorTest.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 */
18
19 use MediaWiki\DB\AbstractSchemaValidationError;
20 use MediaWiki\DB\AbstractSchemaValidator;
21
22 /**
23 * @covers \MediaWiki\DB\AbstractSchemaValidator
24 */
25 class AbstractSchemaValidatorTest extends MediaWikiUnitTestCase {
26
27 /**
28 * @dataProvider provideValidate
29 * @param string $file
30 * @param string|true $expected
31 */
32 public function testValidate( string $file, $expected ): void {
33 // If a dependency is missing, skip this test.
34 $validator = new AbstractSchemaValidator( function ( $msg ) {
35 $this->markTestSkipped( $msg );
36 } );
37
38 if ( is_string( $expected ) ) {
39 $this->expectException( AbstractSchemaValidationError::class );
40 $this->expectExceptionMessage( $expected );
41 }
42
43 $dir = __DIR__ . '/../../../data/db/';
44 $this->assertSame(
45 $expected,
46 $validator->validate( $dir . $file )
47 );
48 }
49
50 public static function provideValidate(): array {
51 return [
52 [
53 'tables.json',
54 true
55 ],
56 [
57 'patch-drop-ct_tag.json',
58 true
59 ],
60 [
61 'notschema.txt',
62 'notschema.txt is not valid JSON'
63 ]
64 ];
65 }
66 }