/** * It converts one naming convention to another * * @param string $string * @return string */ public function convert($string) { $this->validator->validate($string); // for example $string = str_replace('_', ' ', $string); // For Example $string = ucwords($string); // ForExample $string = str_replace(' ', '', $string); return $string; }
/** * It converts one naming convention to another * * @param string $string * @return string */ public function convert($string) { $this->validator->validate($string); // 1. CamelCase // 2. Camel Case // 3. camel case // 4. camel_case $arr = preg_split('/(?=[A-Z])/', $string); array_shift($arr); $string = join('_', $arr); $string = strtolower($string); return $string; }
function it_should_convert_camel_case_string_to_underscore_version(ValidatorInterface $validator) { $validator->validate(Argument::any())->shouldBeCalled(); $this->convert('CamelCaseToUnderscore')->shouldReturn('camel_case_to_underscore'); }
function it_converts_underscored_convention_to_camel_cased(ValidatorInterface $validator) { $validator->validate(Argument::any())->shouldBeCalled(); $this->convert('some_of_the_underscore')->shouldReturn('SomeOfTheUnderscore'); }