public function testCreateMessageFromGroup()
 {
     $timestamp = time();
     $mediaNodeMock = m::mock('Tmv\\WhatsApi\\Message\\Node\\NodeInterface');
     $mediaMock = m::mock('Tmv\\WhatsApi\\Message\\Received\\Media\\MediaInterface');
     $mediaFactoryMock = m::mock('Tmv\\WhatsApi\\Message\\Received\\Media\\MediaFactory');
     $mediaFactoryMock->shouldReceive('createMedia')->with($mediaNodeMock)->once()->andReturn($mediaMock);
     $this->object->setMediaFactory($mediaFactoryMock);
     $nodeMock = m::mock('Tmv\\WhatsApi\\Message\\Node\\NodeInterface');
     $nodeMock->shouldReceive('getAttribute')->with('from')->once()->andReturn('393921234567-1234567@server');
     $nodeMock->shouldReceive('getAttribute')->with('participant')->once()->andReturn('393921234567@server');
     $nodeMock->shouldReceive('getAttribute')->with('id')->once()->andReturn('message-12234567');
     $nodeMock->shouldReceive('getAttribute')->with('t')->once()->andReturn($timestamp);
     $nodeMock->shouldReceive('getAttribute')->with('notify')->once()->andReturn('test-notify');
     $nodeMock->shouldReceive('getAttribute')->with('type')->once()->andReturn('media');
     $nodeMock->shouldReceive('getChild')->with('media')->once()->andReturn($mediaNodeMock);
     $ret = $this->object->createMessage($nodeMock);
     $this->assertInstanceOf('Tmv\\WhatsApi\\Message\\Received\\MessageMedia', $ret);
     $this->assertEquals('393921234567', $ret->getFrom());
     $this->assertTrue($ret->isFromGroup());
     $this->assertEquals('393921234567-1234567', $ret->getGroupId());
     $this->assertEquals('message-12234567', $ret->getId());
     $dateTime = new DateTime();
     $dateTime->setTimestamp($timestamp);
     $this->assertEquals($dateTime, $ret->getDateTime());
     $this->assertEquals('test-notify', $ret->getNotify());
     $this->assertEquals('media', $ret->getType());
     $this->assertEquals($mediaMock, $ret->getMedia());
 }
Beispiel #2
0
 /**
  * @param  NodeInterface             $node
  * @return MessageMedia|MessageText
  * @throws \InvalidArgumentException
  */
 public function createMessage(NodeInterface $node)
 {
     $type = $node->getAttribute('type');
     switch ($type) {
         case AbstractMessage::TYPE_TEXT:
             $factory = new MessageTextFactory();
             break;
         case AbstractMessage::TYPE_MEDIA:
             $factory = new MessageMediaFactory();
             break;
         default:
             throw new InvalidArgumentException("Invalid message type");
     }
     return $factory->createMessage($node);
 }