Slack\Message\Message::addAttachment PHP Method

addAttachment() public method

addAttachment
public addAttachment ( MessageAttachment $attachment )
$attachment MessageAttachment
    public function addAttachment(MessageAttachment $attachment)
    {
        $this->attachments[] = $attachment;
    }

Usage Example

Example #1
0
 /**
  * @covers Slack\Notifier::notify
  */
 public function testNotify()
 {
     $client = $this->getMockBuilder('\\Slack\\Client')->disableOriginalConstructor()->getMock(array('post'));
     $request = $this->getMockBuilder('\\Guzzle\\Http\\Message\\Request')->disableOriginalConstructor()->getMock(array('send'));
     $message = new Message('Hello world');
     $message->setChannel('#test')->setIconEmoji(':ghost:')->setUsername('slack-php');
     $attachment = new \Slack\Message\MessageAttachment();
     $field = new \Slack\Message\MessageField();
     $field->setTitle('foo')->setValue('bar')->setShort(false);
     $attachment->addField($field);
     $message->addAttachment($attachment);
     $expectedDatas = json_encode(array('text' => $message->getText(), 'channel' => $message->getChannel(), 'username' => 'slack-php', 'icon_emoji' => ':ghost:', 'attachments' => array(array('fields' => array(array('title' => 'foo', 'value' => 'bar', 'short' => false))))));
     $client->expects($this->once())->method('post')->with($this->equalTo('/services/hooks/incoming-webhook'), $this->anything(), $this->equalTo($expectedDatas), $this->anything())->will($this->returnValue($request));
     $notifier = new Notifier($client);
     $notifier->notify($message);
 }