Changeset 2293

Show
Ignore:
Timestamp:
03/12/2008 01:59:24 PM (8 months ago)
Author:
Geert
Message:

Various unit_test updates. Mainly renaming stuff to be more consistent.

Location:
trunk/modules/unit_test
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/unit_test/i18n/en_US/unit_test.php

    r2288 r2293  
    1313        'errors'               => 'Errors', 
    1414        'line'                 => 'line', 
    15         'assert_true'          => 'Expected (boolean) TRUE, but was (%s) %s.', 
    16         'assert_true_strict'   => 'Expected strictly (boolean) TRUE, but was (%s) %s.', 
    17         'assert_false'         => 'Expected (boolean) FALSE, but was (%s) %s.', 
    18         'assert_false_strict'  => 'Expected strictly (boolean) FALSE, but was (%s) %s.', 
    19         'assert_equal'         => 'Expected (%s) %s to be equal to (%s) %s.', 
    20         'assert_not_equal'     => 'Expected (%s) %s to not be equal to (%s) %s.', 
    21         'assert_identical'     => 'Expected (%s) %s to be identical to (%s) %s.', 
    22         'assert_not_identical' => 'Expected (%s) %s to not be identical to (%s) %s.', 
    23         'assert_boolean'       => 'Expected (%s) %s to be a boolean.', 
    24         'assert_not_boolean'   => 'Expected (%s) %s to not be a boolean.', 
    25         'assert_integer'       => 'Expected (%s) %s to be an integer.', 
    26         'assert_not_integer'   => 'Expected (%s) %s to not be an integer.', 
    27         'assert_float'         => 'Expected (%s) %s to be a float.', 
    28         'assert_not_float'     => 'Expected (%s) %s to not be a float.', 
    29         'assert_array'         => 'Expected (%s) %s to be an array.', 
    30         'assert_not_array'     => 'Expected (%s) %s to not be an array.', 
    31         'assert_object'        => 'Expected (%s) %s to be an object.', 
    32         'assert_not_object'    => 'Expected (%s) %s to not be an object.', 
    33         'assert_null'          => 'Expected (%s) %s to be NULL.', 
    34         'assert_not_null'      => 'Expected (%s) %s to not be NULL.', 
    35         'assert_empty'         => 'Expected (%s) %s to be empty.', 
    36         'assert_not_empty'     => 'Expected (%s) %s to not be empty.', 
    37         'assert_pattern'       => 'Expected %s to match %s.', 
    38         'assert_not_pattern'   => 'Expected %s to not match %s.', 
     15        'assert_true'          => 'assert_true: Expected true, but was given (%s) %s.', 
     16        'assert_true_strict'   => 'assert_true_strict: Expected (boolean) true, but was given (%s) %s.', 
     17        'assert_false'         => 'assert_false: Expected false, but was given (%s) %s.', 
     18        'assert_false_strict'  => 'assert_false_strict: Expected (boolean) false, but was given (%s) %s.', 
     19        'assert_equal'         => 'assert_equal: Expected (%s) %s, but was given (%s) %s.', 
     20        'assert_not_equal'     => 'assert_not_equal: Expected not (%s) %s, but was given (%s) %s.', 
     21        'assert_same'          => 'assert_same: Expected (%s) %s, but was given (%s) %s.', 
     22        'assert_not_same'      => 'assert_not_same: Expected not (%s) %s, but was given (%s) %s.', 
     23        'assert_boolean'       => 'assert_boolean: Expected a boolean, but was given (%s) %s.', 
     24        'assert_not_boolean'   => 'assert_not_boolean: Expected not a boolean, but was given (%s) %s.', 
     25        'assert_integer'       => 'assert_integer: Expected an integer, but was given (%s) %s.', 
     26        'assert_not_integer'   => 'assert_not_integer: Expected not an integer, but was given (%s) %s.', 
     27        'assert_float'         => 'assert_float: Expected a float, but was given (%s) %s.', 
     28        'assert_not_float'     => 'assert_not_float: Expected not a float, but was given (%s) %s.', 
     29        'assert_array'         => 'assert_array: Expected an array, but was given (%s) %s.', 
     30        'assert_not_array'     => 'assert_not_array: Expected not an array, but was given (%s) %s.', 
     31        'assert_object'        => 'assert_object: Expected an object, but was given (%s) %s.', 
     32        'assert_not_object'    => 'assert_not_object: Expected not an object, but was given (%s) %s.', 
     33        'assert_null'          => 'assert_null: Expected null, but was given (%s) %s.', 
     34        'assert_not_null'      => 'assert_not_null: Expected not null, but was given (%s) %s.', 
     35        'assert_empty'         => 'assert_empty: Expected an empty value, but was given (%s) %s.', 
     36        'assert_not_empty'     => 'assert_not_empty: Expected not an empty value, but was given (%s) %s.', 
     37        'assert_pattern'       => 'assert_pattern: Expected %s to match %s.', 
     38        'assert_not_pattern'   => 'assert_not_pattern: Expected %s to not match %s.', 
    3939); 
  • trunk/modules/unit_test/libraries/Unit_Test.php

    r2290 r2293  
    193193abstract class Unit_Test_Case { 
    194194 
    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); 
    223  
    224                 return $this; 
    225         } 
    226  
    227         public function assert_equal($value1, $value2, $debug = NULL) 
    228         { 
    229                 if ($value1 != $value2) 
    230                         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); 
    231  
    232                 return $this; 
    233         } 
    234  
    235         public function assert_not_equal($value1, $value2, $debug = NULL) 
    236         { 
    237                 if ($value1 == $value2) 
    238                         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); 
    239  
    240                 return $this; 
    241         } 
    242  
    243         public function assert_identical($value1, $value2, $debug = NULL) 
    244         { 
    245                 if ($value1 !== $value2) 
    246                         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); 
    247  
    248                 return $this; 
    249         } 
    250  
    251         public function assert_not_identical($value1, $value2, $debug = NULL) 
    252         { 
    253                 if ($value1 === $value2) 
    254                         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); 
    255  
    256                 return $this; 
    257         } 
    258  
    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); 
     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); 
     223 
     224                return $this; 
     225        } 
     226 
     227        public function assert_equal($expected, $actual, $debug = NULL) 
     228        { 
     229                if ($expected != $actual) 
     230                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_equal', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); 
     231 
     232                return $this; 
     233        } 
     234 
     235        public function assert_not_equal($expected, $actual, $debug = NULL) 
     236        { 
     237                if ($expected == $actual) 
     238                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_equal', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); 
     239 
     240                return $this; 
     241        } 
     242 
     243        public function assert_same($expected, $actual, $debug = NULL) 
     244        { 
     245                if ($expected !== $actual) 
     246                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_same', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); 
     247 
     248                return $this; 
     249        } 
     250 
     251        public function assert_not_same($expected, $actual, $debug = NULL) 
     252        { 
     253                if ($expected === $actual) 
     254                        throw new Kohana_Unit_Test_Exception(Kohana::lang('unit_test.assert_not_same', gettype($expected), var_export($expected, TRUE), gettype($actual), var_export($actual, TRUE)), $debug); 
     255 
     256                return $this; 
     257        } 
     258 
     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); 
    383383 
    384384                return $this; 
  • trunk/modules/unit_test/tests/Example_Test.php

    r2288 r2293  
    1212class Example_Test extends Unit_Test_Case { 
    1313 
     14        public function setup() 
     15        { 
     16                $this->setup_has_run = TRUE; 
     17        } 
     18 
     19        public function setup_test() 
     20        { 
     21                $this->assert_true_strict($this->setup_has_run); 
     22        } 
     23 
    1424        public function true_false_test() 
    1525        { 
     
    2232        } 
    2333 
    24         public function equal_identical_test() 
     34        public function equal_same_test() 
    2535        { 
    2636                $var = '5'; 
     
    2838                        ->assert_equal($var, 5) 
    2939                        ->assert_not_equal($var, 6) 
    30                         ->assert_identical($var, '5') 
    31                         ->assert_not_identical($var, 5); 
     40                        ->assert_same($var, '5') 
     41                        ->assert_not_same($var, 5); 
    3242        } 
    3343