From 148908bef1d7999282ff956d7dcd3751fbe4573e Mon Sep 17 00:00:00 2001 From: Tim Wagner Date: Thu, 22 Jan 2015 17:23:10 +0100 Subject: [PATCH] Add PHPUnit test for MessageWrapper implementation --- src/AppserverIo/Psr/Pms/MessageWrapper.php | 140 ++++++++++++++++++ .../Psr/Pms/MessageWrapperTest.php | 83 +++++++++++ 2 files changed, 223 insertions(+) create mode 100644 src/AppserverIo/Psr/Pms/MessageWrapper.php create mode 100644 tests/AppserverIo/Psr/Pms/MessageWrapperTest.php diff --git a/src/AppserverIo/Psr/Pms/MessageWrapper.php b/src/AppserverIo/Psr/Pms/MessageWrapper.php new file mode 100644 index 0000000..8a7ebe9 --- /dev/null +++ b/src/AppserverIo/Psr/Pms/MessageWrapper.php @@ -0,0 +1,140 @@ + + * @copyright 2014 TechDivision GmbH + * @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 + * @copyright 2014 TechDivision GmbH + * @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(); + } +} diff --git a/tests/AppserverIo/Psr/Pms/MessageWrapperTest.php b/tests/AppserverIo/Psr/Pms/MessageWrapperTest.php new file mode 100644 index 0000000..539eea1 --- /dev/null +++ b/tests/AppserverIo/Psr/Pms/MessageWrapperTest.php @@ -0,0 +1,83 @@ + + * @copyright 2014 TechDivision GmbH + * @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 + * @copyright 2014 TechDivision GmbH + * @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()); + } +}