-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathSQLiteSchemaGrammarTest.php
More file actions
86 lines (65 loc) · 3.22 KB
/
SQLiteSchemaGrammarTest.php
File metadata and controls
86 lines (65 loc) · 3.22 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 Winter\Storm\Tests\Database\Schema\Grammars;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\SQLiteBuilder;
use Illuminate\Database\SQLiteConnection;
use Winter\Storm\Database\Schema\Grammars\SQLiteGrammar;
use Winter\Storm\Tests\GrammarTestCase;
class SQLiteSchemaGrammarTest extends GrammarTestCase
{
public function setUp(): void
{
$this->grammarClass = SQLiteGrammar::class;
$this->builderClass = SQLiteBuilder::class;
parent::setUp();
}
public function testNoInitialModifiersAddNullable()
{
$initialBlueprint = $this->getBlueprint('users');
$initialBlueprint->string('name');
$statements = $this->runBlueprint($initialBlueprint);
$this->assertSame('alter table "users" add column "name" varchar not null', $statements[0]);
$changedBlueprint = $this->getBlueprint('users');
$changedBlueprint->string('name')->nullable()->change();
$statements = $this->runBlueprint($changedBlueprint);
$this->assertStringContainsString('"name" varchar', $statements[0]);
}
public function testNullableInitialModifierAddDefault()
{
$initialBlueprint = $this->getBlueprint('users');
$initialBlueprint->string('name')->nullable();
$statements = $this->runBlueprint($initialBlueprint);
$this->assertSame('alter table "users" add column "name" varchar', $statements[0]);
$changedBlueprint = $this->getBlueprint('users');
$changedBlueprint->string('name')->default('admin')->change();
$statements = $this->runBlueprint($changedBlueprint);
$this->assertStringContainsString("varchar default 'admin'", $statements[0]);
}
public function testNullableInitialModifierAddDefaultNotNullable()
{
$initialBlueprint = $this->getBlueprint('users');
$initialBlueprint->string('name')->nullable();
$statements = $this->runBlueprint($initialBlueprint);
$this->assertSame('alter table "users" add column "name" varchar', $statements[0]);
$changedBlueprint = $this->getBlueprint('users');
$changedBlueprint->string('name')->default('admin')->nullable(false)->change();
$statements = $this->runBlueprint($changedBlueprint);
$this->assertStringContainsString("\"name\" varchar not null default 'admin'", $statements[0]);
}
public function testTypeTinyintTypeIsValid(): void
{
$pdo = new \PDO('sqlite::memory:');
$pdo->exec('CREATE TABLE users (is_active tinyint not null, name varchar not null)');
$connection = new SQLiteConnection($pdo, ':memory:', '');
$grammar = new SQLiteGrammar($connection);
$connection->setSchemaGrammar($grammar);
$blueprint = new Blueprint($connection, 'users');
$blueprint->string('name')->nullable()->change();
// Prior to the typeTinyint fix, this would throw:
// BadMethodCallException: Method SQLiteGrammar::typeTinyint does not exist
$statements = $blueprint->toSql();
// compileChange maps 'tinyint' (SQLite's introspected type_name) to 'integer'.
$this->assertNotEmpty($statements);
$this->assertStringContainsString('"is_active" integer', $statements[0]);
}
}