Skip to content

Commit

Permalink
✅ Add SessionHandler test (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenybernard authored Nov 4, 2016
1 parent 89ab196 commit d3b830f
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Tests/Handler/AlertifySessionHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Troopers\AlertifyBundle\Tests\Helper;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Troopers\AlertifyBundle\DependencyInjection\TroopersAlertifyExtension;
use Troopers\AlertifyBundle\Handler\AlertifySessionHandler;
use Troopers\AlertifyBundle\Helper\AlertifyHelper;

class AlertifySessionHandlerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Twig_Environment
*/
protected $twigEnvironment;
/**
* @var Session
*/
protected $session;

public function testDefault()
{
$this->mockSession();
$container = new ContainerBuilder();
$loader = new TroopersAlertifyExtension();
$loader->load([[]], $container);
/** @var AlertifyHelper $helper */
$helper = new AlertifyHelper($this->session);
$handler = new AlertifySessionHandler(
$this->getTwigEnvironmentMock(),
$container->getParameter('troopers_alertify')
);

$helper->congrat('Alert1');
$this->assertEquals(1, count(explode(' ', $handler->handle($this->session))));
$helper->congrat('Alert2');
$helper->congrat('Alert3', ['opt1' => 42]);
$helper->congrat('Alert4');
$this->assertEquals(3, count(explode(' ', $handler->handle($this->session))));
}

/**
* @return Session
*/
protected function mockSession()
{
$this->session = new Session(new MockArraySessionStorage());
}

protected function getTwigEnvironmentMock()
{
$twigEnvironment = $this->getMockBuilder('Twig_Environment')
->setMethods(['render'])
->getMock();

return $twigEnvironment;
}
}

0 comments on commit d3b830f

Please sign in to comment.