Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

[node] add push method
  • Loading branch information...
commit e7ba64d9e44c89cff215790c25e3c54dc8bdc321 2 parents 0aaa5d4 + 3908caf
@makasim makasim authored
View
13 src/BadaBoom/ChainNode/AbstractChainNode.php
@@ -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);
+ }
}
View
9 src/BadaBoom/ChainNode/ChainNodeInterface.php
@@ -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);
}
View
72 tests/BadaBoom/Tests/ChainNode/AbstractChainNodeTest.php
@@ -69,6 +69,78 @@ public function shouldDelegateHandlingToNextChainNode()
}
/**
+ * @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
*/
Please sign in to comment.
Something went wrong with that request. Please try again.