Permalink
Browse files

further tests and bug-fixes

  • Loading branch information...
1 parent f25da3c commit 3a2a772eb6c0ea977d4eec63a549db794e9b802a Timo Michna committed Aug 25, 2010
View
2 src/ABS/channel/PEIP_ABS_Interceptable_Message_Channel.php
@@ -257,7 +257,7 @@ protected static function getSharedEventDispatcher(){
* @param $eventClass
* @return
*/
- protected function doFireEvent($name, array $headers = array(), $eventClass = false){
+ protected function doFireEvent($name, array $headers = array(), $eventClass = false){
return $this->getEventDispatcher()->buildAndNotify($name, $this, $headers, $eventClass);
}
}
View
2 src/ABS/handler/PEIP_ABS_Reply_Producing_Message_Handler.php
@@ -83,7 +83,7 @@ protected function doGetOutputChannel(PEIP_INF_Message $message){
/**
* Resolves a reply-channel for a message.
* Looks for a reply-channel header in the message (default: 'REPLY_CHANNEL')
- * and returns it´s value, if found.
+ * and returns its value, if found.
*
* @access protected
* @param PEIP_INF_Message $message
View
2 src/base/PEIP_Object_Storage.php
@@ -39,7 +39,7 @@ public function offsetUnset($offset){
}
public function offsetExists($offset){
- return in_array($offset, $this->objects);
+ return in_array($offset, $this->objects);
}
public function count(){
View
18 src/dispatcher/PEIP_Iterating_Dispatcher.php
@@ -32,7 +32,7 @@ class PEIP_Iterating_Dispatcher
* @return
*/
public function __construct(ArrayIterator $listenerIterator = NULL){
- $this->listeners = $iterator ? $iterator : new ArrayIterator;
+ $this->listeners = $listenerIterator ? $listenerIterator : new ArrayIterator;
}
/**
@@ -54,12 +54,12 @@ public function connect(PEIP_INF_Handler $listener){
* @return
*/
public function disconnect(PEIP_INF_Handler $listener){
- foreach ($this->listeners as $i => $callable){
- if ($listener === $callable){
- unset($this->listeners[$name][$i]);
- }
- }
- }
+ foreach ($this->listeners as $i => $callable){
+ if ($listener === $callable){
+ unset($this->listeners[$i]);
+ }
+ }
+ }
/**
* Check wether any listener is registered
@@ -97,7 +97,7 @@ public function notify($subject){
* @return array registered listeners
*/
public function getListeners(){
- return $this->listeners;
- }
+ return $this->listeners->getArrayCopy();
+ }
}
View
6 src/dispatcher/PEIP_Object_Event_Dispatcher.php
@@ -11,10 +11,10 @@
/**
* PEIP_Object_Event_Dispatcher
* Event dispatcher for an abritrary amount of different objects and events.
- * Contrary to it´s parent class (PEIP_Object_Map_Dispatcher) this class can
+ * Contrary to its parent class (PEIP_Object_Map_Dispatcher) this class can
* create event-objects (PEIP_INF_Event) with the notification subject as content/subject
- * and notify it´s listners on the event-objects. Also this class only accepts instaces of
- * PEIP_INF_Event as it´s notification subjects.
+ * and notify its listners on the event-objects. Also this class only accepts instaces of
+ * PEIP_INF_Event as its notification subjects.
*
* @author Timo Michna <timomichna/yahoo.de>
* @package PEIP
View
5 src/pipe/PEIP_Pipe.php
@@ -16,6 +16,7 @@
* @subpackage pipe
* @extends PEIP_ABS_Reply_Producing_Message_Handler
* @implements PEIP_INF_Message_Builder, PEIP_INF_Handler, PEIP_INF_Channel, PEIP_INF_Subscribable_Channel, PEIP_INF_Connectable
+ * @todo full test-coverage, factor out constants to framework-wide constants
*/
@@ -203,7 +204,7 @@ public function disconnect($name, PEIP_INF_Handler $listener){
* @return
*/
public function hasListeners($name){
- return $this->getEventDispatcher()->hasListener($name, $this);
+ return $this->getEventDispatcher()->hasListeners($name, $this);
}
@@ -213,7 +214,7 @@ public function hasListeners($name){
* @return
*/
public function getListeners($name){
- return $this->getEventDispatcher()->hasListener($name, $this);
+ return $this->getEventDispatcher()->getListeners($name, $this);
}
/**
View
2 tests/AllTests.php
@@ -9,6 +9,7 @@
require_once dirname(__FILE__).'/handler/AllTests.php';
require_once dirname(__FILE__).'/message/AllTests.php';
require_once dirname(__FILE__).'/service/AllTests.php';
+require_once dirname(__FILE__).'/pipe/AllTests.php';
class AllTests extends PHPUnit_Framework_TestSuite {
public static function suite(){
@@ -22,6 +23,7 @@ public static function suite(){
$suite->addTestSuite('Handler_AllTests');
$suite->addTestSuite('Message_AllTests');
$suite->addTestSuite('Service_AllTests');
+ $suite->addTestSuite('Pipe_AllTests');
return $suite;
}
}
View
6 tests/_files/MessageChannelInterceptor.php
@@ -18,6 +18,12 @@ public function postSend(PEIP_INF_Message $message, PEIP_INF_Channel $channel, $
$this->message = $message;
}
+ public function eventCallback(PEIP_INF_Message $message){
+ $this->message = $message;
+ }
+ public function callback($message){
+ $this->message = $message;
+ }
}
View
21 tests/_files/Pipe.php
@@ -0,0 +1,21 @@
+<?php
+
+class DefaultPipe extends PEIP_Pipe {
+
+
+
+ public function __construct(){
+ $this->registerCommand('foo', array($this, 'fooCommand'));
+ }
+
+ protected function fooCommand($arg){
+
+ }
+
+
+
+
+
+
+
+}
View
12 tests/_files/SimpleHandler.php
@@ -0,0 +1,12 @@
+<?php
+
+class SimpleHandler implements PEIP_INF_Handler {
+
+ public $subject;
+
+ public function handle($subject){
+ $this->subject = $subject;
+ }
+
+}
+
View
27 tests/channel/InterceptableMessageChannelTest.php
@@ -9,7 +9,9 @@ class InterceptableMessageChannelTest extends PHPUnit_Framework_TestCase {
public function setUp(){
$this->channel = new InterceptableMessageChannel('TestChannel');
- }
+ $dispatcher = new PEIP_Object_Event_Dispatcher;
+ $this->channel->setEventDispatcher($dispatcher, false);
+ }
public function testMessageChannelInterceptor(){
$interceptor = new MessageChannelInterceptor(1);
@@ -69,6 +71,7 @@ public function testSend(){
$this->channel->addInterceptor($iterceptor1);
$message = new PEIP_Generic_Message(321);
$this->channel->send($message);
+ $this->assertEquals($message, $iterceptor1->message);
}
public function testConnect(){
@@ -87,13 +90,24 @@ public function testDisconnect(){
$this->assertFalse($this->channel->hasListeners('preSend'));
}
+ public function testFireEvent(){
+ $interceptor = new MessageChannelInterceptor(1);
+ $message = new PEIP_Generic_Message(321);
+ $handler = new PEIP_Callable_Handler(array($interceptor,'eventCallback'));
+ $dispatcher = new PEIP_Object_Event_Dispatcher;
+ $this->channel->setEventDispatcher($dispatcher, false);
+ $this->channel->connect('preSend', $handler);
+ $this->channel->send($message);
+ $this->assertEquals($message, $interceptor->message->getHeader('MESSAGE'));
+ $this->channel->disconnect('preSend', $handler);
+ }
public function testGetListeners(){
- $handler1 = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
- $handler2 = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
- $this->channel->connect('preSend', $handler1);
- $this->channel->connect('preSend', $handler2);
- $this->assertEquals(array($handler1, $handler2), $this->channel->getListeners('preSend'));
+ $handler1 = new PEIP_Callable_Handler(array('TestClass','TestMethod1'));
+ $handler2 = new PEIP_Callable_Handler(array('TestClass','TestMethod2'));
+ $this->channel->connect('postSend', $handler1);
+ $this->channel->connect('postSend', $handler2);
+ $this->assertEquals(array($handler1, $handler2), $this->channel->getListeners('postSend'));
}
public function testSetEventDispatcher(){
@@ -114,5 +128,4 @@ public function testSetEventDispatcherTransferListners(){
}
-
}
View
4 tests/dispatcher/AllTests.php
@@ -1,15 +1,17 @@
-<?php
+<?php
require_once dirname(__FILE__).'/DispatcherTest.php';
require_once dirname(__FILE__).'/ObjectEventDispatcherTest.php';
require_once dirname(__FILE__).'/ObjectMapDispatcherTest.php';
+require_once dirname(__FILE__).'/IteratingDispatcherTest.php';
class Dispatcher_AllTests extends PHPUnit_Framework_TestSuite {
public static function suite(){
$suite = new PHPUnit_Framework_TestSuite('dispatcher');
$suite->addTestSuite('DispatcherTest');
$suite->addTestSuite('ObjectEventDispatcherTest');
$suite->addTestSuite('ObjectMapDispatcherTest');
+ $suite->addTestSuite('IteratingDispatcherTest');
return $suite;
}
}
View
62 tests/dispatcher/IteratingDispatcherTest.php
@@ -0,0 +1,62 @@
+<?php
+
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
+
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/InterceptableMessageChannel.php');
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/MessageChannelInterceptor.php');
+
+class IteratingDispatcherTest extends PHPUnit_Framework_TestCase {
+
+
+ protected $dispatcher;
+
+ public function setup(){
+ $this->dispatcher = new PEIP_Iterating_Dispatcher;
+ }
+
+ public function testConnect(){
+ $this->assertFalse($this->dispatcher->hasListeners());
+ $handler = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
+ $this->dispatcher->connect($handler);
+ $this->assertTrue($this->dispatcher->hasListeners());
+ }
+
+ public function testDisconnect(){
+ $this->assertFalse($this->dispatcher->hasListeners());
+ $handler = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
+ $this->dispatcher->connect($handler);
+ $this->assertTrue($this->dispatcher->hasListeners());
+ $this->dispatcher->disconnect($handler);
+ $this->assertFalse($this->dispatcher->hasListeners());
+ }
+
+ public function testgetListeners(){
+ $this->assertFalse($this->dispatcher->hasListeners());
+ $handler1 = new PEIP_Callable_Handler(array('TestClass','TestMethod1'));
+ $handler2 = new PEIP_Callable_Handler(array('TestClass','TestMethod2'));
+ $this->dispatcher->connect($handler1);
+ $this->dispatcher->connect($handler2);
+ $this->assertEquals(array($handler1, $handler2), $this->dispatcher->getListeners());
+ }
+
+ public function testNotify(){
+
+ $interceptor1 = new MessageChannelInterceptor ;
+ $interceptor2 = new MessageChannelInterceptor ;
+ $handler1 = new PEIP_Callable_Handler(array($interceptor1,'callback'));
+ $handler2 = new PEIP_Callable_Handler(array($interceptor2,'callback'));
+ $this->dispatcher->connect($handler1);
+ $this->dispatcher->connect($handler2);
+ $this->dispatcher->notify('foo');
+ $this->assertEquals('foo', $interceptor1->message);
+ $this->assertNotEquals('foo', $interceptor2->message);
+ $this->dispatcher->notify('bar');
+ $this->assertEquals('bar', $interceptor2->message);
+ $this->assertNotEquals('bar', $interceptor1->message);
+ }
+
+}
+
+
+
+
View
11 tests/pipe/AllTests.php
@@ -0,0 +1,11 @@
+<?php
+
+require_once dirname(__FILE__).'/PipeTest.php';
+
+ class Pipe_AllTests extends PHPUnit_Framework_TestSuite {
+ public static function suite(){
+ $suite = new PHPUnit_Framework_TestSuite('pipe');
+ $suite->addTestSuite('PipeTest');
+ return $suite;
+ }
+}
View
74 tests/pipe/PipeTest.php
@@ -0,0 +1,74 @@
+<?php
+
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
+
+require_once dirname(__FILE__).'/../_files/Pipe.php';
+require_once dirname(__FILE__).'/../_files/SimpleHandler.php';
+
+
+class PipeTest extends PHPUnit_Framework_TestCase {
+
+
+ protected $dispatcher;
+
+ public function setup(){
+ $this->pipe = new DefaultPipe;
+ }
+
+ public function testSetName(){
+ $this->pipe->setName('foo');
+ $this->assertEquals('foo', $this->pipe->getName());
+ }
+
+ public function testSendPush(){
+ $receiveCh = new PEIP_Pollable_Channel('receive');
+ $message = new PEIP_Generic_Message('foo');
+ $this->pipe->setOutputChannel($receiveCh);
+ $this->pipe->send($message);
+ $this->assertEquals($message, $receiveCh->receive());
+ }
+
+ public function testSendAsynch(){
+ $receiveCh1 = new SimpleHandler();
+ $receiveCh2 = new SimpleHandler();
+ $message = new PEIP_Generic_Message('foo');
+ $this->pipe->subscribe($receiveCh1);
+ $this->pipe->subscribe($receiveCh2);
+ $this->pipe->send($message);
+ $this->assertEquals($message, $receiveCh1->subject);
+ $this->assertEquals($message, $receiveCh2->subject);
+ }
+
+ public function testSubscribeUnsubscribe(){
+ $receiveCh1 = new SimpleHandler();
+ $message = new PEIP_Generic_Message('foo');
+ $this->pipe->subscribe($receiveCh1);
+ $this->pipe->send($message);
+ $this->assertEquals($message, $receiveCh1->subject);
+ $this->pipe->unsubscribe($receiveCh1);
+ $receiveCh1->subject = NULL;
+ $this->pipe->send($message);
+ $this->assertNotEquals($message, $receiveCh1->subject);
+ }
+
+
+ public function testConnect(){
+ $this->assertFalse($this->pipe->hasListeners('preSend'));
+ $handler = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
+ $this->pipe->connect('preSend', $handler);
+ $this->assertTrue($this->pipe->hasListeners('preSend'));
+ $this->pipe->disconnect('preSend', $handler);
+ }
+
+ public function testDisconnect(){
+ $handler = new PEIP_Callable_Handler(array('TestClass','TestMethod'));
+ $this->pipe->connect('preSend', $handler);
+ $this->assertTrue($this->pipe->hasListeners('preSend'));
+ $this->pipe->disconnect('preSend', $handler);
+ $this->assertFalse($this->pipe->hasListeners('preSend'));
+ }
+
+
+
+
+}

0 comments on commit 3a2a772

Please sign in to comment.