Code Duplication    Length = 16-18 lines in 5 locations

spec/ClientSpec.php 5 locations

@@ 127-144 (lines=18) @@
124
        $this->getRedirectLocation('/')->shouldBe('http://test.test');
125
    }
126
127
    public function it_processes_json_error_responses(ClientErrorException $exception)
128
    {
129
        $exception->getResponse()->willReturn(new Response(
130
            400,
131
            ['Content-Type' => 'application/json;charset=utf-8'],
132
            SpecHelper::getDummyData('error_response.json', false)
133
        ));
134
135
        $http = $this->let();
136
        $http->addException($exception->getWrappedObject());
137
138
        $this->shouldThrow(new RequestFailed(
139
            'Mandatory field is missing: library',
140
            '401664'
141
        ))->during('getJSON', ['/items/123']);
142
143
        expect($http->getRequests())->toHaveCount(1);
144
    }
145
146
    public function it_processes_xml_error_responses(ClientErrorException $exception)
147
    {
@@ 146-163 (lines=18) @@
143
        expect($http->getRequests())->toHaveCount(1);
144
    }
145
146
    public function it_processes_xml_error_responses(ClientErrorException $exception)
147
    {
148
        $exception->getResponse()->willReturn(new Response(
149
            400,
150
            ['Content-Type' => 'application/xml;charset=utf-8'],
151
            SpecHelper::getDummyData('error_response.xml', false)
152
        ));
153
154
        $http = $this->let();
155
        $http->addException($exception->getWrappedObject());
156
157
        $this->shouldThrow(new RequestFailed(
158
            'Mandatory field is missing: library',
159
            '401664'
160
        ))->during('getXML', ['/items/123']);
161
162
        expect($http->getRequests())->toHaveCount(1);
163
    }
164
165
    public function it_can_throw_resource_not_found(ClientErrorException $exception)
166
    {
@@ 165-180 (lines=16) @@
162
        expect($http->getRequests())->toHaveCount(1);
163
    }
164
165
    public function it_can_throw_resource_not_found(ClientErrorException $exception)
166
    {
167
        $exception->getResponse()->willReturn(new Response(
168
            400,
169
            ['Content-Type' => 'application/json;charset=utf-8'],
170
            SpecHelper::getDummyData('item_barcode_error_response.json', false)
171
        ));
172
173
        $http = $this->let();
174
        $http->addException($exception->getWrappedObject());
175
176
        $this->shouldThrow(new ResourceNotFound('No items found for barcode 123.', '401689'))
177
            ->during('getJSON', ['/items/123']);
178
179
        expect($http->getRequests())->toHaveCount(1);
180
    }
181
182
    public function it_can_throw_resource_not_found_for_500_errors_too(ServerErrorException $exception)
183
    {
@@ 182-198 (lines=17) @@
179
        expect($http->getRequests())->toHaveCount(1);
180
    }
181
182
    public function it_can_throw_resource_not_found_for_500_errors_too(ServerErrorException $exception)
183
    {
184
        // For Analytics reports, Alma will return 500, not 4xx
185
        $exception->getResponse()->willReturn(new Response(
186
            500,
187
            ['Content-Type' => 'application/xml;charset=utf-8'],
188
            SpecHelper::getDummyData('report_not_found_response.xml', false)
189
        ));
190
191
        $http = $this->let();
192
        $http->addException($exception->getWrappedObject());
193
194
        $this->shouldThrow(new ResourceNotFound('Path not found (/test/path)', 'INTERNAL_SERVER_ERROR'))
195
            ->during('getXML', ['/analytics/reports', ['path' => '/test/path']]);
196
197
        expect($http->getRequests())->toHaveCount(1);
198
    }
199
200
    public function it_can_throw_invalid_api_key(ClientErrorException $exception)
201
    {
@@ 200-215 (lines=16) @@
197
        expect($http->getRequests())->toHaveCount(1);
198
    }
199
200
    public function it_can_throw_invalid_api_key(ClientErrorException $exception)
201
    {
202
        $exception->getResponse()->willReturn(new Response(
203
            400,
204
            ['Content-Type' => 'text/plain;charset=UTF-8'],
205
            'Invalid API Key'
206
        ));
207
208
        $http = $this->let();
209
        $http->addException($exception->getWrappedObject());
210
211
        $this->shouldThrow(new InvalidApiKey('Invalid API Key', 0))
212
           ->during('getJSON', ['/items/123']);
213
214
        expect($http->getRequests())->toHaveCount(1);
215
    }
216
217
    public function it_will_retry_when_reaching_rate_limit(ClientErrorException $exception)
218
    {