• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mpyw / laravel-database-mock / 13674878947

05 Mar 2025 11:24AM UTC coverage: 91.379%. Remained the same
13674878947

push

github

web-flow
chore: 🤖 Bump version (#4)

53 of 58 relevant lines covered (91.38%)

27.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.85
/src/Proxies/SingleConnectionProxy.php
1
<?php
2

3
namespace Mpyw\LaravelDatabaseMock\Proxies;
4

5
use Illuminate\Database\ConnectionInterface;
6
use Mpyw\MockeryPDO\Expectations\ExecuteExpectationProxy;
7
use Mpyw\MockeryPDO\Expectations\PrepareExpectationProxy;
8
use Mpyw\MockeryPDO\PDOMockProxy;
9
use ReflectionProperty;
10

11
/**
12
 * Class SingleConnectionProxy
13
 *
14
 * @mixin \Mpyw\MockeryPDO\PDOMockProxy
15
 */
16
class SingleConnectionProxy
17
{
18
    /**
19
     * @var \Illuminate\Database\Connection|\Illuminate\Database\ConnectionInterface
20
     */
21
    protected $connection;
22

23
    /**
24
     * @var \Mpyw\MockeryPDO\PDOMockProxy
25
     */
26
    protected $pdo;
27

28
    /**
29
     * @var bool
30
     */
31
    protected $ordered = true;
32

33
    /**
34
     * SingleConnectionProxy constructor.
35
     *
36
     * @param \Illuminate\Database\ConnectionInterface $connection
37
     * @param \Mpyw\MockeryPDO\PDOMockProxy            $pdo
38
     */
39
    public function __construct(ConnectionInterface $connection, PDOMockProxy $pdo)
40
    {
41
        $this->connection = $connection;
48✔
42
        $this->pdo = $pdo;
48✔
43
    }
44

45
    /**
46
     * @param  string $name
47
     * @param  array  $arguments
48
     * @return mixed
49
     */
50
    public function __call(string $name, array $arguments)
51
    {
52
        return $this->getPdo()->$name(...$arguments);
16✔
53
    }
54

55
    /**
56
     * @return \Illuminate\Database\Connection|\Illuminate\Database\ConnectionInterface
57
     */
58
    public function getConnection(): ConnectionInterface
59
    {
60
        return $this->connection;
48✔
61
    }
62

63
    /**
64
     * @return \Mpyw\MockeryPDO\PDOMockProxy
65
     */
66
    public function getPdo(): PDOMockProxy
67
    {
68
        return $this->pdo;
48✔
69
    }
70

71
    /**
72
     * @return $this
73
     */
74
    public function inThisOrder()
75
    {
76
        $this->ordered = true;
×
77

78
        return $this;
×
79
    }
80

81
    /**
82
     * @return $this
83
     */
84
    public function inAnyOrder()
85
    {
86
        $this->ordered = false;
8✔
87

88
        return $this;
8✔
89
    }
90

91
    /**
92
     * @param  mixed|string                                          $sql
93
     * @param  array                                                 $bindings
94
     * @return \Mpyw\MockeryPDO\Expectations\ExecuteExpectationProxy
95
     */
96
    public function shouldSelect($sql, array $bindings = []): ExecuteExpectationProxy
97
    {
98
        return $this->shouldPrepareForSelect($sql, $bindings)->shouldExecute();
32✔
99
    }
100

101
    /**
102
     * @param mixed|string $sql
103
     * @param array        $bindings
104
     */
105
    public function shouldInsert($sql, array $bindings = []): void
106
    {
107
        $this->shouldRunStatement($sql, $bindings);
16✔
108
    }
109

110
    /**
111
     * @param mixed|string $sql
112
     * @param array        $bindings
113
     */
114
    public function shouldUpdateOne($sql, array $bindings = []): void
115
    {
116
        $this->shouldUpdateForRows($sql, $bindings, 1);
24✔
117
    }
118

119
    /**
120
     * @param mixed|string $sql
121
     * @param array        $bindings
122
     * @param int          $rowCount
123
     */
124
    public function shouldUpdateForRows($sql, array $bindings, int $rowCount): void
125
    {
126
        $this->shouldRunAffectingStatementForRows($sql, $bindings, $rowCount);
24✔
127
    }
128

129
    /**
130
     * @param mixed|string $sql
131
     * @param array        $bindings
132
     */
133
    public function shouldDeleteOne($sql, array $bindings): void
134
    {
135
        $this->shouldDeleteForRows($sql, $bindings, 1);
×
136
    }
137

138
    /**
139
     * @param mixed|string $sql
140
     * @param array        $bindings
141
     * @param int          $rowCount
142
     */
143
    public function shouldDeleteForRows($sql, array $bindings, int $rowCount): void
144
    {
145
        $this->shouldRunAffectingStatementForRows($sql, $bindings, $rowCount);
×
146
    }
147

148
    /**
149
     * @param mixed|string $sql
150
     * @param array        $bindings
151
     * @param int          $rowCount
152
     */
153
    public function shouldRunAffectingStatementForRows($sql, array $bindings, int $rowCount): void
154
    {
155
        $this->shouldPrepareForEffect($sql, $bindings)->shouldExecute()->shouldRowCountReturns($rowCount);
24✔
156
    }
157

158
    /**
159
     * @param mixed|string $sql
160
     * @param array        $bindings
161
     */
162
    public function shouldRunStatement($sql, array $bindings = []): void
163
    {
164
        $this->shouldPrepareForEffect($sql, $bindings)->shouldExecute();
16✔
165
    }
166

167
    /**
168
     * @param mixed|string $sql
169
     * @param int          $rowCount
170
     */
171
    public function shouldRunUnpreparedStatementForRows($sql, int $rowCount): void
172
    {
173
        $this->getPdo()->shouldExec($sql)->andReturn($rowCount);
×
174
    }
175

176
    /**
177
     * @param  mixed|string                                          $sql
178
     * @param  array                                                 $bindings
179
     * @return \Mpyw\MockeryPDO\Expectations\PrepareExpectationProxy
180
     */
181
    public function shouldPrepareForSelect($sql, array $bindings = []): PrepareExpectationProxy
182
    {
183
        return $this->shouldPrepare($sql, $bindings, true);
32✔
184
    }
185

186
    /**
187
     * @param  mixed|string                                          $sql
188
     * @param  array                                                 $bindings
189
     * @return \Mpyw\MockeryPDO\Expectations\PrepareExpectationProxy
190
     */
191
    public function shouldPrepareForEffect($sql, array $bindings = []): PrepareExpectationProxy
192
    {
193
        return $this->shouldPrepare($sql, $bindings, false);
40✔
194
    }
195

196
    /**
197
     * @param  mixed|string                                          $sql
198
     * @param  array                                                 $bindings
199
     * @param  bool                                                  $setFetchMode
200
     * @return \Mpyw\MockeryPDO\Expectations\PrepareExpectationProxy
201
     */
202
    protected function shouldPrepare($sql, array $bindings, bool $setFetchMode): PrepareExpectationProxy
203
    {
204
        $stmt = $this->getPdo()->shouldPrepare($sql);
48✔
205

206
        if ($setFetchMode) {
48✔
207
            $stmt->shouldReceive('setFetchMode', $this->getFetchMode());
32✔
208
        }
209

210
        $this->getConnection()->bindValues(
48✔
211
            new BindValueDelegator($stmt->shouldBind()),
48✔
212
            $this->getConnection()->prepareBindings($bindings)
48✔
213
        );
48✔
214

215
        if ($this->ordered) {
48✔
216
            $stmt->ordered()->once();
40✔
217
        }
218

219
        return $stmt;
48✔
220
    }
221

222
    /** @noinspection PhpDocMissingThrowsInspection */
223

224
    /**
225
     * @return int
226
     */
227
    public function getFetchMode(): int
228
    {
229
        /* @noinspection PhpUnhandledExceptionInspection */
230
        $reflection = new ReflectionProperty($this->getConnection(), 'fetchMode');
32✔
231
        $reflection->setAccessible(true);
32✔
232
        return $reflection->getValue($this->getConnection());
32✔
233
    }
234
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc