|
8 | 8 | class SchemaTest extends TestCase
|
9 | 9 | {
|
10 | 10 |
|
11 |
| - public function testTest() |
| 11 | + // public function testTest() |
| 12 | + // { |
| 13 | + // $table = new Schema('users9'); |
| 14 | + // $table->id(); |
| 15 | + // $table->integer('age',3); |
| 16 | + // $table->integer('amount'); |
| 17 | + // $table->bigInt('credit')->default(0)->nullable(); |
| 18 | + // $table->tinyInt('credit2')->nullable(); |
| 19 | + // $table->smallInt('credit3')->nullable(); |
| 20 | + // $table->mediumInt('credit4')->nullable(); |
| 21 | + // $table->text('note')->default('is empty'); |
| 22 | + // $table->tinyText('note3'); |
| 23 | + // $table->string('username'); |
| 24 | + // $table->string('password', 150); |
| 25 | + // $table->timestamps(); |
| 26 | + |
| 27 | + // $table->create(); |
| 28 | + // } |
| 29 | + |
| 30 | + public function testDropOldTestTables() |
12 | 31 | {
|
13 |
| - $table = new Schema('users9'); |
14 |
| - $table->id(); |
15 |
| - $table->integer('age',3); |
16 |
| - $table->integer('amount'); |
17 |
| - $table->bigInt('credit')->default(0)->nullable(); |
18 |
| - $table->tinyInt('credit2')->nullable(); |
19 |
| - $table->smallInt('credit3')->nullable(); |
20 |
| - $table->mediumInt('credit4')->nullable(); |
21 |
| - $table->text('note')->default('is empty'); |
22 |
| - $table->tinyText('note3'); |
23 |
| - $table->string('username'); |
24 |
| - $table->string('password', 150); |
25 |
| - $table->timestamps(); |
26 |
| - |
27 |
| - $table->create(); |
| 32 | + (new Schema('users'))->drop(); |
| 33 | + (new Schema('books'))->drop(); |
| 34 | + (new Schema('categorys'))->drop(); |
| 35 | + |
| 36 | + |
| 37 | + $tables = DB::query('SHOW TABLES;', [], true); |
| 38 | + $this->assertCount(0, $tables); |
28 | 39 | }
|
29 | 40 |
|
30 |
| - // public function testDropOldTestTables() |
31 |
| - // { |
32 |
| - // (new Schema('users'))->drop(); |
33 |
| - // (new Schema('books'))->drop(); |
34 |
| - // (new Schema('categorys'))->drop(); |
| 41 | + public function testCreatedTables() |
| 42 | + { |
35 | 43 |
|
| 44 | + $table = new Schema('users'); |
| 45 | + $table->id(); |
| 46 | + $table->string('name')->utf8mb4(); |
| 47 | + $table->string('phone'); |
| 48 | + $table->string('fax'); |
| 49 | + $table->boolean('status'); |
| 50 | + $table->integer('age', 3)->nullable(); |
| 51 | + $table->dateTime('register')->nullable(); |
| 52 | + $table->timestamps(); |
| 53 | + $table->create(); |
| 54 | + |
| 55 | + $table = new Schema('books'); |
| 56 | + $table->id(); |
| 57 | + $table->string('code'); |
| 58 | + $table->integer('user_id'); |
| 59 | + $table->string('title')->utf8mb4(); |
| 60 | + $table->text('text')->utf8mb4(); |
| 61 | + $table->integer('amount'); |
| 62 | + $table->integer('price'); |
| 63 | + $table->timestamps(); |
| 64 | + $table->create(); |
| 65 | + |
| 66 | + |
| 67 | + $table = new Schema('categorys'); |
| 68 | + $table->id(); |
| 69 | + $table->string('name')->utf8mb4(); |
| 70 | + $table->timestamps(); |
| 71 | + $table->create(); |
| 72 | + |
| 73 | + $tables = DB::query('SHOW TABLES;', [], true); |
| 74 | + $this->assertCount(3, $tables); |
| 75 | + |
| 76 | + |
| 77 | + $users_columns = DB::query('SHOW COLUMNS FROM users', [] , true); |
| 78 | + foreach($users_columns as $column){ |
| 79 | + if($column->Field== 'name'){ |
| 80 | + $this->assertEquals('NO', $column->Null, 'The name type must not be null'); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
36 | 84 |
|
37 |
| - // $tables = DB::query('SHOW TABLES;', [], true); |
38 |
| - // $this->assertCount(0, $tables); |
39 |
| - // } |
40 | 85 |
|
41 |
| - // public function testCreatedTables() |
42 |
| - // { |
| 86 | + public function testAddNewColumnToUsersTable(){ |
| 87 | + $table = new Schema('users'); |
| 88 | + $res = $table->addColumn()->boolean('active')->after('register')->default(1)->change(); |
43 | 89 |
|
44 |
| - // $table = new Schema('users'); |
45 |
| - // $table->id(); |
46 |
| - // $table->string('name')->utf8mb4(); |
47 |
| - // $table->string('phone'); |
48 |
| - // $table->string('fax'); |
49 |
| - // $table->boolean('status'); |
50 |
| - // $table->integer('age', 3); |
51 |
| - // $table->dateTime('register')->nullable(); |
52 |
| - // $table->timestamps(); |
53 |
| - // $table->create(); |
54 |
| - |
55 |
| - // $table = new Schema('books'); |
56 |
| - // $table->id(); |
57 |
| - // $table->string('code'); |
58 |
| - // $table->integer('user_id'); |
59 |
| - // $table->string('title')->utf8mb4(); |
60 |
| - // $table->text('text')->utf8mb4(); |
61 |
| - // $table->integer('amount'); |
62 |
| - // $table->integer('price'); |
63 |
| - // $table->timestamps(); |
64 |
| - // $table->create(); |
65 |
| - |
66 |
| - |
67 |
| - // $table = new Schema('categorys'); |
68 |
| - // $table->id(); |
69 |
| - // $table->string('name')->utf8mb4(); |
70 |
| - // $table->timestamps(); |
71 |
| - // $table->create(); |
72 |
| - |
73 |
| - // $tables = DB::query('SHOW TABLES;', [], true); |
74 |
| - // $this->assertCount(3, $tables); |
75 |
| - |
76 |
| - |
77 |
| - // $users_columns = DB::query('SHOW COLUMNS FROM users', [] , true); |
78 |
| - // foreach($users_columns as $column){ |
79 |
| - // if($column->Field== 'name'){ |
80 |
| - // echo "\n".json_encode($column)."\n"; |
81 |
| - // $this->assertEquals('NO', $column->Null, 'The name type must not be null'); |
82 |
| - // } |
83 |
| - // } |
84 |
| - // } |
| 90 | + $columns = DB::query('SHOW COLUMNS FROM `users`', [], true); |
85 | 91 |
|
| 92 | + $status = false; |
| 93 | + $check_after = ''; |
| 94 | + foreach($columns as $column){ |
| 95 | + if($column->Field == 'active' && $check_after == 'register'){ |
| 96 | + $status = true; |
| 97 | + break; |
| 98 | + } |
| 99 | + $check_after = $column->Field; |
| 100 | + } |
86 | 101 |
|
87 |
| - // public function testAddNewColumnToUsersTable(){ |
88 |
| - // $table = new Schema('users'); |
89 |
| - // $res = $table->addColumn()->boolean('active')->after('register')->default(1)->change(); |
| 102 | + $this->assertTrue($status); |
| 103 | + } |
90 | 104 |
|
91 |
| - // $columns = DB::query('SHOW COLUMNS FROM `users`', [], true); |
92 | 105 |
|
93 |
| - // $status = false; |
94 |
| - // $check_after = ''; |
95 |
| - // foreach($columns as $column){ |
96 |
| - // if($column->Field == 'active' && $check_after == 'register'){ |
97 |
| - // $status = true; |
98 |
| - // break; |
99 |
| - // } |
100 |
| - // $check_after = $column->Field; |
101 |
| - // } |
| 106 | + public function testRenameColumn(){ |
| 107 | + $table = new Schema('users'); |
| 108 | + $table->renameColumn('fax')->string('email', 150)->nullable()->change(); |
102 | 109 |
|
103 |
| - // $this->assertTrue($status); |
104 |
| - // } |
| 110 | + $columns = DB::query('SHOW COLUMNS FROM `users`', [], true); |
105 | 111 |
|
| 112 | + $status = false; |
106 | 113 |
|
107 |
| - // public function testRenameColumn(){ |
108 |
| - // $table = new Schema('users'); |
109 |
| - // $table->renameColumn('fax')->string('email', 150)->nullable()->change(); |
| 114 | + foreach($columns as $column){ |
| 115 | + if($column->Field == 'email'){ |
| 116 | + $status = true; |
| 117 | + break; |
| 118 | + } |
| 119 | + } |
110 | 120 |
|
111 |
| - // $columns = DB::query('SHOW COLUMNS FROM `users`', [], true); |
| 121 | + $this->assertTrue($status); |
| 122 | + } |
112 | 123 |
|
113 |
| - // $status = false; |
114 | 124 |
|
115 |
| - // foreach($columns as $column){ |
116 |
| - // if($column->Field == 'email'){ |
117 |
| - // $status = true; |
118 |
| - // break; |
119 |
| - // } |
120 |
| - // } |
| 125 | + public function testAddIndex(){ |
| 126 | + $table = new Schema('users'); |
| 127 | + $table->addIndex('phone',['phone'], Schema::INDEX_UNIQUE)->change(); |
121 | 128 |
|
122 |
| - // $this->assertTrue($status); |
123 |
| - // } |
| 129 | + $columns = DB::query('SHOW COLUMNS FROM `users`', [], true); |
| 130 | + |
| 131 | + $status = false; |
| 132 | + |
| 133 | + foreach($columns as $column){ |
| 134 | + if($column->Field == 'phone' && $column->Key=='UNI'){ |
| 135 | + $status = true; |
| 136 | + break; |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + $this->assertTrue($status); |
| 141 | + } |
124 | 142 |
|
125 | 143 | }
|
126 | 144 |
|
|
0 commit comments