Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / rdbms / resultwrapper / FakeResultWrapperTest.php
1 <?php
2
3 /**
4 * Holds tests for FakeResultWrapper MediaWiki class.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 */
23
24 use Wikimedia\Rdbms\FakeResultWrapper;
25
26 /**
27 * @group Database
28 * @covers \Wikimedia\Rdbms\FakeResultWrapper
29 */
30 class FakeResultWrapperTest extends PHPUnit\Framework\TestCase {
31 public function testIteration() {
32 $res = new FakeResultWrapper( [
33 [ 'colA' => 1, 'colB' => 'a' ],
34 [ 'colA' => 2, 'colB' => 'b' ],
35 (object)[ 'colA' => 3, 'colB' => 'c' ],
36 [ 'colA' => 4, 'colB' => 'd' ],
37 [ 'colA' => 5, 'colB' => 'e' ],
38 (object)[ 'colA' => 6, 'colB' => 'f' ],
39 (object)[ 'colA' => 7, 'colB' => 'g' ],
40 [ 'colA' => 8, 'colB' => 'h' ]
41 ] );
42
43 $expectedRows = [
44 0 => (object)[ 'colA' => 1, 'colB' => 'a' ],
45 1 => (object)[ 'colA' => 2, 'colB' => 'b' ],
46 2 => (object)[ 'colA' => 3, 'colB' => 'c' ],
47 3 => (object)[ 'colA' => 4, 'colB' => 'd' ],
48 4 => (object)[ 'colA' => 5, 'colB' => 'e' ],
49 5 => (object)[ 'colA' => 6, 'colB' => 'f' ],
50 6 => (object)[ 'colA' => 7, 'colB' => 'g' ],
51 7 => (object)[ 'colA' => 8, 'colB' => 'h' ]
52 ];
53
54 $this->assertEquals( 8, $res->numRows() );
55
56 $res->seek( 7 );
57 $this->assertEquals( [ 'colA' => 8, 'colB' => 'h' ], $res->fetchRow() );
58 $res->seek( 7 );
59 $this->assertEquals( (object)[ 'colA' => 8, 'colB' => 'h' ], $res->fetchObject() );
60
61 $this->assertEquals( $expectedRows, iterator_to_array( $res, true ) );
62
63 $rows = [];
64 foreach ( $res as $i => $row ) {
65 $rows[$i] = $row;
66 }
67 $this->assertEquals( $expectedRows, $rows );
68 }
69 }