Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4106498
MwSqlTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
MwSqlTest.php
View Options
<?php
namespace
MediaWiki\Tests\Maintenance
;
use
MwSql
;
/**
* @covers \MwSql
* @group Database
* @author Dreamy Jazz
*/
class
MwSqlTest
extends
MaintenanceBaseTestCase
{
protected
function
getMaintenanceClass
()
{
return
MwSql
::
class
;
}
public
function
testExecuteForSelectQueryProvidedViaQueryOption
()
{
// Add a testing row to the updatelog table, which we will use the maintenance script to read back.
$this
->
getDb
()->
newInsertQueryBuilder
()
->
insertInto
(
'updatelog'
)
->
row
(
[
'ul_key'
=>
'testing'
,
'ul_value'
=>
'testing-value-12345'
]
)
->
caller
(
__METHOD__
)
->
execute
();
// Output JSON to make it easier to assert that the script worked.
$this
->
maintenance
->
setOption
(
'json'
,
1
);
// Specify the query using the 'query' option to avoid needing to write to STDIN.
$this
->
maintenance
->
setOption
(
'query'
,
$this
->
newSelectQueryBuilder
()
->
field
(
'ul_value'
)
->
from
(
'updatelog'
)
->
where
(
[
'ul_key'
=>
'testing'
]
)
->
caller
(
__METHOD__
)
->
getSQL
()
);
$this
->
maintenance
->
execute
();
$this
->
assertArrayEquals
(
[
[
'ul_value'
=>
'testing-value-12345'
]
],
json_decode
(
$this
->
getActualOutputForAssertion
(),
true
),
true
,
true
,
'JSON output was not as expected.'
);
}
public
function
testExecuteForSelectQueryProvidedViaSQLFile
()
{
// Add a testing row to the updatelog table, which we will use the maintenance script to read back.
$this
->
getDb
()->
newInsertQueryBuilder
()
->
insertInto
(
'updatelog'
)
->
row
(
[
'ul_key'
=>
'testing'
,
'ul_value'
=>
'testing-value-12345'
]
)
->
caller
(
__METHOD__
)
->
execute
();
// Output JSON to make it easier to assert that the script worked.
$this
->
maintenance
->
setOption
(
'json'
,
1
);
// Specify the query using the 'query' option to avoid needing to write to STDIN.
$file
=
$this
->
getNewTempFile
();
file_put_contents
(
$file
,
$this
->
newSelectQueryBuilder
()
->
field
(
'ul_value'
)
->
from
(
'updatelog'
)
->
where
(
[
'ul_key'
=>
'testing'
]
)
->
caller
(
__METHOD__
)
->
getSQL
()
);
$this
->
maintenance
->
setArg
(
0
,
$file
);
$this
->
maintenance
->
execute
();
$this
->
assertArrayEquals
(
[
[
'ul_value'
=>
'testing-value-12345'
]
],
json_decode
(
$this
->
getActualOutputForAssertion
(),
true
),
true
,
true
,
'JSON output was not as expected.'
);
}
public
function
testExecuteForUnconfiguredReplicaDB
()
{
$this
->
expectCallToFatalError
();
$this
->
expectOutputRegex
(
'/No replica DB server.*abceftest/'
);
// Specify the query using the 'query' option with a query that should fail.
$this
->
maintenance
->
setOption
(
'query'
,
$this
->
newSelectQueryBuilder
()
->
field
(
'abcdef'
)
->
from
(
'updatelog'
)
->
where
(
[
'ul_key'
=>
'testing'
]
)
->
caller
(
__METHOD__
)
->
getSQL
()
);
$this
->
maintenance
->
setOption
(
'replicadb'
,
'abceftest'
);
$this
->
maintenance
->
execute
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 19:35 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
5f/fe/1ab544938a0fa8c20a9a43326616
Default Alt Text
MwSqlTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment