Skip to content

Commit d195445

Browse files
committed
more code coverage fixes
1 parent abcd163 commit d195445

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

lib/ezSchema.php

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -107,50 +107,39 @@ public function __call($type, $args)
107107
$numberPattern = "/".\implode('|', $numberTypes)."/i";
108108
$dateTimePattern = "/".\implode('|', $dateTimeTypes)."/i";
109109
$objectPattern = "/".\implode('|', $objectTypes)."/i";
110-
111-
$data = null;
112-
if (\preg_match($stringPattern, $type)) {
110+
111+
$store = '';
112+
$value = '';
113+
$options = '';
114+
$extra = '';
115+
if (\preg_match($stringPattern, $type)
116+
|| \preg_match($numberPattern, $type)
117+
|| \preg_match($dateTimePattern, $type)
118+
) {
113119
// check for string data type
120+
// check for whole number data type
121+
// check for date time data type
114122
$numberOrString = $args[0];
115123
$store = \is_int($numberOrString) ? '('.$numberOrString.')' : '';
116124
$store = empty($store) && !empty($numberOrString) ? ' '.$numberOrString : $store;
117125
$value = !empty($args[1]) ? ' '.$args[1] : '';
118126
$options = !empty($args[2]) ? ' '.$args[2] : '';
119127
$extra = !empty($args[3]) ? ' '.$args[3] : '';
120-
$data = $type.$store.$value.$options.$extra;
121128
} elseif (\preg_match($numericPattern, $type)) {
122129
// check for numeric data type
123-
$size = '('.(!empty($args[0]) ? $args[0] : 10 ).',';
124-
$size .= (!empty($args[1]) ? $args[1] : 2 ).')';
130+
$store = '('.(!empty($args[0]) ? $args[0] : 10 ).',';
131+
$store .= (!empty($args[1]) ? $args[1] : 2 ).')';
125132
$value = !empty($args[2]) ? ' '.$args[2] : '';
126133
$options = !empty($args[3]) ? $args[3] : '';
127134
$extra = !empty($args[4]) ? ' '.$args[4] : '';
128-
$data = $type.$size.$value.$options.$extra;
129-
} elseif (\preg_match($numberPattern, $type)) {
130-
// check for whole number data type
131-
$numberOrString = $args[0];
132-
$store = \is_int($numberOrString) ? '('.$numberOrString.')' : '';
133-
$store = empty($store) && !empty($numberOrString) ? ' '.$numberOrString : $store;
134-
$value = !empty($args[1]) ? ' '.$args[1] : '';
135-
$options = !empty($args[2]) ? ' '.$args[2] : '';
136-
$extra = !empty($args[3]) ? ' '.$args[3] : '';
137-
$data = $type.$store.$value.$options.$extra;
138-
} elseif (\preg_match($dateTimePattern, $type)) {
139-
// check for date time data type
140-
$numberOrString = $args[0];
141-
$store = \is_int($numberOrString) ? '('.$numberOrString.')' : '';
142-
$fraction = empty($store) && !empty($numberOrString) ? ' '.$numberOrString : $store;
143-
$value = !empty($args[1]) ? ' '.$args[1] : '';
144-
$options = !empty($args[2]) ? ' '.$args[2] : '';
145-
$data = $type.$fraction.$value.$options;
146135
} elseif (\preg_match($objectPattern, $type)) {
147136
// check for large object data type
148-
$value = !empty($args[0]) ? ' '.$args[0] : ' ';
149-
$data = $type.$value;
137+
$store = !empty($args[0]) ? ' '.$args[0] : ' ';
150138
} else {
151139
throw new \Exception("$type does not exist");
152140
}
153141

142+
$data = $type.$store.$value.$options.$extra;
154143
return $data;
155144
}
156145

tests/ezSchemaTest.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ public function testColumn()
7070

7171
$db = mysqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]);
7272
$result = $db->create('profile',
73-
column('id', INTR, 32, AUTO, PRIMARY),
74-
column('name', CHAR, 32, notNULL)
73+
column('id', INTR, 32, AUTO),
74+
column('name', CHAR, 32, notNULL),
75+
primary('id_pk', 'id'),
76+
index('name_dx', 'name')
7577
);
7678

7779
$this->assertEquals(0, $result);
@@ -102,6 +104,25 @@ public function test__call()
102104
$db->drop('profile');
103105
}
104106

107+
/**
108+
* @covers ezsql\ezSchema::__call
109+
*/
110+
public function test__call_Error()
111+
{
112+
if (!extension_loaded('mysqli')) {
113+
$this->markTestSkipped(
114+
'The MySQLi extension is not available.'
115+
);
116+
}
117+
118+
clearInstance();
119+
$this->assertFalse(column('id', INTR, 32, AUTO, PRIMARY));
120+
$db = mysqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]);
121+
$this->expectException(\Exception::class);
122+
$this->expectExceptionMessageRegExp('/[does not exist]/');
123+
$this->assertNull(column('id', 'DOS', 32));
124+
}
125+
105126
/**
106127
* @covers ezsql\ezSchema::vendor
107128
*/
@@ -165,4 +186,12 @@ public function testVendor_Pdo()
165186
$pdo_mysql->connect();
166187
$this->assertEquals(MYSQLI, getVendor());
167188
}
189+
190+
/**
191+
* @covers ezsql\ezSchema::__construct
192+
*/
193+
public function test__construct()
194+
{
195+
$this->assertNotNull(new ezSchema('test'));
196+
}
168197
}

0 commit comments

Comments
 (0)