|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright 2016 Jan Eichhorn <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace ApaiIO\Test\Request\Rest; |
|
19
|
|
|
|
|
20
|
|
|
use ApaiIO\Configuration\GenericConfiguration; |
|
21
|
|
|
use ApaiIO\Operations\Lookup; |
|
22
|
|
|
use ApaiIO\Request\Rest\Request; |
|
23
|
|
|
use Prophecy\Argument; |
|
24
|
|
|
use Psr\Http\Message\RequestInterface; |
|
25
|
|
|
|
|
26
|
|
|
class RequestTest extends \PHPUnit_Framework_TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
public function testPerform() |
|
29
|
|
|
{ |
|
30
|
|
|
$body = $this->prophesize('\Psr\Http\Message\StreamInterface'); |
|
31
|
|
|
$body |
|
32
|
|
|
->getContents() |
|
33
|
|
|
->shouldBeCalledTimes(1) |
|
34
|
|
|
->willReturn('ABC'); |
|
35
|
|
|
|
|
36
|
|
|
$response = $this->prophesize('\Psr\Http\Message\ResponseInterface'); |
|
37
|
|
|
$response |
|
38
|
|
|
->getBody() |
|
39
|
|
|
->shouldBeCalledTimes(1) |
|
40
|
|
|
->willReturn($body->reveal()); |
|
41
|
|
|
|
|
42
|
|
|
$client = $this->prophesize('\GuzzleHttp\ClientInterface'); |
|
43
|
|
|
|
|
44
|
|
|
$that = $this; |
|
45
|
|
|
|
|
46
|
|
|
$client |
|
47
|
|
|
->send(Argument::that(function ($request) use ($that) { |
|
48
|
|
|
if (!$request instanceof RequestInterface) { |
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$uri = $request->getUri(); |
|
53
|
|
|
$parts = []; |
|
54
|
|
|
parse_str($uri->getQuery(), $parts); |
|
55
|
|
|
|
|
56
|
|
|
$that->assertSame('webservices.amazon.de', $uri->getHost()); |
|
57
|
|
|
$that->assertSame('/onca/xml', $uri->getPath()); |
|
58
|
|
|
$that->assertArrayHasKey('AWSAccessKeyId', $parts); |
|
59
|
|
|
$that->assertSame('jkl', $parts['AWSAccessKeyId']); |
|
60
|
|
|
$that->assertArrayHasKey('AssociateTag', $parts); |
|
61
|
|
|
$that->assertSame('def', $parts['AssociateTag']); |
|
62
|
|
|
$that->assertArrayHasKey('ItemId', $parts); |
|
63
|
|
|
$that->assertSame('1', $parts['ItemId']); |
|
64
|
|
|
$that->assertArrayHasKey('Operation', $parts); |
|
65
|
|
|
$that->assertSame('ItemLookup', $parts['Operation']); |
|
66
|
|
|
$that->assertArrayHasKey('Service', $parts); |
|
67
|
|
|
$that->assertSame('AWSECommerceService', $parts['Service']); |
|
68
|
|
|
$that->assertArrayHasKey('Timestamp', $parts); |
|
69
|
|
|
$that->assertRegExp('#[0-9]{4}(-[0-9]{2}){2}T([0-9]{2}:){2}[0-9]{2}Z#', $parts['Timestamp']); |
|
70
|
|
|
$that->assertArrayHasKey('Version', $parts); |
|
71
|
|
|
$that->assertSame('2011-08-01', $parts['Version']); |
|
72
|
|
|
$that->assertArrayHasKey('Signature', $parts); |
|
73
|
|
|
return true; |
|
74
|
|
|
})) |
|
75
|
|
|
->shouldBeCalledTimes(1) |
|
76
|
|
|
->willReturn($response->reveal()); |
|
77
|
|
|
|
|
78
|
|
|
$request = new Request($client->reveal()); |
|
79
|
|
|
|
|
80
|
|
|
$operation = new Lookup(); |
|
81
|
|
|
$operation->setItemId('1'); |
|
82
|
|
|
|
|
83
|
|
|
$config = new GenericConfiguration(); |
|
84
|
|
|
$config->setAccessKey('abc'); |
|
85
|
|
|
$config->setAssociateTag('def'); |
|
86
|
|
|
$config->setCountry('DE'); |
|
87
|
|
|
$config->setSecretKey('ghi'); |
|
88
|
|
|
$config->setAccessKey('jkl'); |
|
89
|
|
|
|
|
90
|
|
|
$request->perform($operation, $config); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|