Message: add strict type to protected Message::$language
[mediawiki.git] / tests / phpunit / TestSelectQueryBuilder.php
blob9bac7d5e0ea1f2d6444dcbeb51e3ac8759e9c188
1 <?php
3 use PHPUnit\Framework\Assert;
4 use Wikimedia\Rdbms\SelectQueryBuilder;
6 class TestSelectQueryBuilder extends SelectQueryBuilder {
7 public function fields( $fields ) {
8 $this->orderBy( $fields );
9 return parent::fields( $fields );
12 public function field( $field, $alias = null ) {
13 $this->orderBy( $field );
14 return parent::field( $field, $alias );
17 /**
18 * Asserts that the current database query yields the rows given by $expectedRows.
19 * The expected rows should be given as indexed (not associative) arrays, with
20 * the values given in the order of the columns in the $fields parameter.
21 * Note that the rows are sorted by the columns given in $fields.
23 * @param array $expectedRows
25 public function assertResultSet( $expectedRows ) {
26 $res = $this->fetchResultSet();
28 $i = 0;
30 foreach ( $expectedRows as $expected ) {
31 $r = $res->fetchRow();
32 MediaWikiIntegrationTestCase::stripStringKeys( $r );
34 $i += 1;
35 Assert::assertNotFalse( $r, "row #$i missing" );
37 Assert::assertEquals( $expected, $r, "row #$i mismatches" );
40 $r = $res->fetchRow();
41 MediaWikiIntegrationTestCase::stripStringKeys( $r );
43 Assert::assertFalse( $r, "found extra row (after #$i)" );
46 public function assertEmptyResult() {
47 $res = $this->fetchResultSet();
48 Assert::assertSame( 0, $res->numRows(), "Result set should be empty" );
51 /**
52 * Execute the query, and assert that it returns a single row with a single
53 * field with the given value.
55 * Unlike fetchField(), LIMIT 1 is not automatically added.
57 * @param mixed $expectedValue
59 public function assertFieldValue( $expectedValue ) {
60 $res = $this->fetchResultSet();
61 Assert::assertSame( 1, $res->numRows(),
62 "There should be one row in the result set" );
63 $row = (array)$res->fetchObject();
64 Assert::assertCount( 1, $row,
65 "There should be one field in the result set" );
66 $value = reset( $row );
67 Assert::assertEquals( $expectedValue, $value,
68 "The field value should match" );