Skip to content

Commit f6ac920

Browse files
committed
Add missing dependencies and check for presence of VichUploaderBundle before trying to use it
1 parent b1f4d23 commit f6ac920

10 files changed

Lines changed: 254 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
vendor/
1+
/vendor/
2+
/Tests/Functional/cache
3+
/Tests/Functional/logs
24
composer.lock
35
.php_cs.cache

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ matrix:
2727
env: SYMFONY_VERSION="3.1.*"
2828
- php: 5.6
2929
env: SYMFONY_VERSION="3.2.*@dev"
30+
- php: 5.6
31+
env: INSTALL_VICH_UPLOADER_BUNDLE=true
3032
allow_failures:
3133
- php: nightly
3234
- php: hhvm
@@ -42,7 +44,8 @@ before_script:
4244
- if [[ $TRAVIS_PHP_VERSION != hhvm && -f xdebug.ini ]]; then phpenv config-rm xdebug.ini; fi
4345
- if [ "$GITHUB_OAUTH_TOKEN" != "" ]; then echo -e $GITHUB_OAUTH_TOKEN && composer config -g github-oauth.github.com $GITHUB_OAUTH_TOKEN; fi;
4446
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
47+
- if [ -n $INSTALL_VICH_UPLOADER_BUNDLE ]; then composer require "vich/uploader-bundle" --no-update; fi;
4548
- composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
4649

4750
script:
48-
- make test
51+
- if [[ -n $INSTALL_VICH_UPLOADER_BUNDLE ]]; then make test_with_vichuploaderbundle; else make test; fi;

DependencyInjection/HackzillaTicketExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public function load(array $configs, ContainerBuilder $container)
3131

3232
$container->setParameter('hackzilla_ticket.features', $config['features']);
3333
$container->setParameter('hackzilla_ticket.templates', $config['templates']);
34+
35+
$bundles = $container->getParameter('kernel.bundles');
36+
// Remove "file_upload_subscriber" definition if VichUploaderBundle is not registered
37+
if (!isset($bundles['VichUploaderBundle'])) {
38+
$container->removeDefinition('hackzilla_ticket.file_upload_subscriber');
39+
}
3440
}
3541

3642
public static function bundleDirectory()

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ cs_dry_run:
55
php-cs-fixer fix --verbose --dry-run
66

77
test:
8+
vendor/bin/phpunit -c phpunit.xml.dist --exclude-group vichuploaderbundle
9+
10+
test_with_vichuploaderbundle:
811
vendor/bin/phpunit -c phpunit.xml.dist

Tests/Functional/Entity/User.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Hackzilla\Bundle\TicketBundle\Tests\Functional\Entity;
4+
5+
use Hackzilla\Bundle\TicketBundle\Model\UserInterface;
6+
7+
/**
8+
* @author Javier Spagnoletti <phansys@gmail.com>
9+
*/
10+
class User implements UserInterface
11+
{
12+
public function getId()
13+
{
14+
}
15+
16+
public function getUsername()
17+
{
18+
}
19+
20+
public function getEmail()
21+
{
22+
}
23+
24+
public function getRoles()
25+
{
26+
}
27+
28+
public function getPassword()
29+
{
30+
}
31+
32+
public function getSalt()
33+
{
34+
}
35+
36+
public function eraseCredentials()
37+
{
38+
}
39+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Hackzilla\Bundle\TicketBundle\Tests\Functional;
4+
5+
use Vich\UploaderBundle\Event\Events;
6+
7+
/**
8+
* @author Javier Spagnoletti <phansys@gmail.com>
9+
*/
10+
class FunctionalTest extends WebTestCase
11+
{
12+
public function testConfiguredTicketManager()
13+
{
14+
$this->assertTrue(static::$kernel->getContainer()->has('hackzilla_ticket.ticket_manager'));
15+
}
16+
17+
/**
18+
* @group vichuploaderbundle
19+
*/
20+
public function testConfiguredFileUploadSubscriber()
21+
{
22+
$eventDispatcher = static::$kernel->getContainer()->get('event_dispatcher');
23+
$listeners = $eventDispatcher->getListeners();
24+
25+
$this->assertArrayHasKey(Events::POST_UPLOAD, $listeners);
26+
}
27+
}

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 Hackzilla\Bundle\TicketBundle\Tests\Functional;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
/**
8+
* @author Javier Spagnoletti <phansys@gmail.com>
9+
*/
10+
class TestBundle extends Bundle
11+
{
12+
}

Tests/Functional/TestKernel.php

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

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 Hackzilla\Bundle\TicketBundle\Tests\Functional;
4+
5+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
6+
7+
/**
8+
* @author Javier Spagnoletti <phansys@gmail.com>
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();
22+
}
23+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"symfony/http-foundation": "^2.8 || ^3.0 || ^4.0",
4040
"symfony/http-kernel": "^2.8 || ^3.0 || ^4.0",
4141
"symfony/options-resolver": "^2.8 || ^3.0 || ^4.0",
42+
"symfony/security-bundle": "^2.8 || ^3.0 || ^4.0",
4243
"symfony/validator": "^2.8 || ^3.0 || ^4.0"
4344
},
4445
"suggest": {

0 commit comments

Comments
 (0)