Completed
Push — master ( 636137...7806f6 )
by Alex
02:09
created

PdoCrudMock::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 1
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
     * Selected result
12
     *
13
     * @var array
14
     */
15
    public $selectResult = [];
16
17
    /**
18
     *
19
     * {@inheritdoc}
20
     * @see PdoCrud::select()
21
     */
22
    public function select(
23
        string $fields,
24
        string $tableNames,
25
        string $where = '1 = 1',
26
        int $from = 0,
27
        int $limit = 1000000): array
28
    {
29
        return $this->selectResult;
30
    }
31
32
    /**
33
     * Counter for update method calls
34
     *
35
     * @var integer
36
     */
37
    public $updateWasCalledCounter = 0;
38
39
    /**
40
     * Update calls data
41
     *
42
     * @var array
43
     */
44
    public $updateCalls = [];
45
46
    /**
47
     *
48
     * {@inheritdoc}
49
     * @see PdoCrud::update()
50
     */
51
    public function update(string $tableName, array $record, string $where, int $limit = 10000000): int
52
    {
53
        $this->updateWasCalledCounter ++;
54
55
        $this->updateCalls[] = [
56
            $tableName,
57
            $record,
58
            $where,
59
            $limit
60
        ];
61
62
        return 1;
63
    }
64
65
    /**
66
     * Counter for delete method calls
67
     *
68
     * @var integer
69
     */
70
    public $deleteWasCalledCounter = 0;
71
72
    /**
73
     *
74
     * {@inheritdoc}
75
     * @see PdoCrud::delete()
76
     */
77
    public function delete($tableName, $where, $limit = 10000000): int
78
    {
79
        $this->deleteWasCalledCounter ++;
80
81
        return 1;
82
    }
83
84
    /**
85
     * Locked tables
86
     *
87
     * @var array
88
     */
89
    public $lockedTables = [];
90
91
    /**
92
     * Locked tables modes
93
     *
94
     * @var array
95
     */
96
    public $lockedTablesModes = [];
97
98
    /**
99
     *
100
     * {@inheritdoc}
101
     * @see PdoCrud::lock()
102
     */
103
    public function lock(array $tables, array $modes): void
104
    {
105
        $this->lockedTables = $tables;
106
        $this->lockedTablesModes = $modes;
107
    }
108
109
    /**
110
     *
111
     * {@inheritdoc}
112
     * @see PdoCrud::unlock()
113
     */
114
    public function unlock(): void
115
    {
116
        // nop
117
    }
118
119
    /**
120
     * Special flag wich shows that transaction was started
121
     *
122
     * @var boolean
123
     */
124
    public $transactionWasStarted = true;
125
126
    /**
127
     *
128
     * {@inheritdoc}
129
     * @see PdoCrud::startTransaction()
130
     */
131
    public function startTransaction(): void
132
    {
133
        $this->transactionWasStarted = true;
134
    }
135
136
    /**
137
     *
138
     * {@inheritdoc}
139
     * @see PdoCrud::rollback()
140
     */
141
    public function rollback(): void
142
    {
143
        // nop
144
    }
145
146
    /**
147
     * Special flag wich shows that commit was performed
148
     *
149
     * @var boolean
150
     */
151
    public $commitWasPerformed = false;
152
153
    /**
154
     *
155
     * {@inheritdoc}
156
     * @see PdoCrud::commit()
157
     */
158
    public function commit(): void
159
    {
160
        $this->commitWasPerformed = true;
161
    }
162
163
    /**
164
     * Field stores count of insert method was called
165
     *
166
     * @var integer
167
     */
168
    public $insertWasCalledCounter = 0;
169
170
    /**
171
     * Insert calls
172
     *
173
     * @var array
174
     */
175
    public $insertCalls = [];
176
177
    /**
178
     *
179
     * {@inheritdoc}
180
     * @see PdoCrud::insert()
181
     */
182
    public function insert(string $tableName, array $record): int
183
    {
184
        $this->insertWasCalledCounter ++;
185
186
        $this->insertCalls[] = [
187
            $tableName,
188
            $record
189
        ];
190
191
        return 1;
192
    }
193
194
    /**
195
     * Prepare statements
196
     */
197
    public $prepareStatements = [];
198
199
    /**
200
     *
201
     * {@inheritdoc}
202
     * @see PdoCrudStatement::insert()
203
     */
204
    public function prepare(string $query): void
205
    {
206
        $this->prepareStatements[] = $query;
207
    }
208
209
    /**
210
     * Field stores count of executeSelect method was called
211
     *
212
     * @var integer
213
     */
214
    public $executeSelectWasCalledCounter = 0;
215
216
    /**
217
     * List of return values
218
     *
219
     * @var array
220
     */
221
    public $selectResults = [];
222
223
    /**
224
     *
225
     * {@inheritdoc}
226
     * @see PdoCrud::executeSelect()
227
     */
228
    public function executeSelect(?array $data = null): array
0 ignored issues
show
Unused Code introduced by
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

228
    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...
229
    {
230
        $this->executeSelectWasCalledCounter ++;
231
232
        $this->selectResults = array_reverse($this->selectResults);
233
234
        $return = array_pop($this->selectResults);
235
236
        $this->selectResults = array_reverse($this->selectResults);
237
238
        return $return;
239
    }
240
241
    /**
242
     * Binded parameters
243
     *
244
     * @var array
245
     */
246
    public $bindedParameters = [];
247
248
    /**
249
     *
250
     * {@inheritdoc}
251
     * @see PdoCrud::bindParameter()
252
     */
253
    public function bindParameter(string $parameter, $variable, int $type = \PDO::PARAM_STR): void
254
    {
255
        $this->bindedParameters[] = [
256
            $parameter,
257
            $variable,
258
            $type
259
        ];
260
    }
261
262
    /**
263
     * Field stores count of executet method was called
264
     *
265
     * @var integer
266
     */
267
    public $executeWasCalledCounter = 0;
268
269
    /**
270
     * Method executes SQL query
271
     *
272
     * @param ?array $data
273
     *            query data
274
     * @codeCoverageIgnore
275
     */
276
    public function execute(?array $data = null): void
0 ignored issues
show
Unused Code introduced by
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

276
    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...
277
    {
278
        $this->executeWasCalledCounter ++;
279
    }
280
281
    /**
282
     * Result of the lastInsertId call
283
     *
284
     * @var integer
285
     */
286
    public $lastInsertIdResut = 0;
287
288
    /**
289
     * Method returns id of the last inserted record
290
     *
291
     * @return int id of the last inserted record
292
     */
293
    public function lastInsertId(): int
294
    {
295
        return $this->lastInsertIdResut;
296
    }
297
}
298