Debian Codegraph @

tests/phpunit/unit/includes/libs/rdbms/resultwrapper/FakeResultWrapperTest.php

raw symbols SCIP
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 namespace Wikimedia\Tests\Rdbms;
25
26 use PHPUnit\Framework\TestCase;
27 use Wikimedia\Rdbms\FakeResultWrapper;
28
29 /**
30 * @covers \Wikimedia\Rdbms\FakeResultWrapper
31 */
32 class FakeResultWrapperTest extends TestCase {
33 public function testIteration() {
34 $res = new FakeResultWrapper( [
35 [ 'colA' => 1, 'colB' => 'a' ],
36 [ 'colA' => 2, 'colB' => 'b' ],
37 (object)[ 'colA' => 3, 'colB' => 'c' ],
38 [ 'colA' => 4, 'colB' => 'd' ],
39 [ 'colA' => 5, 'colB' => 'e' ],
40 (object)[ 'colA' => 6, 'colB' => 'f' ],
41 (object)[ 'colA' => 7, 'colB' => 'g' ],
42 [ 'colA' => 8, 'colB' => 'h' ]
43 ] );
44
45 $expectedRows = [
46 0 => (object)[ 'colA' => 1, 'colB' => 'a' ],
47 1 => (object)[ 'colA' => 2, 'colB' => 'b' ],
48 2 => (object)[ 'colA' => 3, 'colB' => 'c' ],
49 3 => (object)[ 'colA' => 4, 'colB' => 'd' ],
50 4 => (object)[ 'colA' => 5, 'colB' => 'e' ],
51 5 => (object)[ 'colA' => 6, 'colB' => 'f' ],
52 6 => (object)[ 'colA' => 7, 'colB' => 'g' ],
53 7 => (object)[ 'colA' => 8, 'colB' => 'h' ]
54 ];
55
56 $this->assertEquals( 8, $res->numRows() );
57
58 $res->seek( 7 );
59 $this->assertEquals( [ 'colA' => 8, 'colB' => 'h' ], $res->fetchRow() );
60 $res->seek( 7 );
61 $this->assertEquals( (object)[ 'colA' => 8, 'colB' => 'h' ], $res->fetchObject() );
62
63 $this->assertEquals( $expectedRows, iterator_to_array( $res, true ) );
64
65 $rows = [];
66 foreach ( $res as $i => $row ) {
67 $rows[$i] = $row;
68 }
69 $this->assertEquals( $expectedRows, $rows );
70 }
71 }