Changeset 2270
- Timestamp:
- 03/10/2008 09:41:45 AM (7 months ago)
- Location:
- trunk/modules/unit_test
- Files:
-
- 2 modified
-
libraries/Unit_Test.php (modified) (24 diffs)
-
tests/Example_Test.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/unit_test/libraries/Unit_Test.php
r2265 r2270 145 145 if ($value != TRUE) 146 146 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true', gettype($value), var_export($value, TRUE)), $debug); 147 148 return $this; 147 149 } 148 150 … … 151 153 if ($value !== TRUE) 152 154 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true_strict', gettype($value), var_export($value, TRUE)), $debug); 155 156 return $this; 153 157 } 154 158 … … 157 161 if ($value != FALSE) 158 162 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false', gettype($value), var_export($value, TRUE)), $debug); 163 164 return $this; 159 165 } 160 166 … … 163 169 if ($value !== FALSE) 164 170 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false_strict', gettype($value), var_export($value, TRUE)), $debug); 171 172 return $this; 165 173 } 166 174 … … 169 177 if ($value1 != $value2) 170 178 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_equal', gettype($value1), var_export($value1, TRUE), gettype($value2), var_export($value2, TRUE)), $debug); 179 180 return $this; 171 181 } 172 182 … … 175 185 if ($value1 == $value2) 176 186 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_equal', gettype($value1), var_export($value1, TRUE), gettype($value2), var_export($value2, TRUE)), $debug); 187 188 return $this; 177 189 } 178 190 … … 181 193 if ($value1 !== $value2) 182 194 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_identical', gettype($value1), var_export($value1, TRUE), gettype($value2), var_export($value2, TRUE)), $debug); 195 196 return $this; 183 197 } 184 198 … … 187 201 if ($value1 === $value2) 188 202 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_identical', gettype($value1), var_export($value1, TRUE), gettype($value2), var_export($value2, TRUE)), $debug); 203 204 return $this; 189 205 } 190 206 … … 193 209 if ( ! is_bool($value)) 194 210 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_boolean', gettype($value), var_export($value, TRUE)), $debug); 211 212 return $this; 195 213 } 196 214 … … 199 217 if (is_bool($value)) 200 218 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_boolean', gettype($value), var_export($value, TRUE)), $debug); 219 220 return $this; 201 221 } 202 222 … … 205 225 if ( ! is_int($value)) 206 226 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_integer', gettype($value), var_export($value, TRUE)), $debug); 227 228 return $this; 207 229 } 208 230 … … 211 233 if (is_int($value)) 212 234 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_integer', gettype($value), var_export($value, TRUE)), $debug); 235 236 return $this; 213 237 } 214 238 … … 217 241 if ( ! is_float($value)) 218 242 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_float', gettype($value), var_export($value, TRUE)), $debug); 243 244 return $this; 219 245 } 220 246 … … 223 249 if (is_float($value)) 224 250 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_float', gettype($value), var_export($value, TRUE)), $debug); 251 252 return $this; 225 253 } 226 254 … … 229 257 if ( ! is_array($value)) 230 258 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_array', gettype($value), var_export($value, TRUE)), $debug); 259 260 return $this; 231 261 } 232 262 … … 235 265 if (is_array($value)) 236 266 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_array', gettype($value), var_export($value, TRUE)), $debug); 267 268 return $this; 237 269 } 238 270 … … 241 273 if ( ! is_object($value)) 242 274 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_object', gettype($value), var_export($value, TRUE)), $debug); 275 276 return $this; 243 277 } 244 278 … … 247 281 if (is_object($value)) 248 282 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_object', gettype($value), var_export($value, TRUE)), $debug); 283 284 return $this; 249 285 } 250 286 … … 253 289 if ($value !== NULL) 254 290 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_null', gettype($value), var_export($value, TRUE)), $debug); 291 292 return $this; 255 293 } 256 294 … … 259 297 if ($value === NULL) 260 298 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_null', gettype($value), var_export($value, TRUE)), $debug); 299 300 return $this; 261 301 } 262 302 … … 265 305 if ( ! empty($value)) 266 306 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($value), var_export($value, TRUE)), $debug); 307 308 return $this; 267 309 } 268 310 … … 271 313 if (empty($value)) 272 314 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($value), var_export($value, TRUE)), $debug); 315 316 return $this; 273 317 } 274 318 … … 277 321 if ( ! is_string($value) OR ! is_string($regex) OR ! preg_match($regex, $value)) 278 322 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug); 323 324 return $this; 279 325 } 280 326 … … 283 329 if ( ! is_string($value) OR ! is_string($regex) OR preg_match($regex, $value)) 284 330 throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug); 331 332 return $this; 285 333 } 286 334 -
trunk/modules/unit_test/tests/Example_Test.php
r2267 r2270 15 15 { 16 16 $var = TRUE; 17 $this->assert_true($var); 18 $this->assert_true_strict($var); 19 $this->assert_false( ! $var); 20 $this->assert_false_strict( ! $var); 17 $this 18 ->assert_true($var) 19 ->assert_true_strict($var) 20 ->assert_false( ! $var) 21 ->assert_false_strict( ! $var); 21 22 } 22 23 … … 24 25 { 25 26 $var = '5'; 26 $this->assert_equal($var, 5); 27 $this->assert_not_equal($var, 6); 28 $this->assert_identical($var, '5'); 29 $this->assert_not_identical($var, 5); 27 $this 28 ->assert_equal($var, 5) 29 ->assert_not_equal($var, 6) 30 ->assert_identical($var, '5') 31 ->assert_not_identical($var, 5); 30 32 } 31 33 32 34 public function type_test() 33 35 { 34 $this->assert_boolean(TRUE); 35 $this->assert_not_boolean('TRUE'); 36 $this->assert_integer(123); 37 $this->assert_not_integer('123'); 38 $this->assert_float(1.23); 39 $this->assert_not_float(123); 40 $this->assert_array(array(1, 2, 3)); 41 $this->assert_not_array('array()'); 42 $this->assert_object(new stdClass); 43 $this->assert_not_object('X'); 44 $this->assert_null(NULL); 45 $this->assert_not_null(0); 46 $this->assert_empty('0'); 47 $this->assert_not_empty('1'); 36 $this 37 ->assert_boolean(TRUE) 38 ->assert_not_boolean('TRUE') 39 ->assert_integer(123) 40 ->assert_not_integer('123') 41 ->assert_float(1.23) 42 ->assert_not_float(123) 43 ->assert_array(array(1, 2, 3)) 44 ->assert_not_array('array()') 45 ->assert_object(new stdClass) 46 ->assert_not_object('X') 47 ->assert_null(NULL) 48 ->assert_not_null(0) 49 ->assert_empty('0') 50 ->assert_not_empty('1'); 48 51 } 49 52 … … 51 54 { 52 55 $var = "Kohana\n"; 53 $this->assert_pattern($var, '/^Kohana$/'); 54 $this->assert_not_pattern($var, '/^Kohana$/D'); 56 $this 57 ->assert_pattern($var, '/^Kohana$/') 58 ->assert_not_pattern($var, '/^Kohana$/D'); 55 59 } 56 60
