@@ -39,7 +39,7 @@ final class MyTest extends TestCase
3939{
4040 protected function getClient() : Client
4141 {
42- // you have to implement this method
42+ // TODO: Implement getClient() method.
4343 }
4444
4545 // ...
@@ -162,7 +162,7 @@ public function testChangeUserPassword() : void
162162
163163``` php
164164/**
165- * @requires Tarantool >= 2.3.2
165+ * @requires Tarantool ^ 2.3.2
166166 */
167167public function testPrepareCreatesPreparedStatement() : void
168168{
@@ -212,6 +212,32 @@ public function testGetSpaceIsCached() : void
212212}
213213```
214214
215+ In order to check SQL statements, use the ` Tarantool\PhpUnit\Expectation\SqlStatementExpectations ` trait,
216+ which contains the following methods:
217+
218+ * ` expectSqlStatementToBeExecuted(int $count) : void `
219+ * ` expectSqlStatementToBeExecutedAtLeast(int $count) : void `
220+ * ` expectSqlStatementToBeExecutedAtMost(int $count) : void `
221+ * ` expectSqlStatementToBeExecutedOnce() : void `
222+ * ` expectSqlStatementToBeNeverCalled() : void `
223+ * ` expectSqlStatementToBeExecutedAtLeastOnce() : void `
224+ * ` expectSqlStatementToBeExecutedAtMostOnce() : void `
225+
226+ Usage example:
227+
228+ ``` php
229+ public function testCloseDeallocatesPreparedStatement() : void
230+ {
231+ $stmt = $this->client->prepare('SELECT ?');
232+
233+ $this->expectSqlStatementToBeExecutedOnce();
234+ $stmt->close();
235+ }
236+ ```
237+
238+ To enable all the above expectation methods in one go, use the ` Tarantool\PhpUnit\Expectation\Expectations ` trait,
239+ or extend the ` Tarantool\PhpUnit\TestCase ` class.
240+
215241
216242## Mocking
217243
@@ -249,23 +275,20 @@ public function testFoo() : void
249275
250276To simulate specific scenarios, such as establishing a connection to a server
251277or returning specific responses in a specific order from the server, use the facilities
252- of the ` MockClientBuilder ` class. For example, to simulate ` PING ` request/response :
278+ of the ` MockClientBuilder ` class. For example, to simulate the ` PING ` request:
253279
254280``` php
255281use Tarantool\Client\Request\PingRequest;
256- use Tarantool\PhpUnit\Client\DummyFactory;
257282use Tarantool\PhpUnit\TestCase;
258283
259284final class MyTest extends TestCase
260285{
261286 public function testFoo() : void
262287 {
263288 $mockClient = $this->getMockClientBuilder()
264- ->shouldHandle(
265- new PingRequest(),
266- DummyFactory::createEmptyResponse()
267- )->build();
268-
289+ ->shouldSend(new PingRequest())
290+ ->build();
291+
269292 // ...
270293 }
271294
@@ -285,8 +308,10 @@ final class MyTest extends TestCase
285308 public function testFoo() : void
286309 {
287310 $mockClient = $this->getMockClientBuilder()
288- ->shouldHandle(
289- RequestTypes::EVALUATE,
311+ ->shouldSend(
312+ RequestTypes::EVALUATE,
313+ RequestTypes::EVALUATE
314+ )->willReceive(
290315 DummyFactory::createResponseFromData([2]),
291316 DummyFactory::createResponseFromData([3])
292317 )->build();
@@ -297,6 +322,16 @@ final class MyTest extends TestCase
297322 // ...
298323}
299324```
325+ The above example can be simplified to:
326+
327+ ``` php
328+ $mockClient = $this->getMockClientBuilder()
329+ ->shouldHandle(
330+ RequestTypes::EVALUATE,
331+ DummyFactory::createResponseFromData([2]),
332+ DummyFactory::createResponseFromData([3])
333+ )->build();
334+ ```
300335
301336Besides, the builder allows setting custom ` Connection ` and ` Packer ` instances:
302337
0 commit comments