Пример #1
0
 public function null_carries_no_type_information()
 {
     $add_five_to_argument = function ($argument, SimpleCalculator $calculator = null) {
         if (!$calculator) {
             $calculator = new SimpleCalculator();
         }
         return $calculator->add(5, $argument);
     };
     assert_that($add_five_to_argument(10))->is_identical_to(__);
     assert_that($add_five_to_argument(10), new SimpleCalculator())->is_identical_to(__);
     // try removing the "= null" default value assignment and see what happens
     assert_that($add_five_to_argument(10), null)->is_identical_to(__);
 }
Пример #2
0
 public function objects_can_have_methods()
 {
     $calculator = new SimpleCalculator();
     assert_that($calculator->add(1, 2))->is_identical_to(__);
 }