/** * @covers Guzzle\Service\Description\ApiCommand */ public function testApiCommandIsDataObject() { $c = new ApiCommand(array('name' => 'test', 'doc' => 'doc', 'method' => 'POST', 'path' => '/api/v1', 'params' => array('key' => array('required' => 'true', 'type' => 'string', 'max_length' => 10), 'key_2' => array('required' => 'true', 'type' => 'integer', 'default' => 10)))); $this->assertEquals('test', $c->getName()); $this->assertEquals('doc', $c->getDoc()); $this->assertEquals('POST', $c->getMethod()); $this->assertEquals('/api/v1', $c->getUri()); $this->assertEquals('Guzzle\\Service\\Command\\DynamicCommand', $c->getConcreteClass()); $this->assertEquals(array('key' => new ApiParam(array('required' => 'true', 'type' => 'string', 'max_length' => 10)), 'key_2' => new ApiParam(array('required' => 'true', 'type' => 'integer', 'default' => 10))), $c->getParams()); $this->assertEquals(new ApiParam(array('required' => 'true', 'type' => 'integer', 'default' => 10)), $c->getParam('key_2')); $this->assertNull($c->getParam('afefwef')); }
/** * Constructor * * @param array|Collection $parameters (optional) Collection of parameters * to set on the command * @param ApiCommand $apiCommand (optional) Command definition from description */ public function __construct($parameters = null, ApiCommand $apiCommand = null) { parent::__construct($parameters); // Add arguments and defaults to the command if ($apiCommand) { $this->apiCommand = $apiCommand; Inspector::getInstance()->validateConfig($apiCommand->getParams(), $this, false, false); } else { Inspector::getInstance()->validateClass(get_class($this), $this, false, false); } if (!$this->get('headers') instanceof Collection) { $this->set('headers', new Collection((array) $this->get('headers'))); } $this->init(); }
/** * @covers Guzzle\Service\Description\ApiCommand */ public function testApiCommandIsDataObject() { $c = new ApiCommand(array('name' => 'test', 'doc' => 'doc', 'doc_url' => 'http://www.example.com', 'method' => 'POST', 'uri' => '/api/v1', 'result_type' => 'array', 'result_doc' => 'returns the json_decoded response', 'deprecated' => true, 'params' => array('key' => array('required' => 'true', 'type' => 'string', 'max_length' => 10), 'key_2' => array('required' => 'true', 'type' => 'integer', 'default' => 10)))); $this->assertEquals('test', $c->getName()); $this->assertEquals('doc', $c->getDoc()); $this->assertEquals('http://www.example.com', $c->getDocUrl()); $this->assertEquals('POST', $c->getMethod()); $this->assertEquals('/api/v1', $c->getUri()); $this->assertEquals('array', $c->getResultType()); $this->assertEquals('returns the json_decoded response', $c->getResultDoc()); $this->assertTrue($c->isDeprecated()); $this->assertEquals('Guzzle\\Service\\Command\\DynamicCommand', $c->getConcreteClass()); $this->assertEquals(array('key' => new ApiParam(array('name' => 'key', 'required' => 'true', 'type' => 'string', 'max_length' => 10)), 'key_2' => new ApiParam(array('name' => 'key_2', 'required' => 'true', 'type' => 'integer', 'default' => 10))), $c->getParams()); $this->assertEquals(new ApiParam(array('name' => 'key_2', 'required' => 'true', 'type' => 'integer', 'default' => 10)), $c->getParam('key_2')); $this->assertNull($c->getParam('afefwef')); }