Skip to content

Commit 4632dd6

Browse files
authored
Merge pull request #2 from messagemedia/fix-tests
Fix tests
2 parents 5c9cde9 + 865dc58 commit 4632dd6

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

tests/Controllers/WebhooksControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ class WebhooksControllerTest extends \PHPUnit_Framework_TestCase
2929
*/
3030
public static function setUpBeforeClass()
3131
{
32+
TestHelper::getAuthorizationFromEnvironment();
3233
$client = new \MessageMediaWebhooksLib\MessageMediaWebhooksClient();
3334
self::$controller = $client->getWebhooks();
35+
3436
}
3537

3638
/**

tests/TestHelper.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
namespace MessageMediaWebhooksLib\Tests;
99

10+
1011
use MessageMediaWebhooksLib\APIHelper;
1112
use \apimatic\jsonmapper\JsonMapper;
13+
use MessageMediaWebhooksLib\Configuration;
1214

1315
/**
1416
* Configure Test Constants
@@ -58,7 +60,7 @@ public static function isProperSubsetOf(
5860
$allowExtra,
5961
$isOrdered
6062
) {
61-
63+
6264
if ($leftTree == null) {
6365
return true;
6466
}
@@ -123,7 +125,7 @@ public static function isProperSubsetOf(
123125
}
124126
return true;
125127
}
126-
128+
127129
/**
128130
* Recursively check whether the left JSON object is a proper subset of the right JSON object
129131
* @param array $leftObject Left JSON object as string
@@ -140,7 +142,7 @@ public static function isJsonObjectProperSubsetOf(
140142
$allowExtra,
141143
$isOrdered
142144
) {
143-
145+
144146
return static::isProperSubsetOf(
145147
APIHelper::deserialize($leftObject),
146148
APIHelper::deserialize($rightObject),
@@ -149,7 +151,7 @@ public static function isJsonObjectProperSubsetOf(
149151
$isOrdered
150152
);
151153
}
152-
154+
153155
/**
154156
* Check if left array of objects is a subset of right array
155157
* @param array $leftObject Left array as a JSON string
@@ -166,11 +168,11 @@ public static function isArrayOfStringifiedJsonObjectsProperSubsetOf(
166168
$allowExtra,
167169
$isOrdered
168170
) {
169-
171+
170172
// Deserialize left and right objects from their respective strings
171173
$left = APIHelper::deserialize($leftObject);
172174
$right = APIHelper::deserialize($rightObject);
173-
175+
174176
return static::isArrayOfJsonObjectsProperSubsetOf(
175177
$left,
176178
$right,
@@ -196,27 +198,27 @@ public static function isArrayOfJsonObjectsProperSubsetOf(
196198
$allowExtra,
197199
$isOrdered
198200
) {
199-
201+
200202
// Return false if size different and checking was strict
201203
if (!$allowExtra && count($left) != count($right)) {
202204
return false;
203205
}
204-
206+
205207
// Create list iterators
206208
$leftIter = (new \ArrayObject($left))->getIterator();
207209
$rightIter = (new \ArrayObject($right))->getIterator();
208-
210+
209211
// Iterate left list and check if each value is present in the right list
210212
while ($leftIter->valid()) {
211213
$leftIter->next();
212214
$leftTree = $leftIter->current();
213215
$found = false;
214-
216+
215217
// If order is not required, then search right array from beginning
216218
if (!$isOrdered) {
217219
$rightIter->rewind();
218220
}
219-
221+
220222
// Check each right element to see if left is a subset
221223
while ($rightIter->valid()) {
222224
$rightIter->next();
@@ -231,15 +233,15 @@ public static function isArrayOfJsonObjectsProperSubsetOf(
231233
break;
232234
}
233235
}
234-
236+
235237
if (!$found) {
236238
return false;
237239
}
238240
}
239-
241+
240242
return true;
241243
}
242-
244+
243245
/**
244246
* Check whether the a list is a subset of another list
245247
* @param array $leftList Expected List
@@ -254,7 +256,7 @@ public static function isListProperSubsetOf(
254256
$allowExtra,
255257
$isOrdered
256258
) {
257-
259+
258260
if ($isOrdered && !$allowExtra) {
259261
return $leftList === $rightList;
260262
} elseif ($isOrdered && $allowExtra) {
@@ -267,7 +269,7 @@ public static function isListProperSubsetOf(
267269
}
268270
return true;
269271
}
270-
272+
271273
/**
272274
* Recursively check whether the left headers map is a proper subset of
273275
* the right headers map. Header keys & values are compared case-insensitive.
@@ -282,7 +284,7 @@ public static function areHeadersProperSubsetOf(
282284
array $rightTree,
283285
$checkValues
284286
) {
285-
287+
286288
// Http headers are case-insensitive
287289
$l = array_change_key_case($leftTree);
288290
$r = array_change_key_case($rightTree);
@@ -345,4 +347,10 @@ public static function getJsonMapper()
345347
return $mapper;
346348
}
347349

350+
public static function getAuthorizationFromEnvironment()
351+
{
352+
Configuration::$basicAuthUserName = getenv('MessageMediaApiTestsKey');
353+
Configuration::$basicAuthPassword = getenv('MessageMediaApiTestsSecret');
354+
}
355+
348356
}

0 commit comments

Comments
 (0)