forked from tursodatabase/libsql-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTursoSchemaBuilderTest.php
127 lines (101 loc) · 4.54 KB
/
TursoSchemaBuilderTest.php
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
afterEach(function () {
Schema::dropAllTables();
Schema::dropAllViews();
});
test('it can drops all tables from the database.', function () {
DB::statement('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
Schema::dropAllTables();
$response = DB::select('SELECT * FROM sqlite_schema WHERE type = ? AND name NOT LIKE ?', ['table', 'sqlite_%']);
expect($response)->toBe([]);
})->group('TursoSchemaBuilderTest', 'FeatureTest');
test('it can retrieve all of the table information in the database', function () {
DB::select('CREATE TABLE "migrations" ("id" integer primary key autoincrement not null, "migration" varchar not null, "batch" integer not null)');
$result = Schema::getTables()[0];
expect($result['name'])->toBe('migrations')
->and($result['schema'])->toBeNull()
->and($result['comment'])->toBeNull()
->and($result['collation'])->toBeNull()
->and($result['engine'])->toBeNull();
})->group('TursoSchemaBuilderTest', 'FeatureTest');
test('it can retrieve all of the column information in the table', function () {
DB::select('CREATE TABLE "migrations" ("id" integer primary key autoincrement not null, "migration" varchar not null, "batch" integer not null)');
$result = collect(Schema::getColumns('migrations'))->keyBy('name');
expect($result->count())->toBe(3)
->and($result->has('id'))->toBeTrue()
->and($result->has('migration'))->toBeTrue()
->and($result->has('batch'))->toBeTrue()
->and($result->get('id'))->toBe([
'name' => 'id',
'type_name' => 'integer',
'type' => 'integer',
'collation' => null,
'nullable' => false,
'default' => null,
'auto_increment' => true,
'comment' => null,
'generation' => null,
])
->and($result->get('migration'))->toBe([
'name' => 'migration',
'type_name' => 'varchar',
'type' => 'varchar',
'collation' => null,
'nullable' => false,
'default' => null,
'auto_increment' => false,
'comment' => null,
'generation' => null,
])
->and($result->get('batch'))->toBe([
'name' => 'batch',
'type_name' => 'integer',
'type' => 'integer',
'collation' => null,
'nullable' => false,
'default' => null,
'auto_increment' => false,
'comment' => null,
'generation' => null,
]);
})->group('TursoSchemaBuilderTest', 'FeatureTest');
test('it can create a new table', function () {
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
});
$result = Schema::getTables()[0];
expect($result['name'])->toBe('users')
->and($result['schema'])->toBeNull()
->and($result['comment'])->toBeNull()
->and($result['collation'])->toBeNull()
->and($result['engine'])->toBeNull();
$columns = collect(Schema::getColumns('users'))->keyBy('name')->keys()->all();
expect($columns)->toBe(['id', 'name']);
})->group('TursoSchemaBuilderTest', 'FeatureTest');
test('it can alter an existing table.', function () {
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
});
Schema::table('users', function (Blueprint $table) {
$table->string('email')->after('name');
});
expect(Schema::hasColumn('users', 'email'))->toBeTrue()
->and(Schema::hasColumns('users', ['id', 'name', 'email']))->toBeTrue()
->and(Schema::getColumnType('users', 'email'))->toBe('varchar')
->and(Schema::getColumnListing('users'))->toBe(['id', 'name', 'email']);
})->group('TursoSchemaBuilderTest', 'FeatureTest');
test('it can drop all views from the database', function () {
$createSql = 'CREATE VIEW foo (id) AS SELECT 1';
DB::statement($createSql);
$view = collect(Schema::getViews())->first();
expect($view['name'])->toBe('foo')
->and($view['schema'])->toBeNull()
->and($view['definition'])->toBe($createSql);
Schema::dropAllViews();
expect(Schema::getViews())->toBe([]);
})->group('TursoSchemaBuilderTest', 'FeatureTest');