1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178:
<?php
namespace Guzzle\Tests\Service\Description;
use Guzzle\Service\Description\ServiceDescription;
use Guzzle\Service\Description\ServiceDescriptionLoader;
class ServiceDescriptionLoaderTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testAllowsExtraData()
{
$d = ServiceDescription::factory(array(
'foo' => true,
'baz' => array('bar'),
'apiVersion' => '123',
'operations' => array()
));
$this->assertEquals(true, $d->getData('foo'));
$this->assertEquals(array('bar'), $d->getData('baz'));
$this->assertEquals('123', $d->getApiVersion());
}
public function testAllowsDeepNestedInheritance()
{
$d = ServiceDescription::factory(array(
'operations' => array(
'abstract' => array(
'httpMethod' => 'HEAD',
'parameters' => array(
'test' => array('type' => 'string', 'required' => true)
)
),
'abstract2' => array('uri' => '/test', 'extends' => 'abstract'),
'concrete' => array('extends' => 'abstract2'),
'override' => array('extends' => 'abstract', 'httpMethod' => 'PUT'),
'override2' => array('extends' => 'override', 'httpMethod' => 'POST', 'uri' => '/')
)
));
$c = $d->getOperation('concrete');
$this->assertEquals('/test', $c->getUri());
$this->assertEquals('HEAD', $c->getHttpMethod());
$params = $c->getParams();
$param = $params['test'];
$this->assertEquals('string', $param->getType());
$this->assertTrue($param->getRequired());
$this->assertEquals('PUT', $d->getOperation('override')->getHttpMethod());
$this->assertEquals('POST', $d->getOperation('override2')->getHttpMethod());
$this->assertEquals('/', $d->getOperation('override2')->getUri());
}
public function testThrowsExceptionWhenExtendingMissingCommand()
{
ServiceDescription::factory(array(
'operations' => array(
'concrete' => array(
'extends' => 'missing'
)
)
));
}
public function testAllowsMultipleInheritance()
{
$description = ServiceDescription::factory(array(
'operations' => array(
'a' => array(
'httpMethod' => 'GET',
'parameters' => array(
'a1' => array(
'default' => 'foo',
'required' => true,
'prepend' => 'hi'
)
)
),
'b' => array(
'extends' => 'a',
'parameters' => array(
'b2' => array()
)
),
'c' => array(
'parameters' => array(
'a1' => array(
'default' => 'bar',
'required' => true,
'description' => 'test'
),
'c3' => array()
)
),
'd' => array(
'httpMethod' => 'DELETE',
'extends' => array('b', 'c'),
'parameters' => array(
'test' => array()
)
)
)
));
$command = $description->getOperation('d');
$this->assertEquals('DELETE', $command->getHttpMethod());
$this->assertContains('a1', $command->getParamNames());
$this->assertContains('b2', $command->getParamNames());
$this->assertContains('c3', $command->getParamNames());
$this->assertContains('test', $command->getParamNames());
$this->assertTrue($command->getParam('a1')->getRequired());
$this->assertEquals('bar', $command->getParam('a1')->getDefault());
$this->assertEquals('test', $command->getParam('a1')->getDescription());
}
public function testAddsOtherFields()
{
$description = ServiceDescription::factory(array(
'operations' => array(),
'description' => 'Foo',
'apiVersion' => 'bar'
));
$this->assertEquals('Foo', $description->getDescription());
$this->assertEquals('bar', $description->getApiVersion());
}
public function testCanLoadNestedExtends()
{
$description = ServiceDescription::factory(array(
'operations' => array(
'root' => array(
'class' => 'foo'
),
'foo' => array(
'extends' => 'root',
'parameters' => array(
'baz' => array('type' => 'string')
)
),
'foo_2' => array(
'extends' => 'foo',
'parameters' => array(
'bar' => array('type' => 'string')
)
),
'foo_3' => array(
'class' => 'bar',
'parameters' => array(
'bar2' => array('type' => 'string')
)
),
'foo_4' => array(
'extends' => array('foo_2', 'foo_3'),
'parameters' => array(
'bar3' => array('type' => 'string')
)
)
)
));
$this->assertTrue($description->hasOperation('foo_4'));
$foo4 = $description->getOperation('foo_4');
$this->assertTrue($foo4->hasParam('baz'));
$this->assertTrue($foo4->hasParam('bar'));
$this->assertTrue($foo4->hasParam('bar2'));
$this->assertTrue($foo4->hasParam('bar3'));
$this->assertEquals('bar', $foo4->getClass());
}
}