-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathPostgresDialectTest.php
More file actions
86 lines (66 loc) · 3.02 KB
/
PostgresDialectTest.php
File metadata and controls
86 lines (66 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace DBDiff\Tests\Unit;
use PHPUnit\Framework\TestCase;
use DBDiff\SQLGen\Dialect\PostgresDialect;
class PostgresDialectTest extends TestCase
{
private PostgresDialect $dialect;
protected function setUp(): void
{
$this->dialect = new PostgresDialect();
}
// ── Quoting ───────────────────────────────────────────────────────────
public function testQuoteSimpleName(): void
{
$this->assertSame('"users"', $this->dialect->quote('users'));
}
public function testQuoteHyphenatedName(): void
{
$this->assertSame('"my-table"', $this->dialect->quote('my-table'));
}
public function testQuoteNameWithDoubleQuote(): void
{
$this->assertSame('"name""with""quotes"', $this->dialect->quote('name"with"quotes'));
}
public function testQuoteNameWithSpaces(): void
{
$this->assertSame('"table name"', $this->dialect->quote('table name'));
}
// ── Driver ────────────────────────────────────────────────────────────
public function testGetDriver(): void
{
$this->assertSame('pgsql', $this->dialect->getDriver());
}
public function testIsNotMySQLOnly(): void
{
$this->assertFalse($this->dialect->isMySQLOnly());
}
// ── DROP TRIGGER requires ON table ────────────────────────────────────
public function testDropTriggerIncludesOnTable(): void
{
$sql = $this->dialect->dropTrigger('trg_audit', 'orders');
$this->assertSame('DROP TRIGGER IF EXISTS "trg_audit" ON "orders";', $sql);
}
public function testDropTriggerQuotesSpecialNames(): void
{
$sql = $this->dialect->dropTrigger('my-trigger', 'my-table');
$this->assertSame('DROP TRIGGER IF EXISTS "my-trigger" ON "my-table";', $sql);
}
// ── DROP INDEX (schema-level, no ALTER TABLE) ─────────────────────────
public function testDropIndexNoAlterTable(): void
{
$sql = $this->dialect->dropIndex('orders', 'idx_orders_user');
$this->assertSame('DROP INDEX "idx_orders_user";', $sql);
}
// ── ADD/DROP COLUMN ───────────────────────────────────────────────────
public function testAddColumn(): void
{
$sql = $this->dialect->addColumn('users', '"phone" varchar(20) DEFAULT NULL');
$this->assertSame('ALTER TABLE "users" ADD COLUMN "phone" varchar(20) DEFAULT NULL;', $sql);
}
public function testDropColumn(): void
{
$sql = $this->dialect->dropColumn('users', 'phone');
$this->assertSame('ALTER TABLE "users" DROP COLUMN "phone";', $sql);
}
}