Skip to content

Commit

Permalink
Add PHPUnit test for MessageWrapper implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnert committed Jan 22, 2015
1 parent a61a543 commit 148908b
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 0 deletions.
140 changes: 140 additions & 0 deletions src/AppserverIo/Psr/Pms/MessageWrapper.php
@@ -0,0 +1,140 @@
<?php

/**
* AppserverIo\Psr\Pms\MessageWrapper
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* PHP version 5
*
* @category Appserver
* @package Psr
* @subpackage Pms
* @author Tim Wagner <tw@appserver.io>
* @copyright 2014 TechDivision GmbH <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io-psr/pms
* @link http://www.appserver.io
*/

namespace AppserverIo\Psr\Pms;

/**
* A simple message wrapper instance.
*
* @category Appserver
* @package Psr
* @subpackage Pms
* @author Tim Wagner <tw@appserver.io>
* @copyright 2014 TechDivision GmbH <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io-psr/pms
* @link http://www.appserver.io
*/
class MessageWrapper implements Message
{

/**
* The message we want to wrap.
*
* @var AppserverIo\Psr\Pms\Message
*/
protected $message;

/**
* Injects the message we want to wrap.
*
* @param AppserverIo\Psr\Pms\Message $message
*/
public function injectMessage(Message $message)
{
$this->message = $message;
}

/**
* Returns the injected message instance.
*
* @return AppserverIo\Psr\Pms\Message The injected message instance
*/
public function getInjectedMessage()
{
return $this->message;
}

/**
* Returns the destination queue.
*
* @return \AppserverIo\Psr\Pms\Queue The destination queue
*/
public function getDestination()
{
return $this->getInjectedMessage()->getDestination();
}

/**
* Returns the message id as an
* hash value..
*
* @return string The message id as hash value
*/
public function getMessageId()
{
return $this->getInjectedMessage()->getMessageId();
}

/**
* Returns the message itself.
*
* @return Object The message depending on the type of the Message object
*/
public function getMessage()
{
return $this->getInjectedMessage()->getMessage();
}

/**
* Sets the unique session id.
*
* @param string $sessionId The uniquid id
*
* @return void
*/
public function setSessionId($sessionId)
{
$this->getInjectedMessage()->setSessionId($sessionId);
}

/**
* Returns the unique session id.
*
* @return string The uniquid id
*/
public function getSessionId()
{
return $this->getInjectedMessage()->getSessionId();
}

/**
* Returns the parent message.
*
* @return \AppserverIo\Psr\Pms\Message The parent message
*/
public function getParentMessage()
{
return $this->getInjectedMessage()->getParentMessage();
}

/**
* Returns the message monitor.
*
* @return \AppserverIo\Psr\Pms\Monitor The monitor
*/
public function getMessageMonitor()
{
return $this->getInjectedMessage()->getMessageMonitor();
}
}
83 changes: 83 additions & 0 deletions tests/AppserverIo/Psr/Pms/MessageWrapperTest.php
@@ -0,0 +1,83 @@
<?php

/**
* AppserverIo\Psr\Pms\MessageWrapperTest
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* PHP version 5
*
* @category Appserver
* @package Psr
* @subpackage Pms
* @author Tim Wagner <tw@appserver.io>
* @copyright 2014 TechDivision GmbH <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io-psr/pms
* @link http://www.appserver.io
*/

namespace AppserverIo\Psr\Pms;

/**
* A test implemetation for the simple message wrapper instance.
*
* @category Appserver
* @package Psr
* @subpackage Pms
* @author Tim Wagner <tw@appserver.io>
* @copyright 2014 TechDivision GmbH <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io-psr/pms
* @link http://www.appserver.io
*/
class MessageWrapperTest extends \PHPUnit_Framework_TestCase
{

/**
* The message wrapper instance we want to test.
*
* @var \AppserverIo\Psr\Pms\MessageWrapper
*/
protected $messageWrapper;

/**
* Initializes the message wrapper instance we want to test.
*
* @return void
* @see PHPUnit_Framework_TestCase::setUp()
*/
protected function setUp()
{
$this->messageWrapper = new MessageWrapper();
}

/**
* Test the getMessage() method.
*
* @return void
*/
public function testGetMessage()
{

// create a mock message instance and mock all methods
$mockMessage = $this->getMockBuilder('AppserverIo\Psr\Pms\Message')
->setMethods(get_class_methods('AppserverIo\Psr\Pms\Message'))
->getMock();

// mock the getMessage() method
$mockMessage->expects($this->once())
->method('getMessage')
->will($this->returnValue($value = 'test'));

// inject the message
$this->messageWrapper->injectMessage($mockMessage);

// check the return value
$this->assertSame($value, $this->messageWrapper->getMessage());
}
}

0 comments on commit 148908b

Please sign in to comment.