$serviceBuilder
$serviceBuilder :
Base testcase class for all Guzzle testcases.
getServer() : \Guzzle\Tests\Http\Server
Get the global server object used throughout the unit tests of Guzzle
setServiceBuilder(\Guzzle\Service\Builder\ServiceBuilderInterface $builder)
Set the service builder to use for tests
\Guzzle\Service\Builder\ServiceBuilderInterface | $builder | Service builder |
getServiceBuilder() : \Guzzle\Service\Builder\ServiceBuilder
Get a service builder object that can be used throughout the service tests
getWildcardObserver(\Guzzle\Common\HasDispatcherInterface $hasDispatcher) : \Guzzle\Tests\Mock\MockObserver
Get a wildcard observer for an event dispatcher
\Guzzle\Common\HasDispatcherInterface | $hasDispatcher |
setMockBasePath(string $path) : \Guzzle\Tests\GuzzleTestCase
Set the mock response base path
string | $path | Path to mock response folder |
addMockedRequest(\Guzzle\Http\Message\RequestInterface $request) : self
Mark a request as being mocked
\Guzzle\Http\Message\RequestInterface | $request |
getMockResponse(string $path) : \Guzzle\Http\Message\Response
Get a mock response for a client by mock file name
string | $path | Relative path to the mock response file |
setMockResponse(\Guzzle\Http\Client $client, string $paths) : \Guzzle\Plugin\Mock\MockPlugin
Set a mock response from a mock file on the next client request.
This method assumes that mock response files are located under the Command/Mock/ directory of the Service being tested (e.g. Unfuddle/Command/Mock/). A mock response is added to the next request sent by the client.
\Guzzle\Http\Client | $client | Client object to modify |
string | $paths | Path to files within the Mock folder of the service |
returns the created mock plugin
compareHeaders(array $filteredHeaders, array $actualHeaders) : array|boolean
Compare HTTP headers and use special markup to filter values A header prefixed with '!' means it must not exist A header prefixed with '_' means it must be ignored A header value of '*' means anything after the * will be ignored
array | $filteredHeaders | Array of special headers |
array | $actualHeaders | Array of headers to check against |
Returns an array of the differences or FALSE if none
hasSubscriber(\Guzzle\Common\HasDispatcherInterface $dispatcher, \Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber) : boolean
Check if an event dispatcher has a subscriber
\Guzzle\Common\HasDispatcherInterface | $dispatcher | |
\Symfony\Component\EventDispatcher\EventSubscriberInterface | $subscriber |
<?php
namespace Guzzle\Tests\Service\Description;
use Guzzle\Service\Description\ServiceDescription;
use Guzzle\Service\Description\Operation;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Client;
/**
* @covers Guzzle\Service\Description\ServiceDescription
*/
class ServiceDescriptionTest extends \Guzzle\Tests\GuzzleTestCase
{
protected $serviceData;
public function setup()
{
$this->serviceData = array(
'test_command' => new Operation(array(
'name' => 'test_command',
'description' => 'documentationForCommand',
'httpMethod' => 'DELETE',
'class' => 'Guzzle\\Tests\\Service\\Mock\\Command\\MockCommand',
'parameters' => array(
'bucket' => array('required' => true),
'key' => array('required' => true)
)
))
);
}
/**
* @covers Guzzle\Service\Description\ServiceDescription::factory
* @covers Guzzle\Service\Description\ServiceDescriptionLoader::build
*/
public function testFactoryDelegatesToConcreteFactories()
{
$jsonFile = __DIR__ . '/../../TestData/test_service.json';
$this->assertInstanceOf('Guzzle\Service\Description\ServiceDescription', ServiceDescription::factory($jsonFile));
}
public function testConstructor()
{
$service = new ServiceDescription(array('operations' => $this->serviceData));
$this->assertEquals(1, count($service->getOperations()));
$this->assertFalse($service->hasOperation('foobar'));
$this->assertTrue($service->hasOperation('test_command'));
}
public function testIsSerializable()
{
$service = new ServiceDescription(array('operations' => $this->serviceData));
$data = serialize($service);
$d2 = unserialize($data);
$this->assertEquals(serialize($service), serialize($d2));
}
public function testSerializesParameters()
{
$service = new ServiceDescription(array(
'operations' => array(
'foo' => new Operation(array('parameters' => array('foo' => array('type' => 'string'))))
)
));
$serialized = serialize($service);
$this->assertContains('"parameters":{"foo":', $serialized);
$service = unserialize($serialized);
$this->assertTrue($service->getOperation('foo')->hasParam('foo'));
}
public function testAllowsForJsonBasedArrayParamsFunctionalTest()
{
$description = new ServiceDescription(array(
'operations' => array(
'test' => new Operation(array(
'httpMethod' => 'PUT',
'parameters' => array(
'data' => array(
'required' => true,
'filters' => 'json_encode',
'location' => 'body'
)
)
))
)
));
$client = new Client();
$client->setDescription($description);
$command = $client->getCommand('test', array(
'data' => array(
'foo' => 'bar'
)
));
$request = $command->prepare();
$this->assertEquals('{"foo":"bar"}', (string) $request->getBody());
}
public function testContainsModels()
{
$d = new ServiceDescription(array(
'operations' => array('foo' => array()),
'models' => array(
'Tag' => array('type' => 'object'),
'Person' => array('type' => 'object')
)
));
$this->assertTrue($d->hasModel('Tag'));
$this->assertTrue($d->hasModel('Person'));
$this->assertFalse($d->hasModel('Foo'));
$this->assertInstanceOf('Guzzle\Service\Description\Parameter', $d->getModel('Tag'));
$this->assertNull($d->getModel('Foo'));
$this->assertContains('"models":{', serialize($d));
$this->assertEquals(array('Tag', 'Person'), array_keys($d->getModels()));
}
public function testCanAddModels()
{
$d = new ServiceDescription(array());
$this->assertFalse($d->hasModel('Foo'));
$d->addModel(new Parameter(array('name' => 'Foo')));
$this->assertTrue($d->hasModel('Foo'));
}
public function testHasAttributes()
{
$d = new ServiceDescription(array(
'operations' => array(),
'name' => 'Name',
'description' => 'Description',
'apiVersion' => '1.24'
));
$this->assertEquals('Name', $d->getName());
$this->assertEquals('Description', $d->getDescription());
$this->assertEquals('1.24', $d->getApiVersion());
$s = serialize($d);
$this->assertContains('"name":"Name"', $s);
$this->assertContains('"description":"Description"', $s);
$this->assertContains('"apiVersion":"1.24"', $s);
$d = unserialize($s);
$this->assertEquals('Name', $d->getName());
$this->assertEquals('Description', $d->getDescription());
$this->assertEquals('1.24', $d->getApiVersion());
}
public function testPersistsCustomAttributes()
{
$data = array(
'operations' => array('foo' => array('class' => 'foo', 'parameters' => array())),
'name' => 'Name',
'description' => 'Test',
'apiVersion' => '1.24',
'auth' => 'foo',
'keyParam' => 'bar'
);
$d = new ServiceDescription($data);
$d->setData('hello', 'baz');
$this->assertEquals('foo', $d->getData('auth'));
$this->assertEquals('baz', $d->getData('hello'));
$this->assertEquals('bar', $d->getData('keyParam'));
// responseClass and responseType are added by default
$data['operations']['foo']['responseClass'] = 'array';
$data['operations']['foo']['responseType'] = 'primitive';
$this->assertEquals($data + array('hello' => 'baz'), json_decode($d->serialize(), true));
}
public function testHasToArray()
{
$data = array(
'operations' => array(),
'name' => 'Name',
'description' => 'Test'
);
$d = new ServiceDescription($data);
$arr = $d->toArray();
$this->assertEquals('Name', $arr['name']);
$this->assertEquals('Test', $arr['description']);
}
public function testReturnsNullWhenRetrievingMissingOperation()
{
$s = new ServiceDescription(array());
$this->assertNull($s->getOperation('foo'));
}
public function testCanAddOperations()
{
$s = new ServiceDescription(array());
$this->assertFalse($s->hasOperation('Foo'));
$s->addOperation(new Operation(array('name' => 'Foo')));
$this->assertTrue($s->hasOperation('Foo'));
}
/**
* @expectedException Guzzle\Common\Exception\InvalidArgumentException
*/
public function testValidatesOperationTypes()
{
$s = new ServiceDescription(array(
'operations' => array('foo' => new \stdClass())
));
}
public function testHasBaseUrl()
{
$description = new ServiceDescription(array('baseUrl' => 'http://foo.com'));
$this->assertEquals('http://foo.com', $description->getBaseUrl());
$description->setBaseUrl('http://foobar.com');
$this->assertEquals('http://foobar.com', $description->getBaseUrl());
}
public function testCanUseBasePath()
{
$description = new ServiceDescription(array('basePath' => 'http://foo.com'));
$this->assertEquals('http://foo.com', $description->getBaseUrl());
}
public function testModelsHaveNames()
{
$desc = array(
'models' => array(
'date' => array('type' => 'string'),
'user'=> array(
'type' => 'object',
'properties' => array(
'dob' => array('$ref' => 'date')
)
)
)
);
$s = ServiceDescription::factory($desc);
$this->assertEquals('date', $s->getModel('date')->getName());
$this->assertEquals('dob', $s->getModel('user')->getProperty('dob')->getName());
}
}