packages/ztd-query-core/tests/Unit/Shadow/Mutation/Table/TruncateMutationTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Shadow\Mutation\Table;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\UsesClass;
9use PHPUnit\Framework\TestCase;
10use ZtdQuery\Shadow\Mutation\Table\TruncateMutation;
11use ZtdQuery\Shadow\ShadowStore;
12
13#[UsesClass(ShadowStore::class)]
14#[CoversClass(TruncateMutation::class)]
15#[UsesClass(\ZtdQuery\Schema\RowSet::class)]
16final class TruncateMutationTest extends TestCase
17{
18 public function testApplyClearsAllRows(): void
19 {
20 $store = new ShadowStore();
21 $store->set('users', [
22 ['id' => 1, 'name' => 'Alice'],
23 ['id' => 2, 'name' => 'Bob'],
24 ['id' => 3, 'name' => 'Carol'],
25 ]);
26
27 $mutation = new TruncateMutation('users');
28 $mutation->apply($store, []);
29
30 self::assertSame([], $store->get('users'));
31 }
32
33 public function testTableNameReturnsTableName(): void
34 {
35 $mutation = new TruncateMutation('users');
36
37 self::assertSame('users', $mutation->tableName());
38 }
39
40 public function testApplyOnEmptyTableDoesNothing(): void
41 {
42 $store = new ShadowStore();
43 $store->set('users', []);
44
45 $mutation = new TruncateMutation('users');
46 $mutation->apply($store, []);
47
48 self::assertSame([], $store->get('users'));
49 }
50
51 public function testApplyIgnoresProvidedRows(): void
52 {
53 $store = new ShadowStore();
54 $store->set('users', [['id' => 1]]);
55
56 $mutation = new TruncateMutation('users');
57 $mutation->apply($store, [['id' => 2]]);
58
59 self::assertSame([], $store->get('users'));
60 }
61}
62