ConfigDataCollectorTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Component\HttpKernel\Tests\DataCollector;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Loader\LoaderInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector;
  16. use Symfony\Component\HttpKernel\Kernel;
  17. class ConfigDataCollectorTest extends TestCase
  18. {
  19. public function testCollect()
  20. {
  21. $kernel = new KernelForTest('test', true);
  22. $c = new ConfigDataCollector();
  23. $c->setKernel($kernel);
  24. $c->collect(new Request(), new Response());
  25. $this->assertSame('test', $c->getEnv());
  26. $this->assertTrue($c->isDebug());
  27. $this->assertSame('config', $c->getName());
  28. $this->assertSame('testkernel', $c->getAppName());
  29. $this->assertSame(PHP_VERSION, $c->getPhpVersion());
  30. $this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
  31. $this->assertNull($c->getToken());
  32. // if else clause because we don't know it
  33. if (\extension_loaded('xdebug')) {
  34. $this->assertTrue($c->hasXDebug());
  35. } else {
  36. $this->assertFalse($c->hasXDebug());
  37. }
  38. // if else clause because we don't know it
  39. if (((\extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'))
  40. ||
  41. (\extension_loaded('apc') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN))
  42. ||
  43. (\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN))
  44. ||
  45. (\extension_loaded('xcache') && filter_var(ini_get('xcache.cacher'), FILTER_VALIDATE_BOOLEAN))
  46. ||
  47. (\extension_loaded('wincache') && filter_var(ini_get('wincache.ocenabled'), FILTER_VALIDATE_BOOLEAN)))) {
  48. $this->assertTrue($c->hasAccelerator());
  49. } else {
  50. $this->assertFalse($c->hasAccelerator());
  51. }
  52. }
  53. }
  54. class KernelForTest extends Kernel
  55. {
  56. public function getName()
  57. {
  58. return 'testkernel';
  59. }
  60. public function registerBundles()
  61. {
  62. }
  63. public function getBundles()
  64. {
  65. return array();
  66. }
  67. public function registerContainerConfiguration(LoaderInterface $loader)
  68. {
  69. }
  70. }