public function it_should_send_email_with_headers(\SendGrid $sendGrid) { $recipient = new Recipient('Jane Doe', '*****@*****.**'); $header = new Header('Some-SMTP-header', 'Example value 1'); $anotherHeader = new Header('Some-another-SMTP-header', 'Example value 2'); $this->addRecipient($recipient); $this->setReplyTo('*****@*****.**'); $this->addHeader($header); $this->addHeader($anotherHeader); $email = new \SendGrid\Email(); $email->setFrom('*****@*****.**'); $email->setFromName('Master Jedi Yoda'); $email->addSmtpapiTo('*****@*****.**', 'Jane Doe'); $email->setSubject('Example subject'); $email->setHtml(' '); $email->setTemplateId('example-template'); $email->setReplyTo('*****@*****.**'); $email->setHeaders(['Some-SMTP-header' => 'Example value 1', 'Some-another-SMTP-header' => 'Example value 2']); $sendGrid->send($email)->shouldBeCalled(); $this->send('Example subject', 'example-template')->shouldReturn(true); }
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()); }