1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 18:13:00 +01:00

Trying to ucfirst a command when using the service description command factory

This commit is contained in:
Michael Dowling 2013-04-13 19:24:12 -07:00
parent 24af41160c
commit 5e9b3bfdef
2 changed files with 18 additions and 9 deletions

View File

@ -61,9 +61,13 @@ class ServiceDescriptionFactory implements FactoryInterface
{
$command = $this->description->getOperation($name);
// If an inflector was passed, then attempt to get the command using snake_case inflection
if (!$command && $this->inflector) {
$command = $this->description->getOperation($this->inflector->snake($name));
// If a command wasn't found, then try to uppercase the first letter and try again
if (!$command) {
$command = $this->description->getOperation(ucfirst($name));
// If an inflector was passed, then attempt to get the command using snake_case inflection
if (!$command && $this->inflector) {
$command = $this->description->getOperation($this->inflector->snake($name));
}
}
if ($command) {

View File

@ -37,6 +37,14 @@ class ServiceDescriptionFactoryTest extends \Guzzle\Tests\GuzzleTestCase
}
}
public function testUsesUcFirstIfNoExactMatch()
{
$d = $this->getDescription();
$factory = new ServiceDescriptionFactory($d, new Inflector());
$this->assertInstanceof('Guzzle\Tests\Service\Mock\Command\OtherCommand', $factory->factory('Test'));
$this->assertInstanceof('Guzzle\Tests\Service\Mock\Command\OtherCommand', $factory->factory('test'));
}
public function testUsesInflectionIfNoExactMatch()
{
$d = $this->getDescription();
@ -51,12 +59,9 @@ class ServiceDescriptionFactoryTest extends \Guzzle\Tests\GuzzleTestCase
{
return ServiceDescription::factory(array(
'operations' => array(
'jar_jar' => array(
'class' => 'Guzzle\Tests\Service\Mock\Command\MockCommand'
),
'binks' => array(
'class' => 'Guzzle\Tests\Service\Mock\Command\OtherCommand'
)
'jar_jar' => array('class' => 'Guzzle\Tests\Service\Mock\Command\MockCommand'),
'binks' => array('class' => 'Guzzle\Tests\Service\Mock\Command\OtherCommand'),
'Test' => array('class' => 'Guzzle\Tests\Service\Mock\Command\OtherCommand')
)
));
}