Ejemplo n.º 1
0
 public function the_comprehension_comprehension_errors_when_a_null_is_returned()
 {
     $simple = new SimpleCalculator();
     try {
         $value = (new MaybeComprehension($simple))->eulers_number()->negate()->multiply(10)->factorial()->_maybe_resolve();
         fail("Should not reach here");
     } catch (UnexpectedValueException $e) {
     }
     assert_that(get_class($e))->is_equal_to('UnexpectedValueException');
 }
Ejemplo n.º 2
0
 /**
  * Exercise II. Reverse Arrays.
  *
  * In this exercise you'll need to implement the methods in
  * classes/ReverseArray.php
  *
  * Implementing custom classes that have array operators can be very useful.
  * Sometimes you want to be able to have array semantics. In this case,
  * we want to be able to automatically reverse the contents of an array using
  * a custom array implementation.
  */
 public function reverse_arrays_automatically_reverse_the_contents_given()
 {
     require_once __DIR__ . '/classes/ReverseArray.php';
     $a = ['francesca', 'loves', 'paolo'];
     $reverse_array = new ReverseArray(count($a) - 1);
     for ($i = 0; $i < count($a); $i++) {
         $reverse_array[$i] = $a[$i];
     }
     assert_that($reverse_array->getInternalArray())->is_equal_to(['paolo', 'loves', 'francesca']);
 }
Ejemplo n.º 3
0
 public function the_cow_inventory_displays_frequencies_of_cow_names_when_passed_in_different_form()
 {
     $info = Inventory::parse_inventory(['Bessie, Bilbo, Marjorie, 0, Belinda'], ['freq']);
     assert_that($info)->is_equal_to(['cows' => 5, 'list' => ['0', 'Belinda', 'Bessie', 'Bilbo', 'Marjorie'], 'freq' => ['0' => 1, 'B' => 3, 'M' => 1]]);
 }
Ejemplo n.º 4
0
 public function objects_that_implement_the_JsonSerializable_interface_have_a_custom_json_encode()
 {
     // NumberRange is defined in classes/SPLClasses.php
     $number_range = new NumberRange(1, 10);
     assert_that(json_encode($number_range))->is_identical_to(__);
 }
Ejemplo n.º 5
0
 public function invalid_input_should_get_a_null_back()
 {
     assert_that($this->get_apartment_prices("The Mission", -1))->is_identical_to(null);
     assert_that($this->get_apartment_prices(null, 2))->is_identical_to(null);
     // hint: Are you using == or === ?
     assert_that($this->get_apartment_prices(0, 2))->is_identical_to(null);
 }
Ejemplo n.º 6
0
 public function put_that_coffee_down__coffee_is_for_closers_only()
 {
     $hierarchy = SalesHierarchy::build('0{Blake|Sociopath}0{Dave|Clueless}1{Shelley|Loser}1{Ricky|Loser}0{Williamson|Clueless}1{George|Loser}1{Mitch|Loser}');
     $hierarchy->assign_to_best_rep(new Lead('Rio Rancho', 2000000));
     $hierarchy->assign_to_best_rep(new Lead('Clear Meadows 1', 50000));
     $hierarchy->assign_to_best_rep(new Lead('Clear Meadows 2', 50000));
     $hierarchy->assign_to_best_rep(new Lead('Daytona Isle 1', 1000));
     $hierarchy->assign_to_best_rep(new Lead('Daytona Isle 2', 1000));
     $hierarchy->assign_to_best_rep(new Lead('Daytona Isle 3', 1000));
     $hierarchy->assign_to_best_rep(new Lead('Daytona Isle 4', 1000));
     assert_that(round($hierarchy->total_risk()))->is_equal_to(300000 + 2 * 17500 + 4 * 980);
 }
Ejemplo n.º 7
0
 public function try_catch_finally_will_call_finally_block_if_exception_is_thrown()
 {
     $called_finally = false;
     $value = try_catch_finally(function () {
         throw new Exception();
     }, function () {
         return 10;
     }, function () use(&$called_finally) {
         $called_finally = true;
     });
     assert_that($value)->is_identical_to(10);
     assert_that($called_finally)->is_identical_to(true);
 }
Ejemplo n.º 8
0
 public function really_really_really_asleep()
 {
     assert_that($this->whats_in_the_mouths_of_cerberus(null))->is_equal_to([]);
 }
Ejemplo n.º 9
0
 public function phpcredits_shows_the_folks_that_made_the_language()
 {
     // The ob_* functions allow us to capture output sent to stdout.
     // to see the content of $result, comment out ob_start/ob_get_clean
     ob_start();
     phpcredits(CREDITS_GENERAL);
     $result = ob_get_clean();
     assert_that($result)->contains_string(__);
 }