Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.

Commit 60ad2d4

Browse files
committed
Updated to 1.1.6 version
1 parent b815ca5 commit 60ad2d4

4 files changed

Lines changed: 144 additions & 4 deletions

File tree

src/Database/Database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class Database {
9696
'data' => null, // array → columns and values
9797
'table' => null, // string → database table name
9898
'order' => null, // mixed → order clause
99+
'charset' => null, // string → database charset
99100
'limit' => null, // int → limit clause
100101
'where' => null, // mixed → where clause
101102
'engine' => null, // string → database engine

src/Database/Provider/PDOprovider/PDOprovider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function create($table, $data, $foreing, $reference, $on, $actions, $engi
181181
$index = '';
182182
$references = '';
183183

184-
if (!is_null($foreing, $reference, $on) && count($foreing) === count($on) && count($reference) === count($foreing)) {
184+
if (!is_null($foreing) && !is_null($reference) && !is_null($on) && count($foreing) === count($on) && count($reference) === count($foreing)) {
185185

186186
$count = count($foreing);
187187

@@ -206,7 +206,7 @@ public function create($table, $data, $foreing, $reference, $on, $actions, $engi
206206

207207
$engine = (!is_null($engine)) ? ' ENGINE=' . $engine : '';
208208

209-
$charset = (!is_null($engine)) ? ' CHARSET=' . $charset : '';
209+
$charset = (!is_null($charset)) ? ' CHARSET=' . $charset : '';
210210

211211
$query = $query . $index . $references;
212212

tests/Database/Test/DatabaseConnectionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,4 @@ public function testExceptionAccessDeniedForUserName() {
212212
array('charset' => 'utf8')
213213
);
214214
}
215-
216215
}

tests/Database/Test/DatabaseCreateTest.php

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class DatabaseCreateTest extends TestCase {
2222
*
2323
* @since 1.1.6
2424
*
25-
* @return void
25+
* @return object → database connection
2626
*/
2727
public function testGetConnection() {
2828

@@ -58,4 +58,144 @@ public function testCreateTableQuery($db) {
5858
$this->assertTrue($result);
5959
}
6060

61+
/**
62+
* [QUERY] [CREATE TABLE] [EXCEPTION] [SINTAX ERROR]
63+
*
64+
* @since 1.1.6
65+
*
66+
* @depends testGetConnection
67+
*
68+
* @expectedException Josantonius\Database\Exception\DBException
69+
*
70+
* @expectedExceptionMessage Syntax error or access violation
71+
*
72+
* @return void
73+
*/
74+
public function testCreateTableQueryError($db) {
75+
76+
$result = $db->query(
77+
78+
'CREATE TABLE IF NOT EXISTS test (
79+
80+
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
81+
name VARCHAR(30) NOT NULL,
82+
email VARCHAR(50),
83+
reg_date TIMESTAMP
84+
'
85+
);
86+
}
87+
88+
/**
89+
* [METHOD] [CREATE TABLE] [RETURN TRUE]
90+
*
91+
* @since 1.1.6
92+
*
93+
* @depends testGetConnection
94+
*
95+
* @return void
96+
*/
97+
public function testCreateTableMethod($db) {
98+
99+
$params = [
100+
101+
'id' => 'INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY',
102+
'name' => 'VARCHAR(30) NOT NULL',
103+
'email' => 'VARCHAR(50)',
104+
'reg_date' => 'TIMESTAMP'
105+
];
106+
107+
$this->assertTrue($db->create($params)->table('test')->execute());
108+
}
109+
110+
/**
111+
* [METHOD] [CREATE TABLE] [EXCEPTION] [SINTAX ERROR]
112+
*
113+
* @since 1.1.6
114+
*
115+
* @depends testGetConnection
116+
*
117+
* @expectedException Josantonius\Database\Exception\DBException
118+
*
119+
* @expectedExceptionMessage Syntax error or access violation
120+
*
121+
* @return void
122+
*/
123+
public function testCreateTableMethodError($db) {
124+
125+
$params = [
126+
127+
'id' => 'INT(6 UNSIGNED AUTO_INCREMENT PRIMARY KEY',
128+
'name' => 'VARCHAR(30) NOT NULL',
129+
'email' => 'VARCHAR(50)',
130+
'reg_date' => 'TIMESTAMP'
131+
];
132+
133+
$db->create($params)->table('test')->execute();
134+
}
135+
136+
/**
137+
* [METHOD] [CREATE TABLE] [RETURN TRUE]
138+
*
139+
* @since 1.1.6
140+
*
141+
* @depends testGetConnection
142+
*
143+
* @return void
144+
*/
145+
public function testCreateTableMethod2($db) {
146+
147+
$params = [
148+
149+
'id' => 'INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY',
150+
'name' => 'VARCHAR(30) NOT NULL',
151+
'email' => 'VARCHAR(50)',
152+
'reg_date' => 'TIMESTAMP'
153+
];
154+
155+
$query = $db->create($params)
156+
->table('test_2')
157+
->foreing('id')
158+
->reference('id')
159+
->on('test')
160+
->actions('ON DELETE CASCADE ON UPDATE CASCADE')
161+
->engine('innodb')
162+
->charset('utf8');
163+
164+
$this->assertTrue($query->execute());
165+
}
166+
167+
/**
168+
* [METHOD] [CREATE TABLE] [EXCEPTION] [SINTAX ERROR]
169+
*
170+
* @since 1.1.6
171+
*
172+
* @depends testGetConnection
173+
*
174+
* @expectedException Josantonius\Database\Exception\DBException
175+
*
176+
* @expectedExceptionMessage Syntax error or access violation
177+
*
178+
* @return void
179+
*/
180+
public function testCreateTableMethod2Error($db) {
181+
182+
$params = [
183+
184+
'id' => 'INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY',
185+
'name' => 'VARCHAR(30) NOT NULL',
186+
'email' => 'VARCHAR(50)',
187+
'reg_date' => 'TIMESTAMP'
188+
];
189+
190+
$query = $db->create($params)
191+
->table('test_2')
192+
->foreing('id')
193+
->reference('id')
194+
->on('test')
195+
->actions('ONDELETE CASCADE ON UPDATE CASCADE')
196+
->engine('innodb')
197+
->charset('utf8');
198+
199+
$query->execute();
200+
}
61201
}

0 commit comments

Comments
 (0)