Completed
Push — master ( a8d41d...ff0d7b )
by Alex
07:53
created

PdoCrudMock::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 4
1
<?php
2
namespace Mezon\PdoCrud\Tests;
3
4
use Mezon\PdoCrud\PdoCrud;
5
6
class PdoCrudMock extends PdoCrud
7
{
8
9
    /**
10
     * Selected result
11
     *
12
     * @var array
13
     */
14
    public $selectResult = [];
15
16
    /**
17
     *
18
     * {@inheritdoc}
19
     * @see PdoCrud::select()
20
     */
21
    public function select(
22
        string $fields,
23
        string $tableNames,
24
        string $where = '1 = 1',
25
        int $from = 0,
26
        int $limit = 1000000): array
27
    {
28
        return $this->selectResult;
29
    }
30
31
    /**
32
     * Counter for update method calls
33
     *
34
     * @var integer
35
     */
36
    public $updateWasCalledCounter = 0;
37
38
    /**
39
     *
40
     * {@inheritdoc}
41
     * @see PdoCrud::update()
42
     */
43
    public function update(string $tableName, array $record, string $where, int $limit = 10000000): int
44
    {
45
        $this->updateWasCalledCounter ++;
46
47
        return 1;
48
    }
49
50
    /**
51
     * Counter for delete method calls
52
     *
53
     * @var integer
54
     */
55
    public $deleteWasCalledCounter = 0;
56
57
    /**
58
     *
59
     * {@inheritdoc}
60
     * @see PdoCrud::delete()
61
     */
62
    public function delete($tableName, $where, $limit = 10000000): int
63
    {
64
        $this->deleteWasCalledCounter ++;
65
66
        return 1;
67
    }
68
69
    /**
70
     * Locked tables
71
     *
72
     * @var array
73
     */
74
    public $lockedTables = [];
75
76
    /**
77
     * Locked tables modes
78
     *
79
     * @var array
80
     */
81
    public $lockedTablesModes = [];
82
83
    /**
84
     *
85
     * {@inheritdoc}
86
     * @see PdoCrud::lock()
87
     */
88
    public function lock(array $tables, array $modes): void
89
    {
90
        $this->lockedTables = $tables;
91
        $this->lockedTablesModes = $modes;
92
    }
93
94
    /**
95
     *
96
     * {@inheritdoc}
97
     * @see PdoCrud::unlock()
98
     */
99
    public function unlock(): void
100
    {
101
        // nop
102
    }
103
104
    /**
105
     * Special flag wich shows that transaction was started
106
     *
107
     * @var boolean
108
     */
109
    public $transactionWasStarted = true;
110
111
    /**
112
     *
113
     * {@inheritdoc}
114
     * @see PdoCrud::startTransaction()
115
     */
116
    public function startTransaction(): void
117
    {
118
        $this->transactionWasStarted = true;
119
    }
120
121
    /**
122
     *
123
     * {@inheritdoc}
124
     * @see PdoCrud::rollback()
125
     */
126
    public function rollback(): void
127
    {
128
        // nop
129
    }
130
131
    /**
132
     * Special flag wich shows that commit was performed
133
     *
134
     * @var boolean
135
     */
136
    public $commitWasPerformed = false;
137
138
    /**
139
     *
140
     * {@inheritdoc}
141
     * @see PdoCrud::commit()
142
     */
143
    public function commit(): void
144
    {
145
        $this->commitWasPerformed = true;
146
    }
147
148
    /**
149
     * Field stores count of insert method was called
150
     *
151
     * @var integer
152
     */
153
    public $insertsCounter = 0;
154
155
    /**
156
     *
157
     * {@inheritdoc}
158
     * @see PdoCrud::insert()
159
     */
160
    public function insert(string $tableName, array $record): int
161
    {
162
        $this->insertsCounter ++;
163
164
        return 1;
165
    }
166
}
167