@@ -31,6 +31,11 @@ class ClientTest extends TestCase
31
31
*/
32
32
protected $ resolver ;
33
33
34
+ /**
35
+ * @var Mock
36
+ */
37
+ protected $ response ;
38
+
34
39
/**
35
40
* @var Mock
36
41
*/
@@ -61,17 +66,17 @@ public function it_can_be_constructed()
61
66
*/
62
67
public function it_returns_a_model_for_an_object_response ()
63
68
{
64
- $ response = Mockery::mock (Response::class);
69
+ $ this -> response = Mockery::mock (Response::class);
65
70
66
- $ response ->shouldReceive ('getBody ' )
71
+ $ this -> response ->shouldReceive ('getBody ' )
67
72
->once ()
68
73
->withNoArgs ()
69
74
->andReturn ('{"version":"v2016.6.43325","isCloud":false,"serverTimeZone":"Eastern Standard Time"} ' );
70
75
71
76
$ this ->guzzle ->shouldReceive ('request ' )
72
77
->once ()
73
78
->withAnyArgs ()
74
- ->andReturn ($ response );
79
+ ->andReturn ($ this -> response );
75
80
76
81
$ this ->resolver ->shouldReceive ('find ' )
77
82
->once ()
@@ -106,9 +111,9 @@ public function it_returns_a_model_for_an_object_response()
106
111
*/
107
112
public function it_returns_a_collection_for_an_array_response ()
108
113
{
109
- $ response = Mockery::mock (Response::class);
114
+ $ this -> response = Mockery::mock (Response::class);
110
115
111
- $ response ->shouldReceive ('getBody ' )
116
+ $ this -> response ->shouldReceive ('getBody ' )
112
117
->once ()
113
118
->withNoArgs ()
114
119
->andReturn (
@@ -118,7 +123,7 @@ public function it_returns_a_collection_for_an_array_response()
118
123
$ this ->guzzle ->shouldReceive ('request ' )
119
124
->once ()
120
125
->withAnyArgs ()
121
- ->andReturn ($ response );
126
+ ->andReturn ($ this -> response );
122
127
123
128
$ this ->resolver ->shouldReceive ('find ' )
124
129
->once ()
@@ -153,17 +158,17 @@ public function it_returns_a_collection_for_an_array_response()
153
158
*/
154
159
public function it_returns_an_array_when_there_is_not_a_model_to_map ()
155
160
{
156
- $ response = Mockery::mock (Response::class);
161
+ $ this -> response = Mockery::mock (Response::class);
157
162
158
- $ response ->shouldReceive ('getBody ' )
163
+ $ this -> response ->shouldReceive ('getBody ' )
159
164
->once ()
160
165
->withNoArgs ()
161
166
->andReturn ('{"version":"v2016.6.43325","isCloud":false,"serverTimeZone":"Eastern Standard Time"} ' );
162
167
163
168
$ this ->guzzle ->shouldReceive ('request ' )
164
169
->once ()
165
170
->withAnyArgs ()
166
- ->andReturn ($ response );
171
+ ->andReturn ($ this -> response );
167
172
168
173
$ this ->resolver ->shouldReceive ('find ' )
169
174
->once ()
@@ -579,17 +584,17 @@ public function it_raises_exception_when_making_a_request_without_a_uri()
579
584
580
585
protected function mockOutEverythingForTestingThatGuzzleIsCalled ()
581
586
{
582
- $ response = Mockery::mock (Response::class);
587
+ $ this -> response = Mockery::mock (Response::class);
583
588
584
- $ response ->shouldReceive ('getBody ' )
589
+ $ this -> response ->shouldReceive ('getBody ' )
585
590
->once ()
586
591
->withNoArgs ()
587
592
->andReturn ("{'responded': true} " );
588
593
589
594
$ this ->guzzle ->shouldReceive ('request ' )
590
595
->once ()
591
596
->withAnyArgs ()
592
- ->andReturn ($ response );
597
+ ->andReturn ($ this -> response );
593
598
594
599
$ this ->resolver ->shouldReceive ('find ' )
595
600
->once ()
@@ -636,4 +641,21 @@ public function it_throws_an_exception_on_non_supported_versions()
636
641
$ this ->client ->setVersion ('2012.2 ' );
637
642
$ this ->assertNotEquals ('2012.2 ' , $ this ->client ->getVersion ());
638
643
}
644
+
645
+ /**
646
+ * @test
647
+ */
648
+ public function it_has_a_getAll_method_that_it_passes_to_guzzle_as_paginated_get_calls ()
649
+ {
650
+ $ this ->mockOutEverythingForTestingThatGuzzleIsCalled ();
651
+ $ get_header_link = '<https://some.host/v4_6_release/apis/3.0/finance/agreements&pageSize=10&page=2>; \
652
+ rel="next", <https://some.host/v4_6_release/apis/3.0/finance/agreements&pageSize=10&page=3>; rel="last" ' ;
653
+
654
+ $ this ->response ->shouldReceive ('getHeader ' )
655
+ ->once ()
656
+ ->with ('Link ' )
657
+ ->andReturn ($ get_header_link );
658
+
659
+ $ this ->client ->getAll ('uri ' );
660
+ }
639
661
}
0 commit comments