scratch – Blame information for rev 87
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
87 | office | 1 | <?php |
2 | namespace GuzzleHttp\Tests\Adapter; |
||
3 | |||
4 | use GuzzleHttp\Adapter\FakeParallelAdapter; |
||
5 | use GuzzleHttp\Adapter\MockAdapter; |
||
6 | use GuzzleHttp\Adapter\TransactionIterator; |
||
7 | use GuzzleHttp\Client; |
||
8 | use GuzzleHttp\Event\ErrorEvent; |
||
9 | use GuzzleHttp\Exception\RequestException; |
||
10 | use GuzzleHttp\Message\Response; |
||
11 | |||
12 | /** |
||
13 | * @covers GuzzleHttp\Adapter\FakeParallelAdapter |
||
14 | */ |
||
15 | class FakeParallelAdapterTest extends \PHPUnit_Framework_TestCase |
||
16 | { |
||
17 | public function testSendsAllTransactions() |
||
18 | { |
||
19 | $client = new Client(); |
||
20 | $requests = [ |
||
21 | $client->createRequest('GET', 'http://httbin.org'), |
||
22 | $client->createRequest('HEAD', 'http://httbin.org'), |
||
23 | ]; |
||
24 | |||
25 | $sent = []; |
||
26 | $f = new FakeParallelAdapter(new MockAdapter(function ($trans) use (&$sent) { |
||
27 | $sent[] = $trans->getRequest()->getMethod(); |
||
28 | return new Response(200); |
||
29 | })); |
||
30 | |||
31 | $tIter = new TransactionIterator($requests, $client, []); |
||
32 | $f->sendAll($tIter, 2); |
||
33 | $this->assertContains('GET', $sent); |
||
34 | $this->assertContains('HEAD', $sent); |
||
35 | } |
||
36 | |||
37 | public function testThrowsImmediatelyIfInstructed() |
||
38 | { |
||
39 | $client = new Client(); |
||
40 | $request = $client->createRequest('GET', 'http://httbin.org'); |
||
41 | $request->getEmitter()->on('error', function (ErrorEvent $e) { |
||
42 | $e->throwImmediately(true); |
||
43 | }); |
||
44 | $sent = []; |
||
45 | $f = new FakeParallelAdapter( |
||
46 | new MockAdapter(function ($trans) use (&$sent) { |
||
47 | $sent[] = $trans->getRequest()->getMethod(); |
||
48 | return new Response(404); |
||
49 | }) |
||
50 | ); |
||
51 | $tIter = new TransactionIterator([$request], $client, []); |
||
52 | try { |
||
53 | $f->sendAll($tIter, 1); |
||
54 | $this->fail('Did not throw'); |
||
55 | } catch (RequestException $e) { |
||
56 | $this->assertSame($request, $e->getRequest()); |
||
57 | } |
||
58 | } |
||
59 | } |