Permalink
Browse files

Merge pull request #45 from formapro/chain-node-push

[node] add push method
  • Loading branch information...
makasim committed Mar 4, 2012
2 parents 0aaa5d4 + 3908caf commit e7ba64d9e44c89cff215790c25e3c54dc8bdc321
@@ -33,4 +33,17 @@ public function nextNode(ChainNodeInterface $node)
{
return $this->nextNode = $node;
}
+
+ /**
+ *
+ * {@inheritdoc}
+ */
+ public function push(ChainNodeInterface $pushedNode)
+ {
+ if ($currentNextNode = $this->nextNode) {
+ $pushedNode->nextNode($currentNextNode);
+ }
+
+ return $this->nextNode($pushedNode);
+ }
}
@@ -21,4 +21,13 @@ function handle(\Exception $exception, DataHolderInterface $data);
* @return ChainNodeInterface
*/
function nextNode(ChainNodeInterface $node);
+
+ /**
+ * Pushed a node after the current node, if the current node has next node the pushed will be set among them.
+ *
+ * @param ChainNodeInterface $pushedNode
+ *
+ * @return ChainNodeInterface a pushed node
+ */
+ function push(ChainNodeInterface $pushedNode);
}
@@ -68,6 +68,78 @@ public function shouldDelegateHandlingToNextChainNode()
$chainNode->handleNextNode($exception, $data);
}
+ /**
+ * @test
+ */
+ public function shouldPushNodeAsNextOne()
+ {
+ $exception = new \Exception;
+ $data = new DataHolder;
+
+ $chainNode = $this->createMockChainNode();
+ $pushedChainNode = $this->createMockChainNode();
+ $pushedChainNode
+ ->expects($this->once())
+ ->method('handle')
+ ->with(
+ $this->equalTo($exception),
+ $this->equalTo($data)
+ )
+ ;
+
+ $chainNode->push($pushedChainNode);
+
+ $chainNode->handleNextNode($exception, $data);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldPushReturnPushedInstance()
+ {
+ $chainNode = $this->createMockChainNode();
+ $pushedChainNode = $this->createMockChainNode();
+
+ $actualPushedNode = $chainNode->push($pushedChainNode);
+
+ $this->assertSame($pushedChainNode, $actualPushedNode);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldPushNodeAmongCurrentAndNextOne()
+ {
+ $exception = new \Exception;
+ $data = new DataHolder;
+
+ $chainNode = $this->createMockChainNode();
+
+ $nextChainNode = $this->createMockChainNode();
+
+ $pushedChainNode = $this->getMock('BadaBoom\ChainNode\AbstractChainNode', array('handle', 'nextNode'));
+ $pushedChainNode
+ ->expects($this->once())
+ ->method('handle')
+ ->with(
+ $this->equalTo($exception),
+ $this->equalTo($data)
+ )
+ ;
+ $pushedChainNode
+ ->expects($this->once())
+ ->method('nextNode')
+ ->with(
+ $this->equalTo($nextChainNode)
+ )
+ ;
+
+ $chainNode->nextNode($nextChainNode);
+ $chainNode->push($pushedChainNode);
+
+ $chainNode->handleNextNode($exception, $data);
+ }
+
/**
*
* @test

0 comments on commit e7ba64d

Please sign in to comment.