Inheritance: implements rcrowe\Hippy\Message\SenderInterface, implements rcrowe\Hippy\Message\MessageInterface
Beispiel #1
0
 public function testHtmlMessageLength()
 {
     $msg = str_pad('', 9999, 'jnk3j1');
     $message = new Message();
     $message->setHtml($msg);
     $msg = str_pad('', 10000, 'jnk3j1');
     $message = new Message();
     $message->setHtml($msg);
     try {
         $msg = str_pad('', 10001, 'jnk3j1');
         $message = new Message();
         $message->setHtml($msg);
         $this->assertFalse(true);
     } catch (InvalidArgumentException $ex) {
         $this->assertEquals($ex->getMessage(), 'Message more than 10,000 characters');
     } catch (Exception $ex) {
         $this->assertFalse(true);
     }
 }
Beispiel #2
0
 public function testSetText()
 {
     $message = new Message();
     $message->setText('egg and spoon race');
     $this->assertEquals($message->getMessage(), 'egg and spoon race');
     $message->setText('<a href="#">hello</a>');
     $this->assertEquals($message->getMessage(), '<a href="#">hello</a>');
     $this->assertEquals($message->getMessageFormat(), Message::FORMAT_TEXT);
 }
Beispiel #3
0
 public function testPost()
 {
     $guzzle = new Guzzle('123', 'cog', 'vivalacrowe');
     $message = new Message(true, 'green');
     $entity = m::mock('Guzzle\\Http\\Message\\EntityEnclosingRequest');
     $entity->shouldReceive('send')->once();
     // Build up the data we are sending to Hipchat
     $data = array('room_id' => $guzzle->getRoom(), 'from' => $guzzle->getFrom(), 'message' => $message->getMessage(), 'message_format' => $message->getMessageFormat(), 'notify' => $message->getNotification(), 'color' => $message->getBackgroundColor(), 'format' => 'json');
     $http = m::mock('Guzzle\\Http\\Client');
     $http->shouldReceive('post')->with('rooms/message?format=json&auth_token=123', array('Content-type' => 'application/x-www-form-urlencoded'), http_build_query($data))->andReturn($entity)->once();
     $guzzle->setHttp($http);
     $guzzle->send($message);
 }
Beispiel #4
0
 public function testGray()
 {
     $message = new Message(false, Message::BACKGROUND_GRAY);
     $this->assertEquals($message->getBackgroundColor(), 'gray');
 }
Beispiel #5
0
 public function main($transport = null)
 {
     $transport or $transport = new Guzzle($this->getToken(), $this->getRoom(), $this->getFrom());
     $client = new Client($transport);
     foreach ($this->msgStore as $msg) {
         $message = new Message($this->getNotify(), $this->getBackground());
         switch ($msg['format']) {
             case Message::FORMAT_TEXT:
                 $message->setText($msg['msg']);
                 break;
             case Message::FORMAT_HTML:
                 $message->setHtml($msg['msg']);
                 break;
             default:
                 throw new BuildException('Unknown message format');
         }
         $client->send($message);
     }
 }
Beispiel #6
0
 public function testQueueIteratorInterface()
 {
     $values = array('RC', 'Dog', 'Cat', 'Carrot Cake');
     foreach ($values as $value) {
         $message = new Message();
         $message->setText($value);
         $this->queue->add($message);
     }
     foreach ($this->queue as $value) {
         $this->assertTrue(in_array($value->getMessage(), $values));
     }
     foreach ($this->queue as $key => $value) {
         $this->assertTrue(is_integer($key));
         $this->assertEquals($value->getMessage(), $values[$key]);
     }
 }
Beispiel #7
0
 /**
  * Add a html message to the queue.
  *
  * @param string $msg
  * @param bool   $notify
  * @param string $background
  * @throws RuntimeException When Facade::init() has not been called.
  * @return void
  */
 public static function addHtml($msg, $notify = false, $background = Message::BACKGROUND_YELLOW)
 {
     if (static::$client === null) {
         throw new RuntimeException('Must call init first');
     }
     $message = new Message($notify, $background);
     $message->setHtml($msg);
     static::$queue->add($message);
 }