Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
72.73% covered (warning)
72.73%
8 / 11
57.14% covered (warning)
57.14%
4 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
FakeResultWrapper
72.73% covered (warning)
72.73%
8 / 11
57.14% covered (warning)
57.14%
4 / 7
12.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 doNumRows
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 doFetchObject
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 doFetchRow
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 doSeek
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 doFree
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doGetFieldNames
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use RuntimeException;
6use stdClass;
7
8/**
9 * Overloads the relevant methods of the real ResultWrapper so it
10 * doesn't go anywhere near an actual database.
11 */
12class FakeResultWrapper extends ResultWrapper {
13    /** @var stdClass[]|array[]|null */
14    protected $result;
15
16    /**
17     * @param stdClass[]|array[]|FakeResultWrapper $result
18     */
19    public function __construct( $result ) {
20        if ( $result instanceof self ) {
21            $this->result = $result->result;
22        } else {
23            $this->result = $result;
24        }
25    }
26
27    /** @inheritDoc */
28    protected function doNumRows() {
29        return count( $this->result );
30    }
31
32    /** @inheritDoc */
33    protected function doFetchObject() {
34        $value = $this->result[$this->currentPos] ?? false;
35        return is_array( $value ) ? (object)$value : $value;
36    }
37
38    /** @inheritDoc */
39    protected function doFetchRow() {
40        $row = $this->doFetchObject();
41        return is_object( $row ) ? get_object_vars( $row ) : $row;
42    }
43
44    /** @inheritDoc */
45    protected function doSeek( $pos ) {
46    }
47
48    /** @inheritDoc */
49    protected function doFree() {
50        $this->result = null;
51    }
52
53    /** @inheritDoc */
54    protected function doGetFieldNames() {
55        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
56        throw new RuntimeException( __METHOD__ . ' is unimplemented' );
57    }
58}