|
| 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 | +} |
0 commit comments