public function testasArray() { // empties $this->assertEquals(Re::asArray(array()), array()); $this->assertEquals(Re::asArray(''), array()); $this->assertEquals(Re::asArray(null), array()); $this->assertEquals(Re::asArray(false), array()); $this->assertEquals(Re::asArray(0), array()); // arrays = passthrough $input = array(1, 2, 3 => array(4, 5)); $this->assertEquals(Re::asArray($input), $input); // serialize $this->assertEquals(Re::asArray(serialize($input)), $input); // JSON $this->assertEquals(Re::asArray(json_encode($input)), $input); // string/int... ends up inside a new array $this->assertEquals(Re::asArray('foobar'), array('foobar')); $this->assertEquals(Re::asArray(555), array(555)); // object.. walks the properties // - Re has none.. $obj = new Re(); $this->assertEquals(Re::asArray($obj), array()); // - $this has many properties... $this->TestingReAsArray = time(); $expect = array('fixtures', 'previousConfig', 'fixtureManager', 'autoFixtures', 'dropTables', 'db', 'TestingReAsArray'); $result = Re::asArray($this); $this->assertEquals(array_keys($result), $expect); $this->assertEquals($result['TestingReAsArray'], $this->TestingReAsArray); unset($this->TestingReAsArray); }
/** * A simple funciton to return the first non-empty/valid value from $input array * @param array $input * @param mixed $default [null] * @param array $isValidSettings * @return mixed $output */ public static function firstValid($input, $default = null, $isValidSettings = array()) { if (is_array($input) && !empty($input)) { foreach (Re::asArray($input) as $val) { if (Re::isValid($val, $isValidSettings)) { return $val; } } } return $default; }