3
namespace GuzzleHttp\Tests\Message;
5
use GuzzleHttp\Adapter\Transaction;
7
use GuzzleHttp\Event\CompleteEvent;
8
use GuzzleHttp\Message\Request;
9
use GuzzleHttp\Message\Response;
10
use GuzzleHttp\Subscriber\HttpError;
11
use GuzzleHttp\Subscriber\Mock;
14
* @covers GuzzleHttp\Subscriber\HttpError
16
class HttpErrorTest extends \PHPUnit_Framework_TestCase
18
public function testIgnoreSuccessfulRequests()
20
$event = $this->getEvent();
21
$event->intercept(new Response(200));
22
(new HttpError())->onComplete($event);
26
* @expectedException \GuzzleHttp\Exception\ClientException
28
public function testThrowsClientExceptionOnFailure()
30
$event = $this->getEvent();
31
$event->intercept(new Response(403));
32
(new HttpError())->onComplete($event);
36
* @expectedException \GuzzleHttp\Exception\ServerException
38
public function testThrowsServerExceptionOnFailure()
40
$event = $this->getEvent();
41
$event->intercept(new Response(500));
42
(new HttpError())->onComplete($event);
45
private function getEvent()
47
return new CompleteEvent(new Transaction(new Client(), new Request('PUT', '/')));
51
* @expectedException \GuzzleHttp\Exception\ClientException
53
public function testFullTransaction()
55
$client = new Client();
56
$client->getEmitter()->attach(new Mock([
59
$client->get('http://httpbin.org');