4 * Holds tests for FakeResultWrapper MediaWiki class.
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.
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.
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
24 use Wikimedia\Rdbms\FakeResultWrapper
;
28 * @covers \Wikimedia\Rdbms\FakeResultWrapper
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' ]
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' ]
54 $this->assertEquals( 8, $res->numRows() );
57 $this->assertEquals( [ 'colA' => 8, 'colB' => 'h' ], $res->fetchRow() );
59 $this->assertEquals( (object)[ 'colA' => 8, 'colB' => 'h' ], $res->fetchObject() );
61 $this->assertEquals( $expectedRows, iterator_to_array( $res, true ) );
64 foreach ( $res as $i => $row ) {
67 $this->assertEquals( $expectedRows, $rows );