Debian Codegraph @

tests/phpunit/includes/installer/DatabaseUpdaterTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Installer;
4
5 use MediaWiki\Installer\DatabaseUpdater;
6 use MediaWikiIntegrationTestCase;
7
8 /**
9 * @covers \MediaWiki\Installer\DatabaseUpdater
10 * @group Database
11 */
12 class DatabaseUpdaterTest extends MediaWikiIntegrationTestCase {
13 /** @dataProvider provideUpdateRowExists */
14 public function testUpdateRowExists( $key, $expectedReturnValue ) {
15 // Add a testing row to the updatelog table to test lookup
16 $this->getDb()->newInsertQueryBuilder()
17 ->insertInto( 'updatelog' )
18 ->row( [ 'ul_key' => 'test', 'ul_value' => null ] )
19 ->caller( __METHOD__ )
20 ->execute();
21 // Call the method under test
22 $objectUnderTest = DatabaseUpdater::newForDB(
23 $this->getServiceContainer()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_PRIMARY )
24 );
25 $this->assertSame( $expectedReturnValue, $objectUnderTest->updateRowExists( $key ) );
26 }
27
28 public static function provideUpdateRowExists() {
29 return [
30 'Key is present in updatelog table' => [ 'test', true ],
31 'Key is not present in updatelog table' => [ 'testing', false ],
32 ];
33 }
34
35 /** @dataProvider provideInsertUpdateRow */
36 public function testInsertUpdateRow( $key, $val ) {
37 // Call the method under test
38 $objectUnderTest = DatabaseUpdater::newForDB(
39 $this->getServiceContainer()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_PRIMARY )
40 );
41 $objectUnderTest->insertUpdateRow( $key, $val );
42 // Expect that the updatelog contains the expected row
43 $this->newSelectQueryBuilder()
44 ->select( [ 'ul_key', 'ul_value' ] )
45 ->from( 'updatelog' )
46 ->caller( __METHOD__ )
47 ->assertRowValue( [ $key, $val ] );
48 }
49
50 public static function provideInsertUpdateRow() {
51 return [
52 'Value is not null' => [ 'test', 'test' ],
53 'Value is null' => [ 'testing', null ],
54 ];
55 }
56 }