Changeset 2294

Show
Ignore:
Timestamp:
03/12/2008 02:08:21 PM (8 months ago)
Author:
Geert
Message:

Single value asserts should probably have their argument called $value.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/unit_test/libraries/Unit_Test.php

    r2293 r2294  
    193193abstract class Unit_Test_Case { 
    194194 
    195         public function assert_true($expected, $debug = NULL) 
    196         { 
    197                 if ($expected != TRUE) 
    198                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true', gettype($expected), var_export($expected, TRUE)), $debug); 
    199  
    200                 return $this; 
    201         } 
    202  
    203         public function assert_true_strict($expected, $debug = NULL) 
    204         { 
    205                 if ($expected !== TRUE) 
    206                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true_strict', gettype($expected), var_export($expected, TRUE)), $debug); 
    207  
    208                 return $this; 
    209         } 
    210  
    211         public function assert_false($expected, $debug = NULL) 
    212         { 
    213                 if ($expected != FALSE) 
    214                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false', gettype($expected), var_export($expected, TRUE)), $debug); 
    215  
    216                 return $this; 
    217         } 
    218  
    219         public function assert_false_strict($expected, $debug = NULL) 
    220         { 
    221                 if ($expected !== FALSE) 
    222                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false_strict', gettype($expected), var_export($expected, TRUE)), $debug); 
     195        public function assert_true($value, $debug = NULL) 
     196        { 
     197                if ($value != TRUE) 
     198                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true', gettype($value), var_export($value, TRUE)), $debug); 
     199 
     200                return $this; 
     201        } 
     202 
     203        public function assert_true_strict($value, $debug = NULL) 
     204        { 
     205                if ($value !== TRUE) 
     206                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_true_strict', gettype($value), var_export($value, TRUE)), $debug); 
     207 
     208                return $this; 
     209        } 
     210 
     211        public function assert_false($value, $debug = NULL) 
     212        { 
     213                if ($value != FALSE) 
     214                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false', gettype($value), var_export($value, TRUE)), $debug); 
     215 
     216                return $this; 
     217        } 
     218 
     219        public function assert_false_strict($value, $debug = NULL) 
     220        { 
     221                if ($value !== FALSE) 
     222                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_false_strict', gettype($value), var_export($value, TRUE)), $debug); 
    223223 
    224224                return $this; 
     
    257257        } 
    258258 
    259         public function assert_boolean($expected, $debug = NULL) 
    260         { 
    261                 if ( ! is_bool($expected)) 
    262                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_boolean', gettype($expected), var_export($expected, TRUE)), $debug); 
    263  
    264                 return $this; 
    265         } 
    266  
    267         public function assert_not_boolean($expected, $debug = NULL) 
    268         { 
    269                 if (is_bool($expected)) 
    270                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_boolean', gettype($expected), var_export($expected, TRUE)), $debug); 
    271  
    272                 return $this; 
    273         } 
    274  
    275         public function assert_integer($expected, $debug = NULL) 
    276         { 
    277                 if ( ! is_int($expected)) 
    278                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_integer', gettype($expected), var_export($expected, TRUE)), $debug); 
    279  
    280                 return $this; 
    281         } 
    282  
    283         public function assert_not_integer($expected, $debug = NULL) 
    284         { 
    285                 if (is_int($expected)) 
    286                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_integer', gettype($expected), var_export($expected, TRUE)), $debug); 
    287  
    288                 return $this; 
    289         } 
    290  
    291         public function assert_float($expected, $debug = NULL) 
    292         { 
    293                 if ( ! is_float($expected)) 
    294                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_float', gettype($expected), var_export($expected, TRUE)), $debug); 
    295  
    296                 return $this; 
    297         } 
    298  
    299         public function assert_not_float($expected, $debug = NULL) 
    300         { 
    301                 if (is_float($expected)) 
    302                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_float', gettype($expected), var_export($expected, TRUE)), $debug); 
    303  
    304                 return $this; 
    305         } 
    306  
    307         public function assert_array($expected, $debug = NULL) 
    308         { 
    309                 if ( ! is_array($expected)) 
    310                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_array', gettype($expected), var_export($expected, TRUE)), $debug); 
    311  
    312                 return $this; 
    313         } 
    314  
    315         public function assert_not_array($expected, $debug = NULL) 
    316         { 
    317                 if (is_array($expected)) 
    318                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_array', gettype($expected), var_export($expected, TRUE)), $debug); 
    319  
    320                 return $this; 
    321         } 
    322  
    323         public function assert_object($expected, $debug = NULL) 
    324         { 
    325                 if ( ! is_object($expected)) 
    326                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_object', gettype($expected), var_export($expected, TRUE)), $debug); 
    327  
    328                 return $this; 
    329         } 
    330  
    331         public function assert_not_object($expected, $debug = NULL) 
    332         { 
    333                 if (is_object($expected)) 
    334                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_object', gettype($expected), var_export($expected, TRUE)), $debug); 
    335  
    336                 return $this; 
    337         } 
    338  
    339         public function assert_null($expected, $debug = NULL) 
    340         { 
    341                 if ($expected !== NULL) 
    342                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_null', gettype($expected), var_export($expected, TRUE)), $debug); 
    343  
    344                 return $this; 
    345         } 
    346  
    347         public function assert_not_null($expected, $debug = NULL) 
    348         { 
    349                 if ($expected === NULL) 
    350                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_null', gettype($expected), var_export($expected, TRUE)), $debug); 
    351  
    352                 return $this; 
    353         } 
    354  
    355         public function assert_empty($expected, $debug = NULL) 
    356         { 
    357                 if ( ! empty($expected)) 
    358                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($expected), var_export($expected, TRUE)), $debug); 
    359  
    360                 return $this; 
    361         } 
    362  
    363         public function assert_not_empty($expected, $debug = NULL) 
    364         { 
    365                 if (empty($expected)) 
    366                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($expected), var_export($expected, TRUE)), $debug); 
    367  
    368                 return $this; 
    369         } 
    370  
    371         public function assert_pattern($expected, $regex, $debug = NULL) 
    372         { 
    373                 if ( ! is_string($expected) OR ! is_string($regex) OR ! preg_match($regex, $expected)) 
    374                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_pattern', var_export($expected, TRUE), var_export($regex, TRUE)), $debug); 
    375  
    376                 return $this; 
    377         } 
    378  
    379         public function assert_not_pattern($expected, $regex, $debug = NULL) 
    380         { 
    381                 if ( ! is_string($expected) OR ! is_string($regex) OR preg_match($regex, $expected)) 
    382                         throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_pattern', var_export($expected, TRUE), var_export($regex, TRUE)), $debug); 
     259        public function assert_boolean($value, $debug = NULL) 
     260        { 
     261                if ( ! is_bool($value)) 
     262                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_boolean', gettype($value), var_export($value, TRUE)), $debug); 
     263 
     264                return $this; 
     265        } 
     266 
     267        public function assert_not_boolean($value, $debug = NULL) 
     268        { 
     269                if (is_bool($value)) 
     270                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_boolean', gettype($value), var_export($value, TRUE)), $debug); 
     271 
     272                return $this; 
     273        } 
     274 
     275        public function assert_integer($value, $debug = NULL) 
     276        { 
     277                if ( ! is_int($value)) 
     278                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_integer', gettype($value), var_export($value, TRUE)), $debug); 
     279 
     280                return $this; 
     281        } 
     282 
     283        public function assert_not_integer($value, $debug = NULL) 
     284        { 
     285                if (is_int($value)) 
     286                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_integer', gettype($value), var_export($value, TRUE)), $debug); 
     287 
     288                return $this; 
     289        } 
     290 
     291        public function assert_float($value, $debug = NULL) 
     292        { 
     293                if ( ! is_float($value)) 
     294                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_float', gettype($value), var_export($value, TRUE)), $debug); 
     295 
     296                return $this; 
     297        } 
     298 
     299        public function assert_not_float($value, $debug = NULL) 
     300        { 
     301                if (is_float($value)) 
     302                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_float', gettype($value), var_export($value, TRUE)), $debug); 
     303 
     304                return $this; 
     305        } 
     306 
     307        public function assert_array($value, $debug = NULL) 
     308        { 
     309                if ( ! is_array($value)) 
     310                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_array', gettype($value), var_export($value, TRUE)), $debug); 
     311 
     312                return $this; 
     313        } 
     314 
     315        public function assert_not_array($value, $debug = NULL) 
     316        { 
     317                if (is_array($value)) 
     318                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_array', gettype($value), var_export($value, TRUE)), $debug); 
     319 
     320                return $this; 
     321        } 
     322 
     323        public function assert_object($value, $debug = NULL) 
     324        { 
     325                if ( ! is_object($value)) 
     326                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_object', gettype($value), var_export($value, TRUE)), $debug); 
     327 
     328                return $this; 
     329        } 
     330 
     331        public function assert_not_object($value, $debug = NULL) 
     332        { 
     333                if (is_object($value)) 
     334                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_object', gettype($value), var_export($value, TRUE)), $debug); 
     335 
     336                return $this; 
     337        } 
     338 
     339        public function assert_null($value, $debug = NULL) 
     340        { 
     341                if ($value !== NULL) 
     342                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_null', gettype($value), var_export($value, TRUE)), $debug); 
     343 
     344                return $this; 
     345        } 
     346 
     347        public function assert_not_null($value, $debug = NULL) 
     348        { 
     349                if ($value === NULL) 
     350                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_null', gettype($value), var_export($value, TRUE)), $debug); 
     351 
     352                return $this; 
     353        } 
     354 
     355        public function assert_empty($value, $debug = NULL) 
     356        { 
     357                if ( ! empty($value)) 
     358                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($value), var_export($value, TRUE)), $debug); 
     359 
     360                return $this; 
     361        } 
     362 
     363        public function assert_not_empty($value, $debug = NULL) 
     364        { 
     365                if (empty($value)) 
     366                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_empty', gettype($value), var_export($value, TRUE)), $debug); 
     367 
     368                return $this; 
     369        } 
     370 
     371        public function assert_pattern($value, $regex, $debug = NULL) 
     372        { 
     373                if ( ! is_string($value) OR ! is_string($regex) OR ! preg_match($regex, $value)) 
     374                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug); 
     375 
     376                return $this; 
     377        } 
     378 
     379        public function assert_not_pattern($value, $regex, $debug = NULL) 
     380        { 
     381                if ( ! is_string($value) OR ! is_string($regex) OR preg_match($regex, $value)) 
     382                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug); 
    383383 
    384384                return $this;