7
7
8
8
namespace MessageMediaWebhooksLib \Tests ;
9
9
10
+
10
11
use MessageMediaWebhooksLib \APIHelper ;
11
12
use \apimatic \jsonmapper \JsonMapper ;
13
+ use MessageMediaWebhooksLib \Configuration ;
12
14
13
15
/**
14
16
* Configure Test Constants
@@ -58,7 +60,7 @@ public static function isProperSubsetOf(
58
60
$ allowExtra ,
59
61
$ isOrdered
60
62
) {
61
-
63
+
62
64
if ($ leftTree == null ) {
63
65
return true ;
64
66
}
@@ -123,7 +125,7 @@ public static function isProperSubsetOf(
123
125
}
124
126
return true ;
125
127
}
126
-
128
+
127
129
/**
128
130
* Recursively check whether the left JSON object is a proper subset of the right JSON object
129
131
* @param array $leftObject Left JSON object as string
@@ -140,7 +142,7 @@ public static function isJsonObjectProperSubsetOf(
140
142
$ allowExtra ,
141
143
$ isOrdered
142
144
) {
143
-
145
+
144
146
return static ::isProperSubsetOf (
145
147
APIHelper::deserialize ($ leftObject ),
146
148
APIHelper::deserialize ($ rightObject ),
@@ -149,7 +151,7 @@ public static function isJsonObjectProperSubsetOf(
149
151
$ isOrdered
150
152
);
151
153
}
152
-
154
+
153
155
/**
154
156
* Check if left array of objects is a subset of right array
155
157
* @param array $leftObject Left array as a JSON string
@@ -166,11 +168,11 @@ public static function isArrayOfStringifiedJsonObjectsProperSubsetOf(
166
168
$ allowExtra ,
167
169
$ isOrdered
168
170
) {
169
-
171
+
170
172
// Deserialize left and right objects from their respective strings
171
173
$ left = APIHelper::deserialize ($ leftObject );
172
174
$ right = APIHelper::deserialize ($ rightObject );
173
-
175
+
174
176
return static ::isArrayOfJsonObjectsProperSubsetOf (
175
177
$ left ,
176
178
$ right ,
@@ -196,27 +198,27 @@ public static function isArrayOfJsonObjectsProperSubsetOf(
196
198
$ allowExtra ,
197
199
$ isOrdered
198
200
) {
199
-
201
+
200
202
// Return false if size different and checking was strict
201
203
if (!$ allowExtra && count ($ left ) != count ($ right )) {
202
204
return false ;
203
205
}
204
-
206
+
205
207
// Create list iterators
206
208
$ leftIter = (new \ArrayObject ($ left ))->getIterator ();
207
209
$ rightIter = (new \ArrayObject ($ right ))->getIterator ();
208
-
210
+
209
211
// Iterate left list and check if each value is present in the right list
210
212
while ($ leftIter ->valid ()) {
211
213
$ leftIter ->next ();
212
214
$ leftTree = $ leftIter ->current ();
213
215
$ found = false ;
214
-
216
+
215
217
// If order is not required, then search right array from beginning
216
218
if (!$ isOrdered ) {
217
219
$ rightIter ->rewind ();
218
220
}
219
-
221
+
220
222
// Check each right element to see if left is a subset
221
223
while ($ rightIter ->valid ()) {
222
224
$ rightIter ->next ();
@@ -231,15 +233,15 @@ public static function isArrayOfJsonObjectsProperSubsetOf(
231
233
break ;
232
234
}
233
235
}
234
-
236
+
235
237
if (!$ found ) {
236
238
return false ;
237
239
}
238
240
}
239
-
241
+
240
242
return true ;
241
243
}
242
-
244
+
243
245
/**
244
246
* Check whether the a list is a subset of another list
245
247
* @param array $leftList Expected List
@@ -254,7 +256,7 @@ public static function isListProperSubsetOf(
254
256
$ allowExtra ,
255
257
$ isOrdered
256
258
) {
257
-
259
+
258
260
if ($ isOrdered && !$ allowExtra ) {
259
261
return $ leftList === $ rightList ;
260
262
} elseif ($ isOrdered && $ allowExtra ) {
@@ -267,7 +269,7 @@ public static function isListProperSubsetOf(
267
269
}
268
270
return true ;
269
271
}
270
-
272
+
271
273
/**
272
274
* Recursively check whether the left headers map is a proper subset of
273
275
* the right headers map. Header keys & values are compared case-insensitive.
@@ -282,7 +284,7 @@ public static function areHeadersProperSubsetOf(
282
284
array $ rightTree ,
283
285
$ checkValues
284
286
) {
285
-
287
+
286
288
// Http headers are case-insensitive
287
289
$ l = array_change_key_case ($ leftTree );
288
290
$ r = array_change_key_case ($ rightTree );
@@ -345,4 +347,10 @@ public static function getJsonMapper()
345
347
return $ mapper ;
346
348
}
347
349
350
+ public static function getAuthorizationFromEnvironment ()
351
+ {
352
+ Configuration::$ basicAuthUserName = getenv ('MessageMediaApiTestsKey ' );
353
+ Configuration::$ basicAuthPassword = getenv ('MessageMediaApiTestsSecret ' );
354
+ }
355
+
348
356
}
0 commit comments