|
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\GetOrderMethod; |
|
10
|
|
|
use Pagantis\OrdersApiClient\Model\ApiConfiguration; |
|
11
|
|
|
use Test\Pagantis\OrdersApiClient\AbstractTest; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class GetOrderMethodTest |
|
15
|
|
|
* |
|
16
|
|
|
* @package Test\Pagantis\OrdersApiClient\Method; |
|
17
|
|
|
*/ |
|
18
|
|
|
class GetOrderMethodTest extends AbstractTest |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* testEndpointConstant |
|
22
|
|
|
*/ |
|
23
|
|
|
public function testEndpointConstant() |
|
24
|
|
|
{ |
|
25
|
|
|
$constant = GetOrderMethod::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
|
|
|
$getOrderMethod = new GetOrderMethod($apiConfigurationMock); |
|
40
|
|
|
$getOrderMethod->setOrderId($orderId); |
|
41
|
|
|
$reflectGetOrderMethod = new \ReflectionClass('Pagantis\OrdersApiClient\Method\GetOrderMethod'); |
|
42
|
|
|
$property = $reflectGetOrderMethod->getProperty('orderId'); |
|
43
|
|
|
$property->setAccessible(true); |
|
44
|
|
|
$this->assertEquals($orderId, $property->getValue($getOrderMethod)); |
|
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
|
|
|
$getOrderMethod = new GetOrderMethod($apiConfigurationMock); |
|
64
|
|
|
$this->assertFalse($getOrderMethod->getOrder()); |
|
|
|
|
|
|
65
|
|
|
$reflectGetOrderMethod = new \ReflectionClass('Pagantis\OrdersApiClient\Method\GetOrderMethod'); |
|
66
|
|
|
$property = $reflectGetOrderMethod->getProperty('response'); |
|
67
|
|
|
$property->setAccessible(true); |
|
68
|
|
|
$property->setValue($getOrderMethod, $responseMock); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertInstanceOf('Pagantis\OrdersApiClient\Model\Order', $getOrderMethod->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
|
|
|
$getOrderMethod = new GetOrderMethod($apiConfiguration); |
|
87
|
|
|
$reflectGetOrderMethod = new \ReflectionClass('Pagantis\OrdersApiClient\Method\GetOrderMethod'); |
|
88
|
|
|
$method = $reflectGetOrderMethod->getMethod('prepareRequest'); |
|
89
|
|
|
$method->setAccessible(true); |
|
90
|
|
|
$property = $reflectGetOrderMethod->getProperty('request'); |
|
91
|
|
|
$property->setAccessible(true); |
|
92
|
|
|
$this->assertNull($property->getValue($getOrderMethod)); |
|
93
|
|
|
$getOrderMethod->setOrderId($orderId); |
|
94
|
|
|
$method->invoke($getOrderMethod); |
|
95
|
|
|
/** @var Request $request */ |
|
96
|
|
|
$request = $property->getValue($getOrderMethod); |
|
97
|
|
|
$this->assertInstanceOf('Httpful\Request', $request); |
|
98
|
|
|
$this->assertSame(Http::GET, $request->method); |
|
99
|
|
|
$uri = $url . GetOrderMethod::ENDPOINT . GetOrderMethod::SLASH . $orderId; |
|
100
|
|
|
$this->assertSame($uri, $request->uri); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* testCall |
|
105
|
|
|
* |
|
106
|
|
|
* @throws \Httpful\Exception\ConnectionErrorException |
|
107
|
|
|
* @throws \Pagantis\OrdersApiClient\Exception\HttpException |
|
108
|
|
|
*/ |
|
109
|
|
|
public function testCall() |
|
110
|
|
|
{ |
|
111
|
|
|
$apiConfigurationMock = $this->getMock('Pagantis\OrdersApiClient\Model\ApiConfiguration'); |
|
112
|
|
|
$getOrderMethod = new GetOrderMethod($apiConfigurationMock); |
|
113
|
|
|
try { |
|
114
|
|
|
$getOrderMethod->call(); |
|
115
|
|
|
$this->assertTrue(false); |
|
116
|
|
|
} catch (ClientException $exception) { |
|
117
|
|
|
$this->assertInstanceOf('Pagantis\OrdersApiClient\Exception\ClientException', $exception); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|