Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Dependency injection and Helper tests #56

Merged
merged 2 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/*
composer.lock
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: php

sudo: false

cache:
directory:
- $HOME/.composer/cache/files

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

matrix:
include:
- php: 5.6
env: DEPENDENCIES='dev'

install: composer update $COMPOSER_FLAGS

script: phpunit -v
106 changes: 106 additions & 0 deletions Tests/DependencyInjection/AlertifyExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace Troopers\AlertifyBundle\Tests\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Troopers\AlertifyBundle\DependencyInjection\TroopersAlertifyExtension;

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'));
}
}
62 changes: 62 additions & 0 deletions Tests/Helper/AlertifyHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Troopers\AlertifyBundle\Tests\Helper;

use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
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());
}
}
11 changes: 2 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "troopers/alertify-bundle",
"type": "symfony-bundle",
"description": "Symfony AlertifyBundle",
"keywords": ["alert", "bootstrap"],
"keywords": ["alert"],
"homepage": "https://github.com/Troopers/TroopersAlertifyBundle",
"license": "MIT",
"authors": [
Expand All @@ -29,12 +29,5 @@
"autoload": {
"psr-0": { "Troopers\\AlertifyBundle": "" }
},
"target-dir": "Troopers/AlertifyBundle",

"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
"target-dir": "Troopers/AlertifyBundle"
}
20 changes: 20 additions & 0 deletions phpunit.xml.dist
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>