Kernel.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Tests;
  11. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  12. use Symfony\Component\HttpKernel\Util\Filesystem;
  13. use Symfony\Component\ClassLoader\UniversalClassLoader;
  14. use Symfony\Component\Config\Loader\LoaderInterface;
  15. class Kernel extends BaseKernel
  16. {
  17. public function __construct()
  18. {
  19. $this->rootDir = sys_get_temp_dir().'/sf2_'.rand(1, 9999);
  20. if (!is_dir($this->rootDir)) {
  21. if (false === @mkdir($this->rootDir)) {
  22. exit(sprintf('Unable to create a temporary directory (%s)', $this->rootDir));
  23. }
  24. } elseif (!is_writable($this->rootDir)) {
  25. exit(sprintf('Unable to write in a temporary directory (%s)', $this->rootDir));
  26. }
  27. parent::__construct('env', true);
  28. $loader = new UniversalClassLoader();
  29. $loader->registerNamespaces(array(
  30. 'TestBundle' => __DIR__.'/Fixtures/',
  31. 'TestApplication' => __DIR__.'/Fixtures/',
  32. ));
  33. $loader->register();
  34. }
  35. public function __destruct()
  36. {
  37. $fs = new Filesystem();
  38. $fs->remove($this->rootDir);
  39. }
  40. public function registerBundles()
  41. {
  42. return array(
  43. new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
  44. new \TestBundle\Sensio\FooBundle\SensioFooBundle(),
  45. new \TestBundle\Sensio\Cms\FooBundle\SensioCmsFooBundle(),
  46. new \TestBundle\FooBundle\FooBundle(),
  47. new \TestBundle\Fabpot\FooBundle\FabpotFooBundle(),
  48. );
  49. }
  50. public function registerContainerConfiguration(LoaderInterface $loader)
  51. {
  52. $loader->load(function ($container) {
  53. $container->setParameter('kernel.compiled_classes', array());
  54. });
  55. }
  56. }