Slack\Notifier::notify PHP Method

notify() public method

notify
public notify ( Slack\Message\MessageInterface $message, boolean $debug = false )
$message Slack\Message\MessageInterface
$debug boolean
    public function notify(MessageInterface $message, $debug = false)
    {
        $payload = $this->serializer->serialize($message, 'json');
        $request = $this->client->post('/services/hooks/incoming-webhook', array(), $payload, array('debug' => $debug));
        $request->send();
    }

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);
 }