scratch – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
87 | office | 1 | <?php |
2 | |||
3 | namespace GuzzleHttp\Tests\Http; |
||
4 | |||
5 | use GuzzleHttp\Adapter\TransactionIterator; |
||
6 | use GuzzleHttp\Client; |
||
7 | |||
8 | class TransactionIteratorTest extends \PHPUnit_Framework_TestCase |
||
9 | { |
||
10 | /** |
||
11 | * @expectedException \InvalidArgumentException |
||
12 | */ |
||
13 | public function testValidatesConstructor() |
||
14 | { |
||
15 | new TransactionIterator('foo', new Client(), []); |
||
16 | } |
||
17 | |||
18 | public function testCreatesTransactions() |
||
19 | { |
||
20 | $client = new Client(); |
||
21 | $requests = [ |
||
22 | $client->createRequest('GET', 'http://test.com'), |
||
23 | $client->createRequest('POST', 'http://test.com'), |
||
24 | $client->createRequest('PUT', 'http://test.com'), |
||
25 | ]; |
||
26 | $t = new TransactionIterator($requests, $client, []); |
||
27 | $this->assertEquals(0, $t->key()); |
||
28 | $this->assertTrue($t->valid()); |
||
29 | $this->assertEquals('GET', $t->current()->getRequest()->getMethod()); |
||
30 | $t->next(); |
||
31 | $this->assertEquals(1, $t->key()); |
||
32 | $this->assertTrue($t->valid()); |
||
33 | $this->assertEquals('POST', $t->current()->getRequest()->getMethod()); |
||
34 | $t->next(); |
||
35 | $this->assertEquals(2, $t->key()); |
||
36 | $this->assertTrue($t->valid()); |
||
37 | $this->assertEquals('PUT', $t->current()->getRequest()->getMethod()); |
||
38 | } |
||
39 | |||
40 | public function testCanForeach() |
||
41 | { |
||
42 | $c = new Client(); |
||
43 | $requests = [ |
||
44 | $c->createRequest('GET', 'http://test.com'), |
||
45 | $c->createRequest('POST', 'http://test.com'), |
||
46 | $c->createRequest('PUT', 'http://test.com'), |
||
47 | ]; |
||
48 | |||
49 | $t = new TransactionIterator(new \ArrayIterator($requests), $c, []); |
||
50 | $methods = []; |
||
51 | |||
52 | foreach ($t as $trans) { |
||
53 | $this->assertInstanceOf( |
||
54 | 'GuzzleHttp\Adapter\TransactionInterface', |
||
55 | $trans |
||
56 | ); |
||
57 | $methods[] = $trans->getRequest()->getMethod(); |
||
58 | } |
||
59 | |||
60 | $this->assertEquals(['GET', 'POST', 'PUT'], $methods); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @expectedException \RuntimeException |
||
65 | */ |
||
66 | public function testValidatesEachElement() |
||
67 | { |
||
68 | $c = new Client(); |
||
69 | $requests = ['foo']; |
||
70 | $t = new TransactionIterator(new \ArrayIterator($requests), $c, []); |
||
71 | iterator_to_array($t); |
||
72 | } |
||
73 | } |