1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\Pagantis\OrdersApiClient\Method; |
4
|
|
|
|
5
|
|
|
use Faker\Factory; |
6
|
|
|
use Httpful\Http; |
7
|
|
|
use Httpful\Request; |
8
|
|
|
use Pagantis\OrdersApiClient\Exception\ClientException; |
9
|
|
|
use Pagantis\OrdersApiClient\Method\ConfirmOrderMethod; |
10
|
|
|
use Pagantis\OrdersApiClient\Model\ApiConfiguration; |
11
|
|
|
use Test\Pagantis\OrdersApiClient\AbstractTest; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ConfirmOrderMethodTest |
15
|
|
|
* |
16
|
|
|
* @package Test\Pagantis\OrdersApiClient\Method; |
17
|
|
|
*/ |
18
|
|
|
class ConfirmOrderMethodTest extends AbstractTest |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* testEndpointConstant |
22
|
|
|
*/ |
23
|
|
|
public function testEndpointConstant() |
24
|
|
|
{ |
25
|
|
|
$constant = ConfirmOrderMethod::ENDPOINT; |
26
|
|
|
$this->assertEquals('/orders', $constant); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* testSetOrderId |
31
|
|
|
* |
32
|
|
|
* @throws \ReflectionException |
33
|
|
|
*/ |
34
|
|
|
public function testSetOrderId() |
35
|
|
|
{ |
36
|
|
|
$faker = Factory::create(); |
37
|
|
|
$orderId = $faker->uuid; |
38
|
|
|
$apiConfigurationMock = $this->getMock('Pagantis\OrdersApiClient\Model\ApiConfiguration'); |
39
|
|
|
$confirmOrderMethod = new ConfirmOrderMethod($apiConfigurationMock); |
40
|
|
|
$confirmOrderMethod->setOrderId($orderId); |
41
|
|
|
$reflectConfirmOrderMethod = new \ReflectionClass('Pagantis\OrdersApiClient\Method\ConfirmOrderMethod'); |
42
|
|
|
$property = $reflectConfirmOrderMethod->getProperty('orderId'); |
43
|
|
|
$property->setAccessible(true); |
44
|
|
|
$this->assertEquals($orderId, $property->getValue($confirmOrderMethod)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* testGetOrder |
49
|
|
|
* |
50
|
|
|
* @throws \ReflectionException |
51
|
|
|
* @throws \Exception |
52
|
|
|
*/ |
53
|
|
|
public function testGetOrder() |
54
|
|
|
{ |
55
|
|
|
$orderJson = file_get_contents($this->resourcePath.'Order.json'); |
56
|
|
|
$responseMock = $this->getMockBuilder('Httpful\Response')->disableOriginalConstructor()->getMock(); |
57
|
|
|
$responseMockReflect = new \ReflectionClass('Httpful\Response'); |
58
|
|
|
$property = $responseMockReflect->getProperty('body'); |
59
|
|
|
$property->setAccessible(true); |
60
|
|
|
$property->setValue($responseMock, json_decode($orderJson)); |
61
|
|
|
|
62
|
|
|
$apiConfigurationMock = $this->getMock('Pagantis\OrdersApiClient\Model\ApiConfiguration'); |
63
|
|
|
$confirmOrderMethod = new ConfirmOrderMethod($apiConfigurationMock); |
64
|
|
|
$this->assertFalse($confirmOrderMethod->getOrder()); |
|
|
|
|
65
|
|
|
$reflectConfirmOrderMethod = new \ReflectionClass('Pagantis\OrdersApiClient\Method\ConfirmOrderMethod'); |
66
|
|
|
$property = $reflectConfirmOrderMethod->getProperty('response'); |
67
|
|
|
$property->setAccessible(true); |
68
|
|
|
$property->setValue($confirmOrderMethod, $responseMock); |
69
|
|
|
|
70
|
|
|
$this->assertInstanceOf('Pagantis\OrdersApiClient\Model\Order', $confirmOrderMethod->getOrder()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* testPrepareRequest |
75
|
|
|
* |
76
|
|
|
* @throws \ReflectionException |
77
|
|
|
* @throws ClientException |
78
|
|
|
*/ |
79
|
|
|
public function testPrepareRequest() |
80
|
|
|
{ |
81
|
|
|
$faker = Factory::create(); |
82
|
|
|
$url = $faker->url; |
83
|
|
|
$orderId = $faker->uuid; |
84
|
|
|
$apiConfiguration = new ApiConfiguration(); |
85
|
|
|
$apiConfiguration->setBaseUri($url); |
86
|
|
|
$confirmOrderMethod = new ConfirmOrderMethod($apiConfiguration); |
87
|
|
|
$reflectConfirmOrderMethod = new \ReflectionClass('Pagantis\OrdersApiClient\Method\ConfirmOrderMethod'); |
88
|
|
|
$method = $reflectConfirmOrderMethod->getMethod('prepareRequest'); |
89
|
|
|
$method->setAccessible(true); |
90
|
|
|
$property = $reflectConfirmOrderMethod->getProperty('request'); |
91
|
|
|
$property->setAccessible(true); |
92
|
|
|
$this->assertNull($property->getValue($confirmOrderMethod)); |
93
|
|
|
$confirmOrderMethod->setOrderId($orderId); |
94
|
|
|
$method->invoke($confirmOrderMethod); |
95
|
|
|
/** @var Request $request */ |
96
|
|
|
$request = $property->getValue($confirmOrderMethod); |
97
|
|
|
$this->assertInstanceOf('Httpful\Request', $request); |
98
|
|
|
$this->assertSame(Http::PUT, $request->method); |
99
|
|
|
$uri = |
100
|
|
|
$url . |
101
|
|
|
ConfirmOrderMethod::ENDPOINT . |
102
|
|
|
ConfirmOrderMethod::SLASH . |
103
|
|
|
$orderId . |
104
|
|
|
ConfirmOrderMethod::SLASH . |
105
|
|
|
ConfirmOrderMethod::CONFIRM_ENDPOINT |
106
|
|
|
; |
107
|
|
|
$this->assertSame($uri, $request->uri); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* testCall |
112
|
|
|
* |
113
|
|
|
* @throws \Httpful\Exception\ConnectionErrorException |
114
|
|
|
* @throws \Pagantis\OrdersApiClient\Exception\HttpException |
115
|
|
|
*/ |
116
|
|
|
public function testCall() |
117
|
|
|
{ |
118
|
|
|
$apiConfigurationMock = $this->getMock('Pagantis\OrdersApiClient\Model\ApiConfiguration'); |
119
|
|
|
$confirmOrderMethod = new ConfirmOrderMethod($apiConfigurationMock); |
120
|
|
|
try { |
121
|
|
|
$confirmOrderMethod->call(); |
122
|
|
|
$this->assertTrue(false); |
123
|
|
|
} catch (ClientException $exception) { |
124
|
|
|
$this->assertInstanceOf('Pagantis\OrdersApiClient\Exception\ClientException', $exception); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|