Skip to content

Commit ed9da8c

Browse files
authored
Merge pull request #25 from WebFiori/dev
Dev
2 parents 7b935d6 + 89acc6f commit ed9da8c

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

tests/webfiori/database/tests/common/SchemaTest.php

+73
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class SchemaTest extends TestCase{
2121
public function test00() {
2222
$connInfo = new ConnectionInfo('mysql','root', '123456', 'testing_db', '127.0.0.1');
2323
$s = new Database($connInfo);
24+
$this->assertEquals('testing_db', $s->getName());
2425
$table = new MySQLTable('hello');
2526
$table->addColumn('user-id', new MySQLColumn('user_id', 'int', 11));
2627
$this->assertEquals('int',$table->getColByKey('user-id')->getDatatype());
@@ -109,4 +110,76 @@ public function test01() {
109110
$s->page(5, 40);
110111
$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());
111112
}
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+
}
112185
}

webfiori/database/AbstractQuery.php

-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,6 @@ public function reset() {
795795
$this->lastQueryType = '';
796796
$this->limit = -1;
797797
$this->offset = -1;
798-
$this->associatedTbl = null;
799798
}
800799
/**
801800
* Perform a right join query.

0 commit comments

Comments
 (0)