packages/ztd-query-core/tests/Fake/RecordingTransactionTarget.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Fake;
6
7use ZtdQuery\Sql\TransactionTarget;
8
9/**
10 * A transaction target that records what it was asked for.
11 *
12 * Nothing here keeps transaction state, so a test can check that a statement
13 * asked for the one thing it stands for and handed over the name it carried.
14 */
15final class RecordingTransactionTarget implements TransactionTarget
16{
17 /**
18 * @var list<string> What this target was asked for, in order
19 */
20 public array $asked = [];
21
22 /**
23 * Records that a transaction was opened.
24 */
25 public function begin(): void
26 {
27 $this->asked[] = 'begin';
28 }
29
30 /**
31 * Records that the transaction was kept.
32 */
33 public function commit(): void
34 {
35 $this->asked[] = 'commit';
36 }
37
38 /**
39 * Records that the transaction was undone.
40 */
41 public function rollBack(): void
42 {
43 $this->asked[] = 'rollBack';
44 }
45
46 /**
47 * Records that a point was marked.
48 *
49 * @param string $name Name the point is marked with
50 */
51 public function savepoint(string $name): void
52 {
53 $this->asked[] = "savepoint {$name}";
54 }
55
56 /**
57 * Records that the transaction was brought back to a point.
58 *
59 * @param string $name Name the point was marked with
60 */
61 public function rollBackTo(string $name): void
62 {
63 $this->asked[] = "rollBackTo {$name}";
64 }
65
66 /**
67 * Records that a point was forgotten.
68 *
69 * @param string $name Name the point was marked with
70 */
71 public function release(string $name): void
72 {
73 $this->asked[] = "release {$name}";
74 }
75}
76