-
Notifications
You must be signed in to change notification settings - Fork 629
/
Copy pathBaseTestClass.php
63 lines (57 loc) · 1.55 KB
/
BaseTestClass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* This file contains the base class for testing the request object
* generation for a /mail/send API call
*/
namespace SendGrid\Tests;
use PHPUnit\Framework\TestCase;
use SendGrid;
use Swaggest\JsonDiff\JsonDiff;
use Swaggest\JsonDiff\JsonPatch;
/**
* This class facilitates testing the request object
* generation for a /mail/send API call
*
* @package SendGrid\Mail
*/
class BaseTestClass extends TestCase
{
/** @var string Twilio SendGrid API Key */
protected static $apiKey;
/** @var SendGrid Twilio SendGrid client */
protected static $sg;
/**
* This method is run before the classes are initialised
*
* @return void
*/
public static function setUpBeforeClass(): void
{
self::$apiKey = 'SENDGRID_API_KEY';
self::$sg = new SendGrid(self::$apiKey);
}
/**
* Compares to JSON objects and returns True if equal,
* else return array of differences
*
* @param string $json1 A string representation of a JSON object
* @param string $json2 A string representation of a JSON object
*
* @return bool|array
* @throws \Swaggest\JsonDiff\Exception
*/
public static function compareJSONObjects($json1, $json2)
{
$diff = new JsonDiff(
json_decode($json1),
json_decode($json2),
JsonDiff::REARRANGE_ARRAYS
);
$patch = $diff->getPatch();
$patch_array = JsonPatch::export($patch);
if (empty($patch_array)) {
return true;
}
return $patch_array;
}
}