Example #1
0
 /**
  * Tests Arr::insert()
  * 
  * @test
  */
 public function test_insert()
 {
     $people = array("Jack", "Jill");
     $expected = array("Humpty", "Jack", "Jill");
     $output = Arr::insert($people, "Humpty", 0);
     $this->assertEquals(true, $output);
     $this->assertEquals($expected, $people);
 }
Example #2
0
 public function testInsertsWithStringKeys()
 {
     $array = ['zero' => 'cat', 'one' => 'dog', 'two' => 'octopus', 'three' => 'raven'];
     // inserting before 'dog' which is at index 1
     // make 'dog' which was 1, into 2
     $result = Arr::insert($array, 'spider', 'one');
     // we use `same` here because they must be identical, equals would be true regardless of the order
     // UNFORTUNATELY, IT ONLY WORKS FOR NUMERICAL INDEXES
     $this->assertSame($result, ['zero' => 'cat', 'one' => 'dog', 'two' => 'octopus', 'three' => 'raven']);
 }
Example #3
0
 /**
  * Tests Arr::insert()
  *
  * @test
  */
 public function test_insert_with_index_out_of_range()
 {
     $people = array("Jack", "Jill");
     $output = Arr::insert($people, "Humpty", 4);
     $this->assertFalse($output);
 }