Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
21 / 21 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | use Phexium\Plugin\Transaction\Adapter\InMemoryTransaction; |
| 11 | use Tests\Phexium\Fake\Plugin\Transaction\Transaction as FakeTransaction; |
| 12 | |
| 13 | test('Fake transaction tracks begin calls', function (): void { |
| 14 | $transaction = new FakeTransaction(new InMemoryTransaction()); |
| 15 | expect($transaction->inTransaction())->toBeFalse(); |
| 16 | |
| 17 | $transaction->begin(); |
| 18 | |
| 19 | expect($transaction->inTransaction())->toBeTrue(); |
| 20 | expect($transaction->getCallHistory())->toBe(['begin']); |
| 21 | }); |
| 22 | |
| 23 | test('Fake transaction tracks commit calls', function (): void { |
| 24 | $transaction = new FakeTransaction(new InMemoryTransaction()); |
| 25 | |
| 26 | $transaction->begin(); |
| 27 | $transaction->commit(); |
| 28 | |
| 29 | expect($transaction->inTransaction())->toBeFalse(); |
| 30 | expect($transaction->getCallHistory())->toBe(['begin', 'commit']); |
| 31 | }); |
| 32 | |
| 33 | test('Fake transaction tracks rollback calls', function (): void { |
| 34 | $transaction = new FakeTransaction(new InMemoryTransaction()); |
| 35 | |
| 36 | $transaction->begin(); |
| 37 | $transaction->rollback(); |
| 38 | |
| 39 | expect($transaction->inTransaction())->toBeFalse(); |
| 40 | expect($transaction->getCallHistory())->toBe(['begin', 'rollback']); |
| 41 | }); |