1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 10:03:27 +01:00
guzzle/tests/Exception/RequestExceptionTest.php

62 lines
2.1 KiB
PHP
Raw Normal View History

2013-10-07 12:43:23 -07:00
<?php
namespace GuzzleHttp\Tests\Event;
2013-10-07 12:43:23 -07:00
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Message\Request;
use GuzzleHttp\Message\Response;
2013-10-07 12:43:23 -07:00
/**
* @covers GuzzleHttp\Exception\RequestException
2013-10-07 12:43:23 -07:00
*/
class RequestExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testHasRequestAndResponse()
{
$req = new Request('GET', '/');
$res = new Response(200);
$e = new RequestException('foo', $req, $res);
$this->assertSame($req, $e->getRequest());
$this->assertSame($res, $e->getResponse());
$this->assertTrue($e->hasResponse());
$this->assertEquals('foo', $e->getMessage());
}
public function testCreatesGenerateException()
{
$e = RequestException::create(new Request('GET', '/'));
$this->assertEquals('Error completing request', $e->getMessage());
$this->assertInstanceOf('GuzzleHttp\Exception\RequestException', $e);
2013-10-07 12:43:23 -07:00
}
public function testCreatesClientErrorResponseException()
{
$e = RequestException::create(new Request('GET', '/'), new Response(400));
$this->assertEquals(
'Client error response [url] / [status code] 400 [reason phrase] Bad Request',
$e->getMessage()
);
$this->assertInstanceOf('GuzzleHttp\Exception\ClientException', $e);
2013-10-07 12:43:23 -07:00
}
public function testCreatesServerErrorResponseException()
{
$e = RequestException::create(new Request('GET', '/'), new Response(500));
$this->assertEquals(
'Server error response [url] / [status code] 500 [reason phrase] Internal Server Error',
$e->getMessage()
);
$this->assertInstanceOf('GuzzleHttp\Exception\ServerException', $e);
2013-10-07 12:43:23 -07:00
}
public function testCreatesGenericErrorResponseException()
{
$e = RequestException::create(new Request('GET', '/'), new Response(600));
$this->assertEquals(
'Unsuccessful response [url] / [status code] 600 [reason phrase] ',
$e->getMessage()
);
$this->assertInstanceOf('GuzzleHttp\Exception\RequestException', $e);
2013-10-07 12:43:23 -07:00
}
}