Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[sender] html sender

  • Loading branch information...
commit 8c3125ece9d08fa9473d57a74dfd716f339980bc 1 parent c0568b2
@makasim makasim authored
View
34 ChainNode/Sender/HtmlSender.php
@@ -0,0 +1,34 @@
+<?php
+namespace Fp\BadaBoomBundle\ChainNode\Sender;
+
+use Symfony\Component\HttpKernel\Debug\ExceptionHandler;
+
+use BadaBoom\ChainNode\AbstractChainNode;
+use BadaBoom\DataHolder\DataHolderInterface;
+
+class HtmlSender extends AbstractChainNode
@vatson Owner
vatson added a note

Name is a bit confusing. On the one hand, it is the sender. But on the other hand, it does not fit into the concept of senders from our library, and does not implement AbstractSenderChainNode.

@makasim Owner
makasim added a note

let's stay with SymfonyExceptionHandlerChainNode

@vatson Owner
vatson added a note

agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+{
+ /**
+ * @var \Symfony\Component\HttpKernel\Debug\ExceptionHandler
+ */
+ protected $exceptionHandler;
+
+ /**
+ * @param \Symfony\Component\HttpKernel\Debug\ExceptionHandler $exceptionHandler
+ */
+ public function __construct(ExceptionHandler $exceptionHandler)
+ {
+ $this->exceptionHandler = $exceptionHandler;
+ }
+
+ /**
+ * @param \Exception $exception
+ * @param \BadaBoom\DataHolder\DataHolderInterface $data
+ */
+ public function handle(\Exception $exception, DataHolderInterface $data)
+ {
+ $this->exceptionHandler->handle($exception);
+
+ $this->handleNextNode($exception, $data);
+ }
+}
View
86 Tests/ChainNode/Sender/HtmlSenderTest.php
@@ -0,0 +1,86 @@
+<?php
+namespace Fp\BadaBoomBundle\Tests\ChainNode\Sender;
+
+use Fp\BadaBoomBundle\ChainNode\Sender\HtmlSender;
+
+class HtmlSenderTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ *
+ * @test
+ */
+ public function shouldBeSubClassOfAbstractSender()
+ {
+ $rc = new \ReflectionClass('Fp\BadaBoomBundle\ChainNode\Sender\HtmlSender');
+ $this->assertTrue($rc->isSubclassOf('BadaBoom\ChainNode\AbstractChainNode'));
+ }
+
+ /**
+ * @test
+ */
+ public function couldBeConstructedWithExceptionHandlerAsArgument()
@vatson Owner
vatson added a note

Could be? The exception handler is a required argument. There can be no duality

@makasim Owner
makasim added a note

it useless without symfony's exception handler. The handle will be always here cuz it is in HttpKernel component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ {
+ new HtmlSender($this->createExceptionHandlerMock());
+ }
+
+ /**
+ * @test
+ */
+ public function shouldDelegateHandlingToNextNode()
+ {
+ $expectedException = new \Exception();
+ $expectedDataHolderMock = $this->createDataHolderMock();
+
+ $nextChainNodeMock = $this->createChainNodeMock();
+ $nextChainNodeMock
+ ->expects($this->once())
+ ->method('handle')
+ ->with(
+ $this->equalTo($expectedException),
@vatson Owner
vatson added a note

Something bad happened with these indents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $this->equalTo($expectedDataHolderMock)
+ )
+ ;
+
+ $sender = new HtmlSender($this->createExceptionHandlerMock());
+
+ $sender->nextNode($nextChainNodeMock);
+
+ $sender->handle($expectedException, $expectedDataHolderMock);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldProxyExceptionToExceptionHandler()
+ {
+ $expectedException = new \Exception();
+
+ $exceptionHandlerMock = $this->createExceptionHandlerMock();
+ $exceptionHandlerMock
+ ->expects($this->once())
+ ->method('handle')
+ ->with(
+ $this->equalTo($expectedException)
+ )
+ ;
+
+ $sender = new HtmlSender($exceptionHandlerMock);
+
+ $sender->handle($expectedException, $this->createDataHolderMock());
+ }
+
+ protected function createDataHolderMock()
+ {
+ return $this->getMock('BadaBoom\DataHolder\DataHolderInterface');
+ }
+
+ protected function createChainNodeMock()
+ {
+ return $this->getMock('BadaBoom\ChainNode\ChainNodeInterface');
+ }
+
+ protected function createExceptionHandlerMock()
+ {
+ return $this->getMock('Symfony\Component\HttpKernel\Debug\ExceptionHandler', array('handle'));
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.