public function testAssociativity() { // TODO: Ensure this is the right way to test this. $lowerCase = function ($string) { return Maybe::just(strtolower($string)); }; $camelCase = function ($string) { return Maybe::just('Camelcase: ' . Str::camel($string)); }; $this->assertEquals(Maybe::just('OMG_WHAT_IS_THIS')->bind($lowerCase)->bind($camelCase), Maybe::just('OMG_WHAT_IS_THIS')->bind(function ($x) use($lowerCase, $camelCase) { return $lowerCase($x)->bind($camelCase); })); $this->assertEquals(Maybe::nothing()->bind($lowerCase)->bind($camelCase), Maybe::nothing()->bind(function ($x) use($lowerCase, $camelCase) { return $lowerCase($x)->bind($camelCase); })); $this->assertEquals(Maybe::fromJust(Maybe::just('OMG_WHAT_IS_THIS')->bind($lowerCase)->bind($camelCase)), 'Camelcase: omgWhatIsThis'); }
public function testCamel() { $this->assertEquals('snakeCaseStuff', Str::camel('snake_case_stuff')); $this->assertEquals('studlyCaseStuff', Str::camel('StudlyCaseStuff')); }
/** * Get an array representation of this entity. * * @return array */ public function toArray() { $result = []; ArrayList::of($this->getFillable())->append(ArrayList::of($this->getVisible()))->unique(SORT_STRING)->exceptValues($this->getHidden())->each(function ($key) use(&$result) { $getter = vsprintf('get%s', [Str::studly($key)]); if (method_exists($this, $getter)) { $result[$key] = $this->{$getter}(); return; } $camel = Str::camel($key); $result[$key] = $this->{$camel}; }); return $result; }