Issues (13)

Mezon/PdoCrud/Tests/PdoCrudMock.php (2 issues)

Severity
1
<?php
2
namespace Mezon\PdoCrud\Tests;
3
4
use Mezon\PdoCrud\PdoCrud;
5
use Mezon\PdoCrud\PdoCrudStatement;
6
7
class PdoCrudMock extends PdoCrud
8
{
9
10
    /**
11
     * Was the "connect" method called
12
     *
13
     * @var boolean
14
     */
15
    public $connectWasCalled = false;
16
17
    /**
18
     * Method connects to the database
19
     *
20
     * @param array $connnectionData
21
     *            Connection settings
22
     * @codeCoverageIgnore
23
     */
24
    public function connect(array $connnectionData): void
25
    {
26
        $this->connectWasCalled = true;
27
    }
28
29
    /**
30
     * Selected result
31
     *
32
     * @var array
33
     */
34
    public $selectResult = [];
35
36
    /**
37
     *
38
     * {@inheritdoc}
39
     * @see PdoCrud::select()
40
     */
41
    public function select(
42
        string $fields,
43
        string $tableNames,
44
        string $where = '1 = 1',
45
        int $from = 0,
46
        int $limit = 1000000): array
47
    {
48
        return $this->selectResult;
49
    }
50
51
    /**
52
     * Counter for update method calls
53
     *
54
     * @var integer
55
     */
56
    public $updateWasCalledCounter = 0;
57
58
    /**
59
     * Update calls data
60
     *
61
     * @var array
62
     */
63
    public $updateCalls = [];
64
65
    /**
66
     *
67
     * {@inheritdoc}
68
     * @see PdoCrud::update()
69
     */
70
    public function update(string $tableName, array $record, string $where, int $limit = 10000000): int
71
    {
72
        $this->updateWasCalledCounter ++;
73
74
        $this->updateCalls[] = [
75
            $tableName,
76
            $record,
77
            $where,
78
            $limit
79
        ];
80
81
        return 1;
82
    }
83
84
    /**
85
     * Counter for delete method calls
86
     *
87
     * @var integer
88
     */
89
    public $deleteWasCalledCounter = 0;
90
91
    /**
92
     *
93
     * {@inheritdoc}
94
     * @see PdoCrud::delete()
95
     */
96
    public function delete($tableName, $where, $limit = 10000000): int
97
    {
98
        $this->deleteWasCalledCounter ++;
99
100
        return 1;
101
    }
102
103
    /**
104
     * Locked tables
105
     *
106
     * @var array
107
     */
108
    public $lockedTables = [];
109
110
    /**
111
     * Locked tables modes
112
     *
113
     * @var array
114
     */
115
    public $lockedTablesModes = [];
116
117
    /**
118
     *
119
     * {@inheritdoc}
120
     * @see PdoCrud::lock()
121
     */
122
    public function lock(array $tables, array $modes): void
123
    {
124
        $this->lockedTables = $tables;
125
        $this->lockedTablesModes = $modes;
126
    }
127
128
    /**
129
     *
130
     * {@inheritdoc}
131
     * @see PdoCrud::unlock()
132
     */
133
    public function unlock(): void
134
    {
135
        // nop
136
    }
137
138
    /**
139
     * Special flag wich shows that transaction was started
140
     *
141
     * @var boolean
142
     */
143
    public $transactionWasStarted = true;
144
145
    /**
146
     *
147
     * {@inheritdoc}
148
     * @see PdoCrud::startTransaction()
149
     */
150
    public function startTransaction(): void
151
    {
152
        $this->transactionWasStarted = true;
153
    }
154
155
    /**
156
     *
157
     * {@inheritdoc}
158
     * @see PdoCrud::rollback()
159
     */
160
    public function rollback(): void
161
    {
162
        // nop
163
    }
164
165
    /**
166
     * Special flag wich shows that commit was performed
167
     *
168
     * @var boolean
169
     */
170
    public $commitWasPerformed = false;
171
172
    /**
173
     *
174
     * {@inheritdoc}
175
     * @see PdoCrud::commit()
176
     */
177
    public function commit(): void
178
    {
179
        $this->commitWasPerformed = true;
180
    }
181
182
    /**
183
     * Field stores count of insert method was called
184
     *
185
     * @var integer
186
     */
187
    public $insertWasCalledCounter = 0;
188
189
    /**
190
     * Insert calls
191
     *
192
     * @var array
193
     */
194
    public $insertCalls = [];
195
196
    /**
197
     *
198
     * {@inheritdoc}
199
     * @see PdoCrud::insert()
200
     */
201
    public function insert(string $tableName, array $record): int
202
    {
203
        $this->insertWasCalledCounter ++;
204
205
        $this->insertCalls[] = [
206
            $tableName,
207
            $record
208
        ];
209
210
        return 1;
211
    }
212
213
    /**
214
     * Prepare statements
215
     */
216
    public $prepareStatements = [];
217
218
    /**
219
     *
220
     * {@inheritdoc}
221
     * @see PdoCrudStatement::insert()
222
     */
223
    public function prepare(string $query): void
224
    {
225
        $this->prepareStatements[] = $query;
226
    }
227
228
    /**
229
     * Field stores count of executeSelect method was called
230
     *
231
     * @var integer
232
     */
233
    public $executeSelectWasCalledCounter = 0;
234
235
    /**
236
     * List of return values
237
     *
238
     * @var array
239
     */
240
    public $selectResults = [];
241
242
    /**
243
     *
244
     * {@inheritdoc}
245
     * @see PdoCrud::executeSelect()
246
     */
247
    public function executeSelect(?array $data = null): array
0 ignored issues
show
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

247
    public function executeSelect(/** @scrutinizer ignore-unused */ ?array $data = null): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
248
    {
249
        $this->executeSelectWasCalledCounter ++;
250
251
        $this->selectResults = array_reverse($this->selectResults);
252
253
        $return = array_pop($this->selectResults);
254
255
        $this->selectResults = array_reverse($this->selectResults);
256
257
        return $return;
258
    }
259
260
    /**
261
     * Binded parameters
262
     *
263
     * @var array
264
     */
265
    public $bindedParameters = [];
266
267
    /**
268
     *
269
     * {@inheritdoc}
270
     * @see PdoCrud::bindParameter()
271
     */
272
    public function bindParameter(string $parameter, $variable, int $type = \PDO::PARAM_STR): void
273
    {
274
        $this->bindedParameters[] = [
275
            $parameter,
276
            $variable,
277
            $type
278
        ];
279
    }
280
281
    /**
282
     * Field stores count of executet method was called
283
     *
284
     * @var integer
285
     */
286
    public $executeWasCalledCounter = 0;
287
288
    /**
289
     * Method executes SQL query
290
     *
291
     * @param ?array $data
292
     *            query data
293
     * @codeCoverageIgnore
294
     */
295
    public function execute(?array $data = null): void
0 ignored issues
show
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

295
    public function execute(/** @scrutinizer ignore-unused */ ?array $data = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
296
    {
297
        $this->executeWasCalledCounter ++;
298
    }
299
300
    /**
301
     * Result of the lastInsertId call
302
     *
303
     * @var integer
304
     */
305
    public $lastInsertIdResut = 0;
306
307
    /**
308
     * Method returns id of the last inserted record
309
     *
310
     * @return int id of the last inserted record
311
     */
312
    public function lastInsertId(): int
313
    {
314
        return $this->lastInsertIdResut;
315
    }
316
317
    /**
318
     * Method returns count of affected rows
319
     *
320
     * @return int count of affected rows
321
     */
322
    public function rowCount(): int
323
    {
324
        return 1;
325
    }
326
}
327