| 1 |
<?php |
| 2 |
|
| 3 |
use PHPUnit\Framework\Assert; |
| 4 |
use Wikimedia\Rdbms\SelectQueryBuilder; |
| 5 |
|
| 6 |
class TestSelectQueryBuilder extends SelectQueryBuilder { |
| 7 |
public function fields( $fields ) { |
| 8 |
$this->orderBy( $fields ); |
| 9 |
return parent::fields( $fields ); |
| 10 |
} |
| 11 |
|
| 12 |
public function field( $field, $alias = null ) { |
| 13 |
$this->orderBy( $field ); |
| 14 |
return parent::field( $field, $alias ); |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public function assertResultSet( $expectedRows ) { |
| 26 |
$res = $this->fetchResultSet(); |
| 27 |
|
| 28 |
$i = 0; |
| 29 |
|
| 30 |
foreach ( $expectedRows as $expected ) { |
| 31 |
$r = $res->fetchRow(); |
| 32 |
MediaWikiIntegrationTestCase::stripStringKeys( $r ); |
| 33 |
|
| 34 |
$i += 1; |
| 35 |
Assert::assertNotFalse( $r, "row #$i missing" ); |
| 36 |
|
| 37 |
Assert::assertEquals( $expected, $r, "row #$i mismatches" ); |
| 38 |
} |
| 39 |
|
| 40 |
$r = $res->fetchRow(); |
| 41 |
MediaWikiIntegrationTestCase::stripStringKeys( $r ); |
| 42 |
|
| 43 |
Assert::assertFalse( $r, "found extra row (after #$i)" ); |
| 44 |
} |
| 45 |
|
| 46 |
public function assertEmptyResult() { |
| 47 |
$res = $this->fetchResultSet(); |
| 48 |
Assert::assertSame( 0, $res->numRows(), "Result set should be empty" ); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 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" ); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public function assertFieldValues( array $expectedValues ) { |
| 80 |
Assert::assertSame( $expectedValues, $this->fetchFieldValues() ); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public function assertRowValue( array $expectedRow ) { |
| 92 |
$res = $this->fetchResultSet(); |
| 93 |
Assert::assertSame( 1, $res->numRows(), "There should be one row in the result set" ); |
| 94 |
$row = $res->fetchRow(); |
| 95 |
MediaWikiIntegrationTestCase::stripStringKeys( $row ); |
| 96 |
Assert::assertEquals( $expectedRow, $row, "The row should match" ); |
| 97 |
} |
| 98 |
} |