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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
<?php
/**
* This file tests the SendGrid Client
*
* PHP Version - 5.6, 7.0, 7.1, 7.2
*
* @package SendGrid\Tests
* @author Elmer Thomas <dx@sendgrid.com>
* @copyright 2018-19 Twilio SendGrid
* @license https://opensource.org/licenses/MIT The MIT License
* @version GIT: <git_id>
* @link http://packagist.org/packages/sendgrid/sendgrid
*/
namespace SendGrid\Tests;
/**
* This class tests the Twilio SendGrid Client
*
* @package SendGrid\Tests
*/
class SendGridTest extends BaseTestClass
{
/**
* Test if the version is correct
*/
public function testVersionIsCorrect()
{
$this->assertEquals(\SendGrid::VERSION, '7.3.0');
$version = json_decode(
file_get_contents(__DIR__ . '/../../composer.json')
)->version;
$this->assertEquals(
$version,
\SendGrid::VERSION
);
}
/**
* Test that we can connect to the Twilio SendGrid API
*/
public function testCanConnectToSendGridApi()
{
$sg = new \SendGrid(self::$apiKey);
$headers = [
'Authorization: Bearer ' . self::$apiKey,
'User-Agent: sendgrid/' . $sg->version . ';php',
'Accept: application/json'
];
$this->assertEquals(
$sg->client->getHost(),
'https://api.sendgrid.com',
'/v3'
);
$this->assertEquals(
$sg->client->getHeaders(),
$headers
);
$this->assertEquals($sg->client->getVersion(), '/v3');
$sg2 = new \SendGrid(self::$apiKey, ['host' => 'https://api.test.com']);
$this->assertEquals($sg2->client->getHost(), 'https://api.test.com');
$sg3 = new \SendGrid(self::$apiKey, ['curl' => ['foo' => 'bar']]);
$this->assertEquals(['foo' => 'bar'], $sg3->client->getCurlOptions());
$sg4 = new \SendGrid(
self::$apiKey,
['curl' => [CURLOPT_PROXY => '127.0.0.1:8000']]
);
$this->assertEquals(
$sg4->client->getCurlOptions(),
[10004 => '127.0.0.1:8000']
);
$subuser = 'abcxyz@this.is.a.test.subuser';
$headers[] = 'On-Behalf-Of: ' . $subuser;
$sg5 = new \SendGrid(
self::$apiKey,
['impersonateSubuser' => $subuser]
);
$this->assertSame(
$headers,
$sg5->client->getHeaders()
);
}
}
|