1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Doctrine\Tests\Mocks; |
||
6 | |||
7 | use Doctrine\DBAL\Driver\Statement; |
||
8 | use function array_shift; |
||
9 | use function current; |
||
10 | use function is_array; |
||
11 | use function next; |
||
12 | |||
13 | /** |
||
14 | * This class is a mock of the Statement interface that can be passed in to the Hydrator |
||
15 | * to test the hydration standalone with faked result sets. |
||
16 | */ |
||
17 | class HydratorMockStatement implements \IteratorAggregate, Statement |
||
18 | { |
||
19 | /** @var array */ |
||
20 | private $resultSet; |
||
21 | |||
22 | /** |
||
23 | * Creates a new mock statement that will serve the provided fake result set to clients. |
||
24 | * |
||
25 | * @param array $resultSet The faked SQL result set. |
||
26 | */ |
||
27 | public function __construct(array $resultSet) |
||
28 | { |
||
29 | $this->resultSet = $resultSet; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public function fetchAll($fetchMode = null, ...$args) |
||
36 | { |
||
37 | return $this->resultSet; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function fetchColumn($columnNumber = 0) |
||
44 | { |
||
45 | $row = current($this->resultSet); |
||
46 | if (! is_array($row)) { |
||
47 | return false; |
||
48 | } |
||
49 | $val = array_shift($row); |
||
50 | return $val !== null ? $val : false; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function fetch($fetchMode = null, ...$args) |
||
57 | { |
||
58 | $current = current($this->resultSet); |
||
59 | next($this->resultSet); |
||
60 | return $current; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function closeCursor() |
||
67 | { |
||
68 | return true; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function bindValue($param, $value, $type = null) |
||
75 | { |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | public function bindParam($column, &$variable, $type = null, $length = null) |
||
82 | { |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public function columnCount() |
||
89 | { |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | public function errorCode() |
||
96 | { |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | public function errorInfo() |
||
103 | { |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | public function execute($params = null) |
||
110 | { |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function rowCount() : int |
||
117 | { |
||
118 | } |
||
0 ignored issues
–
show
|
|||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function getIterator() |
||
124 | { |
||
125 | return $this->resultSet; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | public function setFetchMode($fetchMode, ...$args) |
||
132 | { |
||
133 | } |
||
134 | } |
||
135 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: