1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lifeboat\Tests; |
4
|
|
|
|
5
|
|
|
use Lifeboat\Exceptions\InvalidArgumentException; |
6
|
|
|
use Lifeboat\Resource\ListResource; |
7
|
|
|
use Lifeboat\Resource\SimpleList; |
8
|
|
|
use Lifeboat\Services\Addresses; |
9
|
|
|
use Lifeboat\Services\Collections; |
10
|
|
|
use Lifeboat\Services\Customers; |
11
|
|
|
use Lifeboat\Services\CustomPages; |
12
|
|
|
use Lifeboat\Services\DeliveryZones; |
13
|
|
|
use Lifeboat\Services\Orders; |
14
|
|
|
use Lifeboat\Services\Pages; |
15
|
|
|
|
16
|
|
|
class ServicesTest extends TestCase { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @test |
20
|
|
|
* @covers \Lifeboat\Services\Addresses::all |
21
|
|
|
*/ |
22
|
|
|
public function test_address_all() |
23
|
|
|
{ |
24
|
|
|
$service = new Addresses($this->getMockClient()); |
25
|
|
|
$this->check_curl_all( |
26
|
|
|
$service->all('xxx'), |
27
|
|
|
'api/addresses/all', |
28
|
|
|
ListResource::class, |
29
|
|
|
['search' => 'xxx'] |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
* @covers \Lifeboat\Services\Collections::all |
36
|
|
|
*/ |
37
|
|
|
public function test_collections_all() |
38
|
|
|
{ |
39
|
|
|
$service = new Collections($this->getMockClient()); |
40
|
|
|
$this->check_curl_all($service->all(), 'api/collections/all'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
* @covers \Lifeboat\Services\Customers::all |
46
|
|
|
*/ |
47
|
|
|
public function test_customers_all() |
48
|
|
|
{ |
49
|
|
|
$service = new Customers($this->getMockClient()); |
50
|
|
|
$this->check_curl_all( |
51
|
|
|
$service->all('xxx'), |
52
|
|
|
'api/customers/all', |
53
|
|
|
ListResource::class, |
54
|
|
|
['search' => 'xxx'] |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @test |
60
|
|
|
* @covers \Lifeboat\Services\CustomPages::all |
61
|
|
|
*/ |
62
|
|
|
public function test_custom_pages_all() |
63
|
|
|
{ |
64
|
|
|
$service = new CustomPages($this->getMockClient()); |
65
|
|
|
$this->check_curl_all( |
66
|
|
|
$service->all('xxx'), |
67
|
|
|
'api/pages/page/all', |
68
|
|
|
ListResource::class, |
69
|
|
|
['search' => 'xxx', 'sort' => CustomPages::SORT_DEFAULT] |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
try { |
73
|
|
|
$service->all('xxx', 'xxx'); |
74
|
|
|
$this->fail('CustomPages::all() parameter 2 should be a valid sort'); |
75
|
|
|
} catch (InvalidArgumentException $e) { |
76
|
|
|
// Error should have been thrown |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @test |
82
|
|
|
* @covers \Lifeboat\Services\DeliveryZones::all |
83
|
|
|
*/ |
84
|
|
|
public function test_delivery_zones_all() |
85
|
|
|
{ |
86
|
|
|
$service = new DeliveryZones($this->getMockClient()); |
87
|
|
|
$this->check_curl_all($service->all(), 'api/delivery-zones/all'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @test |
92
|
|
|
* @covers \Lifeboat\Services\Orders::all |
93
|
|
|
*/ |
94
|
|
|
public function test_orders_all() |
95
|
|
|
{ |
96
|
|
|
$params = ['period' => Orders::PERIOD_7, 'status' => Orders::STATUS_PAID, 'fulfillment' => Orders::FULFILLMENT_PENDING]; |
97
|
|
|
|
98
|
|
|
$service = new Orders($this->getMockClient()); |
99
|
|
|
$this->check_curl_all($service->all(), 'api/orders/all', ListResource::class, $params); |
100
|
|
|
|
101
|
|
|
try { |
102
|
|
|
$service->all('xxx'); |
103
|
|
|
$this->fail('Orders::all expects parameter 1 to be a valid period'); |
104
|
|
|
} catch (InvalidArgumentException $e) { |
105
|
|
|
// Error should have been thrown |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
try { |
109
|
|
|
$service->all(Orders::PERIOD_7, -1); |
110
|
|
|
$this->fail('Orders::all expects parameter 2 to be a valid status'); |
111
|
|
|
} catch (InvalidArgumentException $e) { |
112
|
|
|
// Error should have been thrown |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
try { |
116
|
|
|
$service->all(Orders::PERIOD_7, Orders::STATUS_PAID, -1); |
117
|
|
|
$this->fail('Orders::all expects parameter 3 to be a valid fulfillment status'); |
118
|
|
|
} catch (InvalidArgumentException $e) { |
119
|
|
|
// Error should have been thrown |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @test |
125
|
|
|
* @covers \Lifeboat\Services\Pages::all |
126
|
|
|
*/ |
127
|
|
|
public function test_pages_all() |
128
|
|
|
{ |
129
|
|
|
$service = new Pages($this->getMockClient()); |
130
|
|
|
$this->check_curl_all($service->all(), 'api/pages/all', SimpleList::class); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @covers \Lifeboat\Resource\ListResource::getClient |
135
|
|
|
* @covers \Lifeboat\Resource\ListResource::setClient |
136
|
|
|
* @covers \Lifeboat\Resource\ListResource::getURL |
137
|
|
|
* @covers \Lifeboat\Resource\ListResource::setURL |
138
|
|
|
* @covers \Lifeboat\Resource\ListResource::getParams |
139
|
|
|
* @covers \Lifeboat\Resource\ListResource::setParams |
140
|
|
|
* |
141
|
|
|
* @param ListResource $all |
142
|
|
|
* @param string $list_class |
143
|
|
|
* @param string $url |
144
|
|
|
* @param array $params |
145
|
|
|
*/ |
146
|
|
|
private function check_curl_all( |
147
|
|
|
ListResource $all, |
148
|
|
|
string $url, |
149
|
|
|
string $list_class = ListResource::class, |
150
|
|
|
array $params = [] |
151
|
|
|
){ |
152
|
|
|
$this->assertInstanceOf($list_class, $all); |
153
|
|
|
$this->assertEquals($url, $all->getURL()); |
154
|
|
|
$this->assertEquals($this->getMockClient(), $all->getClient()); |
155
|
|
|
$this->assertEquals($params, $all->getParams()); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|