Exemplo n.º 1
0
 public function test05()
 {
     ### generate_object_value_hash($object, $value)
     $obj = new \stdClass();
     $this->assertEquals(['stdClass' => Util::assoc_from_str('one:1, two:2, three:3, four:4')], Util::value_class($obj, Util::assoc_from_str('one:1, two:2, three:3, four:4')));
     # non-object returns null
     /** @noinspection PhpParamsInspection */
     $this->assertNull(Util::value_class('not an object', Util::assoc_from_str('one:1, two:2, three:3, four:4')));
     ### pivot_array_on_index(array $input)
     $worker = [['name' => 'Google', 'url' => 'https://google.com'], ['name' => 'Yahoo!', 'url' => 'http://yahoo.com']];
     $this->assertEquals(['name' => ['Google', 'Yahoo!'], 'url' => ['https://google.com', 'http://yahoo.com']], Util::pivot_array($worker));
     ### array_get($array, $key, $default = NULL)
     $this->assertEquals('now', Util::array_get('Candy.start', $this->source_array));
     $this->assertEquals('not found', Util::array_get('Candy.nope', $this->source_array, 'not found'));
     ###  multi_explode(array $delimiters, $string, $trim)
     $this->assertEquals([0 => 'This is a string', 1 => ' Break it up', 2 => ' Ok?'], Util::multi_explode('This is a string. Break it up! Ok?', ['.', '!']));
     ### convert_list_to_indexed_array($array)
     $this->assertEquals([0 => 'one', 1 => 'two'], Util::array_to_numeric_index(Util::array_from_str('one two')));
     ### get_array_value_safely($index, $array)
     //$this->assertEquals(
     //    [
     //        'start' => 'now',
     //        'end'   => 'then',
     //    ],
     //    Util::get_array_value_safely('Candy', $this->source_array)
     //);
     //$this->assertNull(Util::get_array_value_safely('does-not-exist', $this->source_array));
 }
Exemplo n.º 2
0
 public function test8_Iteration()
 {
     # iteration
     $this->assertTrue(static::$collection->getIterator() instanceof \ArrayIterator);
     $result = [];
     foreach (static::$collection as $key => $value) {
         $result[] = $key;
     }
     sort($result);
     $this->assertEquals($result, Util::array_from_str('json part1 part2 yaml'));
 }