-
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.
✅ add Dependency injection and Helper tests
- Loading branch information
Leny BERNARD
committed
Nov 3, 2016
1 parent
2c58770
commit d52c53f
Showing
6 changed files
with
218 additions
and
9 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,2 @@ | ||
vendor/* | ||
composer.lock |
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,26 @@ | ||
language: php | ||
|
||
sudo: false | ||
|
||
cache: | ||
directory: | ||
- $HOME/.composer/cache/files | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- hhvm | ||
|
||
matrix: | ||
include: | ||
- php: 5.3 | ||
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable' | ||
- php: 5.6 | ||
env: DEPENDENCIES='dev' | ||
|
||
install: composer update $COMPOSER_FLAGS | ||
|
||
script: phpunit -v |
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,107 @@ | ||
<?php | ||
|
||
namespace Troopers\AlertifyBundle\Tests\DependencyInjection; | ||
|
||
use Troopers\AlertifyBundle\DependencyInjection\TroopersAlertifyExtension; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class AlertifyExtensionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testDefault() | ||
{ | ||
$container = new ContainerBuilder(); | ||
$loader = new TroopersAlertifyExtension(); | ||
$loader->load([[]], $container); | ||
$this->assertTrue($container->hasDefinition('alertify'), 'The alertify service exists'); | ||
$this->assertEquals('Troopers\\AlertifyBundle\\Twig\\Extension\\AlertifyExtension', $container->getParameter('alertify.twig.extension.class')); | ||
$this->assertEquals('Troopers\\AlertifyBundle\\Handler\\AlertifySessionHandler', $container->getParameter('alertify.handler.session.class')); | ||
$this->assertEquals('Troopers\\AlertifyBundle\\Helper\\AlertifyHelper', $container->getParameter('alertify.helper.class')); | ||
$this->assertEquals('Troopers\\AlertifyBundle\\EventListener\\AlertifyListener', $container->getParameter('alertify.event_listener')); | ||
$this->assertEquals([ | ||
'default' => [ | ||
'context' => 'front', | ||
'engine' => 'toastr', | ||
'layout' => null, | ||
'translationDomain' => 'alertify' | ||
], | ||
'contexts' => [] | ||
], $container->getParameter('troopers_alertify')); | ||
$this->assertEquals([], $container->getParameter('troopers_alertify.contexts')); | ||
$this->assertEquals('front', $container->getParameter('troopers_alertify.default.context')); | ||
$this->assertEquals('toastr', $container->getParameter('troopers_alertify.default.engine')); | ||
$this->assertEquals(null, $container->getParameter('troopers_alertify.default.layout')); | ||
$this->assertEquals('alertify', $container->getParameter('troopers_alertify.default.translationdomain')); | ||
} | ||
|
||
public function testContexts() | ||
{ | ||
$container = new ContainerBuilder(); | ||
$loader = new TroopersAlertifyExtension(); | ||
$loader->load([[ | ||
'contexts' => [ | ||
'front' => [ | ||
'engine' => 'notie', | ||
'options' => [ | ||
'animationDelay' => 300 | ||
] | ||
], | ||
'back' => [ | ||
'engine' => 'pushjs', | ||
'translationDomain' => 'admin' | ||
] | ||
], | ||
'default' => [ | ||
'engine' => 'notie' | ||
]]], $container); | ||
$this->assertSame([ | ||
'contexts' => [ | ||
'front' => [ | ||
'engine' => 'notie', | ||
'options' => [ | ||
'animationDelay' => 300 | ||
], | ||
'layout' => null, | ||
'translationDomain' => 'alertify', | ||
'timeout' => null, | ||
], | ||
'back' => [ | ||
'engine' => 'pushjs', | ||
'translationDomain' => 'admin', | ||
'layout' => null, | ||
'timeout' => null, | ||
'options' => [] | ||
] | ||
], | ||
'default' => [ | ||
'engine' => 'notie', | ||
'context' => 'front', | ||
'layout' => null, | ||
'translationDomain' => 'alertify' | ||
] | ||
, | ||
], $container->getParameter('troopers_alertify')); | ||
|
||
$this->assertEquals([ | ||
'front' => [ | ||
'engine' => 'notie', | ||
'layout' => null, | ||
'translationDomain' => 'alertify', | ||
'timeout' => null, | ||
'options' => [ | ||
'animationDelay' => 300 | ||
] | ||
], | ||
'back' => [ | ||
'engine' => 'pushjs', | ||
'translationDomain' => 'admin', | ||
'layout' => null, | ||
'timeout' => null, | ||
'options' => [] | ||
] | ||
], $container->getParameter('troopers_alertify.contexts')); | ||
$this->assertEquals('front', $container->getParameter('troopers_alertify.default.context')); | ||
$this->assertEquals('notie', $container->getParameter('troopers_alertify.default.engine')); | ||
$this->assertEquals(null, $container->getParameter('troopers_alertify.default.layout')); | ||
$this->assertEquals('alertify', $container->getParameter('troopers_alertify.default.translationdomain')); | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
namespace Troopers\AlertifyBundle\Tests\Helper; | ||
|
||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
use Troopers\AlertifyBundle\Helper\AlertifyHelper; | ||
|
||
class AlertifyHelperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testFlashBagPopulate() | ||
{ | ||
$session = $this->getSessionMock(); | ||
$helper = new AlertifyHelper($session); | ||
$helper->alert('Alert', 'success'); | ||
$this->assertEquals([['body' => 'Alert', 'options' => []]], $session->getFlashBag()->get('success')); | ||
|
||
$helper->alert('Alert', 'success'); | ||
$helper->alert('Alert queued', 'success'); | ||
$this->assertEquals([['body' => 'Alert', 'options' => []], ['body' => 'Alert queued', 'options' => []]], $session->getFlashBag()->get('success')); | ||
|
||
$helper->congrat('Congratulation'); | ||
$this->assertEquals([['body' => 'Congratulation', 'options' => []]], $session->getFlashBag()->get('success')); | ||
|
||
$helper->inform('Information'); | ||
$this->assertEquals([['body' => 'Information', 'options' => []]], $session->getFlashBag()->get('info')); | ||
|
||
$helper->warn('Warning'); | ||
$this->assertEquals([['body' => 'Warning', 'options' => []]], $session->getFlashBag()->get('warning')); | ||
|
||
$helper->scold('Danger !'); | ||
$this->assertEquals([['body' => 'Danger !', 'options' => []]], $session->getFlashBag()->get('error')); | ||
} | ||
|
||
public function testFlashBagWithOptions() | ||
{ | ||
$session = $this->getSessionMock(); | ||
$helper = new AlertifyHelper($session); | ||
$helper->alert('Alert', 'success', ['backgroundColor' => 'green']); | ||
$this->assertEquals([['body' => 'Alert', 'options' => ['backgroundColor' => 'green']]], $session->getFlashBag()->get('success')); | ||
|
||
$helper->congrat('Congratulation', ['backgroundColor' => 'green']); | ||
$this->assertEquals([['body' => 'Congratulation', 'options' => ['backgroundColor' => 'green']]], $session->getFlashBag()->get('success')); | ||
|
||
$helper->inform('Information', ['backgroundColor' => 'blue']); | ||
$this->assertEquals([['body' => 'Information', 'options' => ['backgroundColor' => 'blue']]], $session->getFlashBag()->get('info')); | ||
|
||
$helper->warn('Warning', ['backgroundColor' => 'orange']); | ||
$this->assertEquals([['body' => 'Warning', 'options' => ['backgroundColor' => 'orange']]], $session->getFlashBag()->get('warning')); | ||
|
||
$helper->scold('Danger !', ['backgroundColor' => 'red']); | ||
$this->assertEquals([['body' => 'Danger !', 'options' => ['backgroundColor' => 'red']]], $session->getFlashBag()->get('error')); | ||
} | ||
|
||
/** | ||
* @return Session | ||
*/ | ||
protected function getSessionMock() { | ||
return new Session(new MockArraySessionStorage()); | ||
} | ||
} |
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
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit colors="true" bootstrap="vendor/autoload.php"> | ||
<testsuites> | ||
<testsuite name="TroopersAlertifyBundle Test Suite"> | ||
<directory suffix="Test.php">./Tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./</directory> | ||
<exclude> | ||
<directory>./Resources</directory> | ||
<directory>./Tests</directory> | ||
<directory>./vendor</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |