packages/sql-semantics-sqlite/tests/Unit/Model/Statement/SnapshotTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Model\Statement;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\Sqlite\Model\Statement\Snapshot;
12
13#[CoversClass(Snapshot::class)]
14#[Small]
15final class SnapshotTest extends TestCase
16{
17    public function testCloningIsRefused(): void
18    {
19        $name = new Name('id');
20
21        $this->expectExceptionMessage('Semantic values cannot be cloned.');
22
23        self::assertNotSame($name, clone $name);
24    }
25
26    public function testSerializationIsRefused(): void
27    {
28        $name = new Name('id');
29
30        $this->expectExceptionMessage('Semantic values must be constructed, not serialized.');
31
32        serialize($name);
33    }
34
35    public function testRestorationWithoutConstructionIsRefused(): void
36    {
37        $this->expectExceptionMessage('Semantic values cannot be restored without construction.');
38
39        unserialize(sprintf('O:%d:"%s":1:{s:5:"value";s:2:"id";}', strlen(Name::class), Name::class));
40    }
41}
42