3 namespace MediaWiki\Tests\Maintenance
;
12 class MwSqlTest
extends MaintenanceBaseTestCase
{
14 protected function getMaintenanceClass() {
18 public function testExecuteForSelectQueryProvidedViaQueryOption() {
19 // Add a testing row to the updatelog table, which we will use the maintenance script to read back.
20 $this->getDb()->newInsertQueryBuilder()
21 ->insertInto( 'updatelog' )
22 ->row( [ 'ul_key' => 'testing', 'ul_value' => 'testing-value-12345' ] )
23 ->caller( __METHOD__
)
25 // Output JSON to make it easier to assert that the script worked.
26 $this->maintenance
->setOption( 'json', 1 );
27 // Specify the query using the 'query' option to avoid needing to write to STDIN.
28 $this->maintenance
->setOption(
30 $this->newSelectQueryBuilder()
33 ->where( [ 'ul_key' => 'testing' ] )
34 ->caller( __METHOD__
)
37 $this->maintenance
->execute();
38 $this->assertArrayEquals(
39 [ [ 'ul_value' => 'testing-value-12345' ] ],
40 json_decode( $this->getActualOutputForAssertion(), true ),
43 'JSON output was not as expected.'
47 public function testExecuteForSelectQueryProvidedViaSQLFile() {
48 // Add a testing row to the updatelog table, which we will use the maintenance script to read back.
49 $this->getDb()->newInsertQueryBuilder()
50 ->insertInto( 'updatelog' )
51 ->row( [ 'ul_key' => 'testing', 'ul_value' => 'testing-value-12345' ] )
52 ->caller( __METHOD__
)
54 // Output JSON to make it easier to assert that the script worked.
55 $this->maintenance
->setOption( 'json', 1 );
56 // Specify the query using the 'query' option to avoid needing to write to STDIN.
57 $file = $this->getNewTempFile();
60 $this->newSelectQueryBuilder()
63 ->where( [ 'ul_key' => 'testing' ] )
64 ->caller( __METHOD__
)
67 $this->maintenance
->setArg( 0, $file );
68 $this->maintenance
->execute();
69 $this->assertArrayEquals(
70 [ [ 'ul_value' => 'testing-value-12345' ] ],
71 json_decode( $this->getActualOutputForAssertion(), true ),
74 'JSON output was not as expected.'
78 public function testExecuteForUnconfiguredReplicaDB() {
79 $this->expectCallToFatalError();
80 $this->expectOutputRegex( '/No replica DB server.*abceftest/' );
81 // Specify the query using the 'query' option with a query that should fail.
82 $this->maintenance
->setOption(
84 $this->newSelectQueryBuilder()
87 ->where( [ 'ul_key' => 'testing' ] )
88 ->caller( __METHOD__
)
91 $this->maintenance
->setOption( 'replicadb', 'abceftest' );
92 $this->maintenance
->execute();