/**
  * Test that constructor args were pulled properly
  *
  * Note that we need to deuplicate the CamelCase conversion here for old
  * fashioned classes
  */
 public function testInitConstructorArgs()
 {
     $expectedConstructorArgs = array();
     foreach ($this->getConstructorArgs() as $param) {
         $expectedConstructorArgs[Util::snakeToCamelCase($param->getName())] = $param;
     }
     $this->assertEquals($expectedConstructorArgs, $this->resolver->getConstructorArgs());
 }
 /**
  * Fetches constructor args (array of ReflectionParameter) from the reflected class
  * and set them as an associative array
  *
  * Convert the parameter names to camelCase for classes that have contructor
  * params defined in snake_case for consistency with the options
  */
 public function initConstructorArgs()
 {
     $constructor = $this->reflected->getConstructor();
     if (!is_null($constructor)) {
         // Index parameters by their names
         foreach ($constructor->getParameters() as $param) {
             $name = Util::snakeToCamelCase($param->getName());
             $this->constructorArgs[$name] = $param;
         }
     }
 }
Esempio n. 3
0
 public function testSnakeToCamelCase()
 {
     // non-strings
     $this->assertSame(null, Util::snakeToCamelCase(null));
     $this->assertSame(null, Util::snakeToCamelCase(array()));
     $this->assertSame(null, Util::snakeToCamelCase(1));
     // strings
     $this->assertSame('', Util::snakeToCamelCase(''));
     $this->assertSame('foo', Util::snakeToCamelCase('foo'));
     $this->assertSame('fooBar', Util::snakeToCamelCase('foo_bar'));
     $this->assertSame('fooBarBaz', Util::snakeToCamelCase('foo_bar_baz'));
     // weird strings
     $this->assertSame('_', Util::snakeToCamelCase('_'));
     $this->assertSame('__', Util::snakeToCamelCase('___'));
     $this->assertSame('_ _', Util::snakeToCamelCase('_ _'));
     $this->assertSame('x_', Util::snakeToCamelCase('X__'));
     $this->assertSame('_X', Util::snakeToCamelCase('__X'));
 }
Esempio n. 4
0
 /**
  * Return option values indexed by name using camelCased keys
  *
  * @param  array  $options Array of options
  *
  * @return mixed[] Array of options indexed by (camelCased) name
  */
 public static function optionsToCamelCase(array $options)
 {
     $optionsByName = array();
     if (count($options)) {
         foreach ($options as $name => $value) {
             $optionsByName[Util::snakeToCamelCase($name)] = $value;
         }
     }
     return $optionsByName;
 }