Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[provider] session #2

Merged
merged 4 commits into from

2 participants

@makasim
Owner

No description provided.

@vatson
Owner

Approved a greater extent. btw, are we going to stick to writing DocBlock comments?

@makasim makasim merged commit a38d895 into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 2, 2012
  1. @makasim

    [provider] session

    makasim authored
Commits on Mar 31, 2012
  1. @makasim

    fix test name.

    makasim authored
Commits on Apr 10, 2012
  1. @makasim

    [provider] fix test autoload

    makasim authored
  2. @makasim

    [provider] add docblocks.

    makasim authored
This page is out of date. Refresh to see the latest.
View
45 ChainNode/Provider/SessionProvider.php
@@ -0,0 +1,45 @@
+<?php
+namespace Fp\BadaBoomBundle\ChainNode\Provider;
+
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+
+use BadaBoom\ChainNode\Provider\AbstractProvider;
+use BadaBoom\DataHolder\DataHolderInterface;
+
+/**
+ * @author Kotlyar Maksim <kotlyar.maksim@gmail.com>
+ * @since 4/10/12
+ */
+class SessionProvider extends AbstractProvider
+{
+ /**
+ * @var string
+ */
+ protected $sectionName;
+
+ /**
+ * @var \Symfony\Component\HttpFoundation\Session\SessionInterface
+ */
+ protected $session;
+
+ /**
+ * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
+ * @param string $sectionName
+ */
+ public function __construct(SessionInterface $session, $sectionName = 'session')
+ {
+ $this->session = $session;
+ $this->sectionName = $sectionName;
+ }
+
+ /**
+ * @param \Exception $exception
+ * @param \BadaBoom\DataHolder\DataHolderInterface $data
+ */
+ public function handle(\Exception $exception, DataHolderInterface $data)
+ {
+ $data->set($this->sectionName, $this->session->all());
+
+ $this->handleNextNode($exception, $data);
+ }
+}
View
134 Tests/ChainNode/Provider/SessionProviderTest.php
@@ -0,0 +1,134 @@
+<?php
+namespace Fp\BadaBoomBundle\Tests\ChainNode\Provider;
+
+use Fp\BadaBoomBundle\ChainNode\Provider\SessionProvider;
+
+/**
+ * @author Kotlyar Maksim <kotlyar.maksim@gmail.com>
+ * @since 4/10/12
+ */
+class SessionProviderTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @test
+ */
+ public function shouldBeSubclassOfAbstractProvider()
+ {
+ $rc = new \ReflectionClass('Fp\BadaBoomBundle\ChainNode\Provider\SessionProvider');
+ $this->assertTrue($rc->isSubclassOf('BadaBoom\ChainNode\Provider\AbstractProvider'));
+ }
+
+ /**
+ * @test
+ */
+ public function couldBeConstructedWithSecurityContextAsArgument()
+ {
+ new SessionProvider($this->createSessionMock());
+ }
+
+ /**
+ * @test
+ */
+ public function shouldAddSessionDataToDefaultSection()
+ {
+ $expectedSessionData = array(
+ 'foo' => 'foo',
+ 'bar' => new \stdClass(),
+ 'olo' => 123
+ );
+
+ $sessionMock = $this->createSessionMock();
+ $sessionMock
+ ->expects($this->once())
+ ->method('all')
+ ->will($this->returnValue($expectedSessionData))
+ ;
+
+ $dataHolderMock = $this->createDataHolderMock();
+ $dataHolderMock
+ ->expects($this->once())
+ ->method('set')
+ ->with(
+ $this->equalTo('session'),
+ $this->equalTo($expectedSessionData)
+ )
+ ;
+
+ $sessionProvider = new SessionProvider($sessionMock);
+
+ $sessionProvider->handle(new \Exception(), $dataHolderMock);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldAddSessionDataToCustomSection()
+ {
+ $expectedCustomSectionName = 'custom_section_name';
+
+ $dataHolderMock = $this->createDataHolderMock();
+ $dataHolderMock
+ ->expects($this->once())
+ ->method('set')
+ ->with(
+ $this->equalTo($expectedCustomSectionName)
+ )
+ ;
+
+ $sessionProvider = new SessionProvider(
+ $this->createSessionMock(),
+ $expectedCustomSectionName
+ );
+
+ $sessionProvider->handle(new \Exception(), $dataHolderMock);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldDelegateHandlingToNextNode()
+ {
+ $expectedException = new \Exception();
+ $expectedDataHolder = $this->createDataHolderMock();
+
+ $nextChainNodeMock = $this->createChainNodeMock();
+ $nextChainNodeMock
+ ->expects($this->once())
+ ->method('handle')
+ ->with(
+ $this->equalTo($expectedException),
+ $this->equalTo($expectedDataHolder)
+ )
+ ;
+
+ $sessionProvider = new SessionProvider($this->createSessionMock());
+
+ $sessionProvider->nextNode($nextChainNodeMock);
+
+ $sessionProvider->handle($expectedException, $expectedDataHolder);
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\HttpFoundation\Session\SessionInterface
+ */
+ protected function createSessionMock()
+ {
+ return $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject|\BadaBoom\DataHolder\DataHolderInterface
+ */
+ protected function createDataHolderMock()
+ {
+ return $this->getMock('BadaBoom\DataHolder\DataHolderInterface');
+ }
+
+ /**
+ * @return \PHPUnit_Framework_MockObject_MockObject|\BadaBoom\ChainNode\ChainNodeInterface
+ */
+ protected function createChainNodeMock()
+ {
+ return $this->getMock('BadaBoom\ChainNode\ChainNodeInterface');
+ }
+}
View
14 Tests/autoload.php.dist
@@ -1,4 +1,14 @@
<?php
-$loader = include_once __DIR__ . '/../vendor/.composer/autoload.php';
-$loader->add('Fp\\BadaBoomBundle', __DIR__ . '/../../../');
+include_once __DIR__ . '/../vendor/.composer/autoload.php';
+
+spl_autoload_register(function($class) {
+ if (0 === strpos($class, 'Fp\\BadaBoomBundle\\')) {
+ $path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 2)).'.php';
+ if (!stream_resolve_include_path($path)) {
+ return false;
+ }
+ require_once $path;
+ return true;
+ }
+});
Something went wrong with that request. Please try again.