scratch – Blame information for rev 87
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
87 | office | 1 | <?php |
2 | |||
3 | namespace GuzzleHttp\Tests\Message; |
||
4 | |||
5 | use GuzzleHttp\Adapter\Transaction; |
||
6 | use GuzzleHttp\Client; |
||
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; |
||
12 | |||
13 | /** |
||
14 | * @covers GuzzleHttp\Subscriber\HttpError |
||
15 | */ |
||
16 | class HttpErrorTest extends \PHPUnit_Framework_TestCase |
||
17 | { |
||
18 | public function testIgnoreSuccessfulRequests() |
||
19 | { |
||
20 | $event = $this->getEvent(); |
||
21 | $event->intercept(new Response(200)); |
||
22 | (new HttpError())->onComplete($event); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @expectedException \GuzzleHttp\Exception\ClientException |
||
27 | */ |
||
28 | public function testThrowsClientExceptionOnFailure() |
||
29 | { |
||
30 | $event = $this->getEvent(); |
||
31 | $event->intercept(new Response(403)); |
||
32 | (new HttpError())->onComplete($event); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @expectedException \GuzzleHttp\Exception\ServerException |
||
37 | */ |
||
38 | public function testThrowsServerExceptionOnFailure() |
||
39 | { |
||
40 | $event = $this->getEvent(); |
||
41 | $event->intercept(new Response(500)); |
||
42 | (new HttpError())->onComplete($event); |
||
43 | } |
||
44 | |||
45 | private function getEvent() |
||
46 | { |
||
47 | return new CompleteEvent(new Transaction(new Client(), new Request('PUT', '/'))); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @expectedException \GuzzleHttp\Exception\ClientException |
||
52 | */ |
||
53 | public function testFullTransaction() |
||
54 | { |
||
55 | $client = new Client(); |
||
56 | $client->getEmitter()->attach(new Mock([ |
||
57 | new Response(403) |
||
58 | ])); |
||
59 | $client->get('http://httpbin.org'); |
||
60 | } |
||
61 | } |