@@ -21,6 +21,7 @@ class SchemaTest extends TestCase{
21
21
public function test00 () {
22
22
$ connInfo = new ConnectionInfo ('mysql ' ,'root ' , '123456 ' , 'testing_db ' , '127.0.0.1 ' );
23
23
$ s = new Database ($ connInfo );
24
+ $ this ->assertEquals ('testing_db ' , $ s ->getName ());
24
25
$ table = new MySQLTable ('hello ' );
25
26
$ table ->addColumn ('user-id ' , new MySQLColumn ('user_id ' , 'int ' , 11 ));
26
27
$ this ->assertEquals ('int ' ,$ table ->getColByKey ('user-id ' )->getDatatype ());
@@ -109,4 +110,76 @@ public function test01() {
109
110
$ s ->page (5 , 40 );
110
111
$ this ->assertEquals ("select * from `hello` where `hello`.`user_id` = 31 and `hello`.`user_id` < 44 and `hello`.`username` != 'Ibrahim' limit 40 offset 200 " ,$ s ->getLastQuery ());
111
112
}
113
+ /**
114
+ * @test
115
+ */
116
+ public function test02 () {
117
+ $ connInfo = new ConnectionInfo ('mysql ' ,'root ' , '123456 ' , 'testing_db ' , '127.0.0.1 ' );
118
+ $ s = new Database ($ connInfo );
119
+
120
+ $ s ->table (HelloTable::class);
121
+ $ this ->assertFalse ($ s ->addTable (new HelloTable ()));
122
+ }
123
+ /**
124
+ * @test
125
+ */
126
+ public function test03 () {
127
+ $ connInfo = new ConnectionInfo ('mysql ' ,'root ' , '123456 ' , 'testing_db ' , '127.0.0.1 ' );
128
+ $ s = new Database ($ connInfo );
129
+
130
+ $ s ->table (HelloTable::class);
131
+ $ s ->delete ();
132
+ $ this ->assertEquals ("delete from `hello` " , $ s ->getLastQuery ());
133
+ }
134
+ /**
135
+ * @test
136
+ */
137
+ public function test04 () {
138
+ $ connInfo = new ConnectionInfo ('mysql ' ,'root ' , '123456 ' , 'testing_db ' , '127.0.0.1 ' );
139
+ $ s = new Database ($ connInfo );
140
+
141
+ $ s ->table (HelloTable::class);
142
+ $ s ->drop ();
143
+ $ this ->assertEquals ("drop table `hello`; " , $ s ->getLastQuery ());
144
+ $ s ->select ();
145
+ $ this ->assertEquals ("select * from `hello` " , $ s ->getLastQuery ());
146
+ $ s ->limit (50 );
147
+ $ s ->offset (20 );
148
+ $ this ->assertEquals ("select * from `hello` limit 50 offset 20 " , $ s ->getLastQuery ());
149
+
150
+ $ s ->insert ([
151
+ 'user-id ' => 33 ,
152
+ 'username ' => 'Ibrahim ' ,
153
+ 'pass ' => 'rand_pass '
154
+ ]);
155
+ $ this ->assertEquals ('insert into `hello` (`user_id`, `username`, `password`) '
156
+ . "values (33, 'Ibrahim', 'rand_pass'); " , $ s ->getLastQuery ());
157
+ }
158
+ /**
159
+ * @test
160
+ */
161
+ public function test05 () {
162
+ $ connInfo = new ConnectionInfo ('mysql ' ,'root ' , '123456 ' , 'testing_db ' , '127.0.0.1 ' );
163
+ $ s = new Database ($ connInfo );
164
+ $ this ->assertEquals ([
165
+ 'message ' => '' ,
166
+ 'code ' => 0
167
+ ], $ s ->getLastError ());
168
+ }
169
+ /**
170
+ * @test
171
+ */
172
+ public function test06 () {
173
+ $ connInfo = new ConnectionInfo ('mysql ' ,'root ' , '123456 ' , 'testing_db ' , '127.0.0.1 ' );
174
+ $ s = new Database ($ connInfo );
175
+ try {
176
+ $ s ->table (HelloTable::class)->drop ()->execute ();
177
+ } catch (\Exception $ ex ) {
178
+ $ this ->assertEquals ([
179
+ 'message ' => "Unknown table 'testing_db.hello' " ,
180
+ 'code ' => 1051
181
+ ], $ s ->getLastError ());
182
+ }
183
+
184
+ }
112
185
}
0 commit comments