$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\Exception;
use Guzzle\Http\Exception\MultiTransferException;
use Guzzle\Http\Message\Request;
use Guzzle\Service\Exception\CommandTransferException;
use Guzzle\Tests\Service\Mock\Command\MockCommand;
/**
* @covers Guzzle\Service\Exception\CommandTransferException
*/
class CommandTransferExceptionTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testStoresCommands()
{
$c1 = new MockCommand();
$c2 = new MockCommand();
$e = new CommandTransferException('Test');
$e->addSuccessfulCommand($c1)->addFailedCommand($c2);
$this->assertSame(array($c1), $e->getSuccessfulCommands());
$this->assertSame(array($c2), $e->getFailedCommands());
$this->assertSame(array($c1, $c2), $e->getAllCommands());
}
public function testConvertsMultiExceptionIntoCommandTransfer()
{
$r1 = new Request('GET', 'http://foo.com');
$r2 = new Request('GET', 'http://foobaz.com');
$e = new MultiTransferException('Test', 123);
$e->addSuccessfulRequest($r1)->addFailedRequest($r2);
$ce = CommandTransferException::fromMultiTransferException($e);
$this->assertInstanceOf('Guzzle\Service\Exception\CommandTransferException', $ce);
$this->assertEquals('Test', $ce->getMessage());
$this->assertEquals(123, $ce->getCode());
$this->assertSame(array($r1), $ce->getSuccessfulRequests());
$this->assertSame(array($r2), $ce->getFailedRequests());
}
public function testCanRetrieveExceptionForCommand()
{
$r1 = new Request('GET', 'http://foo.com');
$e1 = new \Exception('foo');
$c1 = $this->getMockBuilder('Guzzle\Tests\Service\Mock\Command\MockCommand')
->setMethods(array('getRequest'))
->getMock();
$c1->expects($this->once())->method('getRequest')->will($this->returnValue($r1));
$e = new MultiTransferException('Test', 123);
$e->addFailedRequestWithException($r1, $e1);
$ce = CommandTransferException::fromMultiTransferException($e);
$ce->addFailedCommand($c1);
$this->assertSame($e1, $ce->getExceptionForFailedCommand($c1));
}
public function testAddsNonRequestExceptions()
{
$e = new MultiTransferException();
$e->add(new \Exception('bar'));
$e->addFailedRequestWithException(new Request('GET', 'http://www.foo.com'), new \Exception('foo'));
$ce = CommandTransferException::fromMultiTransferException($e);
$this->assertEquals(2, count($ce));
}
}