Debian Codegraph @

tests/phpunit/structure/AbstractSchemaValidationTest.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 * http://www.gnu.org/copyleft/gpl.html
17 */
18
19 use MediaWiki\DB\AbstractSchemaValidationError;
20 use MediaWiki\DB\AbstractSchemaValidator;
21
22 /**
23 * Validates all abstract schemas against the abstract-schema schemas in the docs/ folder.
24 * @coversNothing
25 */
26 class AbstractSchemaValidationTest extends PHPUnit\Framework\TestCase {
27 use MediaWikiCoversValidator;
28
29 /**
30 * @var AbstractSchemaValidator
31 */
32 protected $validator;
33
34 protected function setUp(): void {
35 parent::setUp();
36
37 $this->validator = new AbstractSchemaValidator( [ $this, 'markTestSkipped' ] );
38 $this->validator->checkDependencies();
39 }
40
41 public static function provideSchemas(): Generator {
42 yield 'maintenance/tables.json' => [ __DIR__ . '/../../../maintenance/tables.json' ];
43
44 foreach ( glob( __DIR__ . '/../../../maintenance/abstractSchemaChanges/*.json' ) as $schemaChange ) {
45 $fileName = pathinfo( $schemaChange, PATHINFO_BASENAME );
46
47 yield $fileName => [ $schemaChange ];
48 }
49 }
50
51 /**
52 * @dataProvider provideSchemas
53 * @param string $path Path to tables.json file
54 */
55 public function testSchemasPassValidation( string $path ): void {
56 try {
57 $this->validator->validate( $path );
58 // All good
59 $this->assertTrue( true );
60 } catch ( AbstractSchemaValidationError $e ) {
61 $this->fail( $e->getMessage() );
62 }
63 }
64 }