From 137dd0ceaff5baacf9e01c6e2790b4c83784d246 Mon Sep 17 00:00:00 2001 From: l3l0 Date: Sat, 30 Jun 2012 09:37:02 +0200 Subject: [PATCH] Added session tests --- .../Tests/Storage/SessionFlowsBagTest.php | 43 +++++++ .../Tests/Storage/SessionStorageTest.php | 112 ++++++++++++++++++ .../FlowBundle/Tests/Storage/StorageTest.php | 39 ++++++ 3 files changed, 194 insertions(+) create mode 100644 src/Sylius/Bundle/FlowBundle/Tests/Storage/SessionFlowsBagTest.php create mode 100644 src/Sylius/Bundle/FlowBundle/Tests/Storage/SessionStorageTest.php create mode 100644 src/Sylius/Bundle/FlowBundle/Tests/Storage/StorageTest.php diff --git a/src/Sylius/Bundle/FlowBundle/Tests/Storage/SessionFlowsBagTest.php b/src/Sylius/Bundle/FlowBundle/Tests/Storage/SessionFlowsBagTest.php new file mode 100644 index 0000000000..50f1ecb255 --- /dev/null +++ b/src/Sylius/Bundle/FlowBundle/Tests/Storage/SessionFlowsBagTest.php @@ -0,0 +1,43 @@ + + */ +class SessionFlowsBagTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + */ + public function shouldGetName() + { + $sessionBag = new SessionFlowsBag(); + + $this->assertEquals('sylius_flow.bag', $sessionBag->getName()); + } + + /** + * @test + */ + public function shouldSetValue() + { + $sessionBag = new SessionFlowsBag(); + $sessionBag->set('key', 'value'); + + $this->assertEquals('value', $sessionBag->get('key')); + } +} diff --git a/src/Sylius/Bundle/FlowBundle/Tests/Storage/SessionStorageTest.php b/src/Sylius/Bundle/FlowBundle/Tests/Storage/SessionStorageTest.php new file mode 100644 index 0000000000..5ffbcbf4fa --- /dev/null +++ b/src/Sylius/Bundle/FlowBundle/Tests/Storage/SessionStorageTest.php @@ -0,0 +1,112 @@ + + */ +class SessionStorageTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + * @covers Sylius\Bundle\FlowBundle\Storage\SessionStorage + */ + public function shouldSetValueToSessionBag() + { + $sessionBag = $this->getSessionBag(); + $sessionBag->expects($this->once()) + ->method('set') + ->with('mydomain/test', 'my-value'); + $sessionBag->expects($this->once()) + ->method('get') + ->with('mydomain/test') + ->will($this->returnValue('my-value')); + + $sessionStorage = new SessionStorage($this->getSession($sessionBag)); + $sessionStorage->initialize('mydomain'); + $sessionStorage->set('test', 'my-value'); + + $this->assertEquals('my-value', $sessionStorage->get('test')); + } + + /** + * @test + * @covers Sylius\Bundle\FlowBundle\Storage\SessionStorage + */ + public function shouldCheckIfValueIsSetInSessionBag() + { + $sessionBag = $this->getSessionBag(); + $sessionBag->expects($this->once()) + ->method('has') + ->with('mydomain/test') + ->will($this->returnValue(true)); + + $sessionStorage = new SessionStorage($this->getSession($sessionBag)); + $sessionStorage->initialize('mydomain'); + + $this->assertTrue($sessionStorage->has('test')); + } + + /** + * @test + * @covers Sylius\Bundle\FlowBundle\Storage\SessionStorage + */ + public function shouldRemoveFromSessionBag() + { + $sessionBag = $this->getSessionBag(); + $sessionBag->expects($this->once()) + ->method('remove') + ->with('mydomain/test'); + + $sessionStorage = new SessionStorage($this->getSession($sessionBag)); + $sessionStorage->initialize('mydomain'); + + $sessionStorage->remove('test'); + } + + /** + * @test + * @covers Sylius\Bundle\FlowBundle\Storage\SessionStorage + */ + public function shouldClearDomainInSessionBag() + { + $sessionBag = $this->getSessionBag(); + $sessionBag->expects($this->once()) + ->method('remove') + ->with('mydomain'); + + $sessionStorage = new SessionStorage($this->getSession($sessionBag)); + $sessionStorage->initialize('mydomain'); + + $sessionStorage->clear(); + } + + private function getSessionBag() + { + return $this->getMock('Sylius\Bundle\FlowBundle\Storage\SessionFlowsBag'); + } + + private function getSession($bag) + { + $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface'); + $session->expects($this->any()) + ->method('getBag') + ->will($this->returnValue($bag)); + + return $session; + } +} diff --git a/src/Sylius/Bundle/FlowBundle/Tests/Storage/StorageTest.php b/src/Sylius/Bundle/FlowBundle/Tests/Storage/StorageTest.php new file mode 100644 index 0000000000..b50a372d45 --- /dev/null +++ b/src/Sylius/Bundle/FlowBundle/Tests/Storage/StorageTest.php @@ -0,0 +1,39 @@ + + */ +class StorageTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + * @covers Sylius\Bundle\FlowBundle\Storage\Storage + */ + public function shouldSetDomainWhenInitialize() + { + $storage = $this->getMockForAbstractClass('Sylius\Bundle\FlowBundle\Storage\Storage'); + $storage->initialize('mydomain'); + + $this->assertAttributeEquals( + 'mydomain', + 'domain', + $storage + ); + } +} +