Skip to content

Commit fd11f91

Browse files
committed
Add test suite and configuration for Travis CI
1 parent fb63a8e commit fd11f91

File tree

13 files changed

+315
-18
lines changed

13 files changed

+315
-18
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/
2+
/Tests/Functional/cache
3+
/Tests/Functional/logs
4+
composer.lock

.travis.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
language: php
2+
warnings_are_errors: false
3+
sudo: false
4+
5+
php:
6+
- 5.6
7+
- 7.0
8+
- 7.1
9+
- 7.2
10+
- nightly
11+
- hhvm
12+
13+
env:
14+
global:
15+
- PATH="$HOME/.composer/vendor/bin:$PATH"
16+
- COMPOSER_MEMORY_LIMIT=3G
17+
18+
matrix:
19+
fast_finish: true
20+
include:
21+
- php: 5.6
22+
- php: 5.6
23+
env: COMPOSER_FLAGS="--prefer-lowest"
24+
- php: 5.6
25+
env: SYMFONY_VERSION="~2.8.0"
26+
- php: 5.6
27+
env: SYMFONY_VERSION="~3.0.0"
28+
- php: 5.6
29+
env: SYMFONY_VERSION="~3.4.0"
30+
- php: 7.2
31+
env: SYMFONY_VERSION="^4.0@dev"
32+
allow_failures:
33+
- php: nightly
34+
- php: hhvm
35+
- env: SYMFONY_VERSION="^4.0@dev"
36+
37+
cache:
38+
directories:
39+
- $HOME/.composer/cache
40+
41+
before_script:
42+
- if [[ $TRAVIS_PHP_VERSION != hhvm && -f xdebug.ini ]]; then phpenv config-rm xdebug.ini; fi
43+
- if [ "$GITHUB_OAUTH_TOKEN" != "" ]; then echo -e $GITHUB_OAUTH_TOKEN && composer config -g github-oauth.github.com $GITHUB_OAUTH_TOKEN; fi;
44+
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
45+
- composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
46+
47+
script:
48+
- vendor/bin/simple-phpunit

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function getConfigTreeBuilder()
2222
$treeBuilder->root('flodaq_ticket_notification')
2323
->children()
2424
->arrayNode('emails')
25+
->isRequired()
2526
->children()
2627
->scalarNode('sender_email')->isRequired()->cannotBeEmpty()->end()
2728
->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()

EventSubscriber/HackzillaTicketSubscriber.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Flodaq\TicketNotificationBundle\Mailer\Mailer;
66
use Hackzilla\Bundle\TicketBundle\Event\TicketEvent;
77
use Hackzilla\Bundle\TicketBundle\TicketEvents;
8-
use Symfony\Component\DependencyInjection\ContainerInterface;
98
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
109

1110
/**
@@ -15,18 +14,16 @@
1514
class HackzillaTicketSubscriber implements EventSubscriberInterface
1615
{
1716
/**
18-
* @var ContainerInterface
17+
* @var Mailer
1918
*/
20-
private $container;
19+
private $mailer;
2120

2221
/**
23-
* Mailer constructor.
24-
*
25-
* @param ContainerInterface $container
22+
* @param Mailer $mailer
2623
*/
27-
public function __construct(ContainerInterface $container)
24+
public function __construct(Mailer $mailer)
2825
{
29-
$this->container = $container;
26+
$this->mailer = $mailer;
3027
}
3128

3229
/**
@@ -48,8 +45,6 @@ public static function getSubscribedEvents()
4845
*/
4946
public function ticketNotification(TicketEvent $event, $eventName)
5047
{
51-
/** @var Mailer $mailer */
52-
$mailer = $this->container->get('flodaq_ticket_notification.mailer');
53-
$mailer->sendTicketNotificationEmailMessage($event->getTicket(), $eventName);
48+
$this->mailer->sendTicketNotificationEmailMessage($event->getTicket(), $eventName);
5449
}
55-
}
50+
}

Mailer/Mailer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function sendTicketNotificationEmailMessage(TicketWithAttachment $ticket,
7979
if ($message->getUser() !== $creator->getId()) {
8080
$recipients[] = $creator->getEmail();
8181
}
82-
82+
8383
// Add every user with the ROLE_TICKET_ADMIN role
8484
/** @var User $user */
8585
foreach ($users as $user) {

Resources/config/services.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ services:
22
# Hackzilla TicketEvent subscriber
33
flodaq_ticket_notification.hackzilla_ticket_subscriber:
44
class: Flodaq\TicketNotificationBundle\EventSubscriber\HackzillaTicketSubscriber
5-
arguments: ["@service_container"]
5+
arguments: ["@flodaq_ticket_notification.mailer"]
66
tags:
77
- { name: kernel.event_subscriber }
88

99
# Mailers
1010
flodaq_ticket_notification.mailer:
1111
class: Flodaq\TicketNotificationBundle\Mailer\Mailer
12-
arguments: ["@service_container"]
12+
arguments: ["@service_container"]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Flodaq\TicketNotificationBundle\Tests\Functional;
4+
5+
/**
6+
* @author Javier Spagnoletti <[email protected]>
7+
*/
8+
class FunctionalTest extends WebTestCase
9+
{
10+
public function testConfiguredMailer()
11+
{
12+
$container = static::$kernel->getContainer();
13+
14+
$this->assertTrue($container->hasParameter('flodaq_ticket_notification.emails'));
15+
$this->assertArrayHasKey('sender_email', $container->getParameter('flodaq_ticket_notification.emails'));
16+
$this->assertArrayHasKey('sender_name', $container->getParameter('flodaq_ticket_notification.emails'));
17+
}
18+
19+
public function testMailerService()
20+
{
21+
$container = static::$kernel->getContainer();
22+
23+
$this->assertTrue($container->has('mailer'));
24+
$this->assertInstanceOf(\Swift_Mailer::class, $container->get('mailer'));
25+
}
26+
27+
public function testConfiguredTemplates()
28+
{
29+
$container = static::$kernel->getContainer();
30+
31+
$this->assertTrue($container->hasParameter('flodaq_ticket_notification.templates'));
32+
$this->assertArrayHasKey('new_html', $container->getParameter('flodaq_ticket_notification.templates'));
33+
$this->assertArrayHasKey('new_txt', $container->getParameter('flodaq_ticket_notification.templates'));
34+
$this->assertArrayHasKey('update_html', $container->getParameter('flodaq_ticket_notification.templates'));
35+
$this->assertArrayHasKey('update_txt', $container->getParameter('flodaq_ticket_notification.templates'));
36+
}
37+
}

Tests/Functional/TestBundle.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Flodaq\TicketNotificationBundle\Tests\Functional;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
/**
8+
* @author Javier Spagnoletti <[email protected]>
9+
*/
10+
class TestBundle extends Bundle
11+
{
12+
}

Tests/Functional/TestKernel.php

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
namespace Flodaq\TicketNotificationBundle\Tests\Functional;
4+
5+
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
6+
use Flodaq\TicketNotificationBundle\FlodaqTicketNotificationBundle;
7+
use Hackzilla\Bundle\TicketBundle\HackzillaTicketBundle;
8+
use Hackzilla\Bundle\TicketBundle\Tests\Functional\Entity\User;
9+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
10+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
11+
use Symfony\Bundle\SecurityBundle\SecurityBundle;
12+
use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle;
13+
use Symfony\Component\Config\Loader\LoaderInterface;
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\HttpKernel\Kernel;
16+
use Symfony\Component\Routing\RouteCollectionBuilder;
17+
18+
/**
19+
* @author Javier Spagnoletti <[email protected]>
20+
*/
21+
class TestKernel extends Kernel
22+
{
23+
use MicroKernelTrait;
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
public function registerBundles()
29+
{
30+
$bundles = [
31+
new FrameworkBundle(),
32+
new SecurityBundle(),
33+
new DoctrineBundle(),
34+
new HackzillaTicketBundle(),
35+
new SwiftmailerBundle(),
36+
new FlodaqTicketNotificationBundle(),
37+
new TestBundle(),
38+
];
39+
40+
return $bundles;
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
protected function configureRoutes(RouteCollectionBuilder $routes)
47+
{
48+
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
54+
{
55+
// FrameworkBundle config
56+
$c->loadFromExtension('framework', [
57+
'secret' => 'MySecretKey',
58+
'default_locale' => 'en',
59+
'translator' => [
60+
'fallbacks' => [
61+
'en',
62+
],
63+
],
64+
]);
65+
66+
// SecurityBundle config
67+
$c->loadFromExtension('security', [
68+
'providers' => [
69+
'in_memory' => [
70+
'memory' => null,
71+
],
72+
],
73+
'firewalls' => [
74+
'main' => [
75+
'anonymous' => null,
76+
],
77+
],
78+
]);
79+
80+
// DoctrineBundle config
81+
$c->loadFromExtension('doctrine', [
82+
'dbal' => [
83+
'connections' => [
84+
'default' => [
85+
'driver' => 'pdo_sqlite',
86+
],
87+
],
88+
],
89+
'orm' => [
90+
'default_entity_manager' => 'default',
91+
],
92+
]);
93+
94+
// HackzillaBundle config
95+
$c->loadFromExtension('hackzilla_ticket', [
96+
'user_class' => User::class,
97+
]);
98+
99+
// FlodaqTicketNotificationBundle config
100+
$c->loadFromExtension('flodaq_ticket_notification', [
101+
'emails' => [
102+
'sender_email' => '[email protected]',
103+
'sender_name' => 'John Doe',
104+
],
105+
]);
106+
}
107+
108+
/**
109+
* {@inheritdoc}
110+
*/
111+
public function getCacheDir()
112+
{
113+
return parent::getCacheDir();
114+
}
115+
116+
/**
117+
* {@inheritdoc}
118+
*/
119+
public function getLogDir()
120+
{
121+
return parent::getLogDir();
122+
}
123+
124+
public function unserialize($str)
125+
{
126+
$this->__construct(unserialize($str));
127+
}
128+
}

Tests/Functional/WebTestCase.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Flodaq\TicketNotificationBundle\Tests\Functional;
4+
5+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
6+
7+
/**
8+
* @author Javier Spagnoletti <[email protected]>
9+
*/
10+
class WebTestCase extends BaseWebTestCase
11+
{
12+
protected function setUp()
13+
{
14+
parent::setUp();
15+
16+
static::bootKernel();
17+
}
18+
19+
protected static function createKernel(array $options = [])
20+
{
21+
return new TestKernel('test', true);
22+
}
23+
}

0 commit comments

Comments
 (0)