Example #1
0
 public function testHeaderAccessors()
 {
     // A new message shouldn't have any RFC-822 headers set
     $message = new \SendGrid\Email();
     $this->assertEquals('{}', $message->getSmtpapi()->jsonString());
     // Add some message headers, check they are correctly stored
     $headers = ['X-Sent-Using' => 'SendGrid-API', 'X-Transport' => 'web'];
     $message->setHeaders($headers);
     $this->assertEquals($headers, $message->getHeaders());
     // Add another header, check if it is stored
     $message->addHeader('X-Another-Header', 'first_value');
     $headers['X-Another-Header'] = 'first_value';
     $this->assertEquals($headers, $message->getHeaders());
     // Replace a header
     $message->addHeader('X-Another-Header', 'second_value');
     $headers['X-Another-Header'] = 'second_value';
     $this->assertEquals($headers, $message->getHeaders());
     // Get the encoded headers; they must be a valid JSON
     $json = $message->getHeadersJson();
     $decoded = json_decode($json, TRUE);
     $this->assertInternalType('array', $decoded);
     // Test we get the same message headers we put in the message
     $this->assertEquals($headers, $decoded);
     // Remove a header
     $message->removeHeader('X-Transport');
     unset($headers['X-Transport']);
     $this->assertEquals($headers, $message->getHeaders());
 }