public function testKeys() { // from js $this->assertEquals(array('one', 'two'), __u::keys((object) array('one' => 1, 'two' => 2)), 'can extract the keys from an object'); $a = array(1 => 0); $this->assertEquals(array(1), __u::keys($a), 'is not fooled by sparse arrays'); $actual = 'underscore'; try { $actual = __u::keys(null); } catch (Exception $e) { } $this->assertEquals('underscore', $actual, 'throws an exception for null values'); $actual = 'underscore'; try { $actual = __u::keys(UNDERSCORE_FOO); } catch (Exception $e) { } $this->assertEquals('underscore', $actual, 'throws an exception for undefined values'); $actual = 'underscore'; try { $actual = __u::keys(1); } catch (Exception $e) { } $this->assertEquals('underscore', $actual, 'throws an exception for number primitives'); $actual = 'underscore'; try { $actual = __u::keys('a'); } catch (Exception $e) { } $this->assertEquals('underscore', $actual, 'throws an exception for string primitives'); $actual = 'underscore'; try { $actual = __u::keys(true); } catch (Exception $e) { } $this->assertEquals('underscore', $actual, 'throws an exception for boolean primitives'); // extra $this->assertEquals(array('one', 'two'), __u::keys(array('one' => 1, 'two' => 2)), 'can extract the keys from an array'); $this->assertEquals(array('three', 'four'), __u(array('three' => 3, 'four' => 4))->keys(), 'can extract the keys from an array using OO-style call'); // docs $this->assertEquals(array('name', 'age'), __u::keys((object) array('name' => 'moe', 'age' => 40))); }