packages/sql-semantics-mysql/tests/Unit/Lowering/Server/Storage/StorageOptionRuleTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Lowering\Server\Storage;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Lowering\Server\Storage\StorageOptionRule;
11use SqlSemantics\Platform\MySql\Semantics;
12
13#[CoversClass(StorageOptionRule::class)]
14#[Medium]
15final class StorageOptionRuleTest extends TestCase
16{
17 public function testOptionsFlattensTheListsWithAndWithoutCommas(): void
18 {
19 self::assertSame("CREATE LOGFILE GROUP g ADD UNDOFILE 'u' INITIAL_SIZE 1 UNDO_BUFFER_SIZE 2 REDO_BUFFER_SIZE 3 NODEGROUP 4 WAIT COMMENT 'c'", (new Semantics('mysql-5.6.51'))->analyze("create logfile group g add undofile 'u' initial_size 1, undo_buffer_size 2 redo_buffer_size 3, nodegroup 4 wait comment 'c'")->toString());
20 }
21
22 public function testOptionLowersEveryOptionOf80(): void
23 {
24 self::assertSame("CREATE TABLESPACE ts ADD DATAFILE 'f' AUTOEXTEND_SIZE `4M` EXTENT_SIZE 1 NODEGROUP 2 FILE_BLOCK_SIZE 3 ENCRYPTION 'N' ENGINE_ATTRIBUTE '{}' NO_WAIT", (new Semantics())->analyze("create tablespace ts add datafile 'f' autoextend_size 4M, extent_size 1 nodegroup 2 file_block_size 3 encryption 'N' engine_attribute '{}' no_wait")->toString());
25 }
26
27 public function testValueSkipsTheEqualsSign(): void
28 {
29 self::assertSame("CREATE TABLESPACE ts ADD DATAFILE 'f' COMMENT 'c'", (new Semantics('mysql-5.7.44'))->analyze("create tablespace ts add datafile 'f' comment = 'c'")->toString());
30 }
31
32 public function testEngineSkipsStorage(): void
33 {
34 self::assertSame('DROP TABLESPACE ts ENGINE innodb', (new Semantics('mysql-9.1.0'))->analyze('drop tablespace ts storage engine = innodb')->toString());
35 }
36}
37