Add options and join conds to MediaWikiTestCase::assertSelect
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 5 Jan 2018 16:26:56 +0000 (11:26 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Fri, 5 Jan 2018 16:27:40 +0000 (11:27 -0500)
Because selects sometimes need to specify these.

Change-Id: I853e8210bbafe16a62060b9075384afb9cdb03c0

tests/phpunit/MediaWikiTestCase.php

index d542826..5c27fa1 100644 (file)
@@ -1482,13 +1482,17 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         * @param string|array $fields The columns to include in the result (and to sort by)
         * @param string|array $condition "where" condition(s)
         * @param array $expectedRows An array of arrays giving the expected rows.
+        * @param array $options Options for the query
+        * @param array $join_conds Join conditions for the query
         *
         * @throws MWException If this test cases's needsDB() method doesn't return true.
         *         Test cases can use "@group Database" to enable database test support,
         *         or list the tables under testing in $this->tablesUsed, or override the
         *         needsDB() method.
         */
-       protected function assertSelect( $table, $fields, $condition, array $expectedRows ) {
+       protected function assertSelect(
+               $table, $fields, $condition, array $expectedRows, array $options = [], array $join_conds = []
+       ) {
                if ( !$this->needsDB() ) {
                        throw new MWException( 'When testing database state, the test cases\'s needDB()' .
                                ' method should return true. Use @group Database or $this->tablesUsed.' );
@@ -1496,7 +1500,14 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                $db = wfGetDB( DB_REPLICA );
 
-               $res = $db->select( $table, $fields, $condition, wfGetCaller(), [ 'ORDER BY' => $fields ] );
+               $res = $db->select(
+                       $table,
+                       $fields,
+                       $condition,
+                       wfGetCaller(),
+                       $options + [ 'ORDER BY' => $fields ],
+                       $join_conds
+               );
                $this->assertNotEmpty( $res, "query failed: " . $db->lastError() );
 
                $i = 0;