Exemplo n.º 1
0
 public function test01()
 {
     ### array_to_object
     $obj = Util::cast_array_to_object($this->source_array);
     $this->assertEquals($obj->Apples, $this->source_array['Apples']);
     ### object_to_array
     $array = Util::cast_object_as_array($obj);
     $this->assertEquals($this->source_array, $array);
     ### copy_object_to_array
     $obj2 = Util::cast_array_to_object(['a' => 'not much']);
     $obj1 = Util::cast_array_to_object(['apples' => 10, 'beets' => 'nope', 'candy.start' => 'now', 'candy.end' => 'never', 'value_obj' => $obj2]);
     $obj_array = Util::array_from_object($obj1);
     $this->assertEquals(['apples' => 10, 'beets' => 'nope', 'candy.start' => 'now', 'candy.end' => 'never', 'value_obj' => ['a' => 'not much']], $obj_array);
     ### array_insert_before_key
     $this->assertEquals(['Apples' => 'One', 'Beets' => 2, 'Beef' => ['hamburger', 'roast beef'], 'Candy' => ['start' => 'now', 'end' => 'then']], Util::insert_before('Candy', $this->source_array, "Beef", ['hamburger', 'roast beef']));
     ### array_except($array, $keys)
     $this->assertEquals(['Apples' => 'One', 'Candy' => ['start' => 'now', 'end' => 'then']], Util::array_except(['Beets'], $this->source_array));
     ### array_pull(&$array, $key, $default = NULL)
     # copy the test array
     $worker = $this->source_array;
     # pull 'Beets' -> 2
     $this->assertEquals(2, Util::array_pull("Beets", $worker, $default = FALSE));
     # verify removed from original
     $this->assertArrayNotHasKey("Beets", $worker);
 }