-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89ab196
commit d3b830f
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |