ConfigDataCollectorTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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->assertRegExp('~^'.preg_quote($c->getPhpVersion(), '~').'~', PHP_VERSION);
  30. $this->assertRegExp('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', PHP_VERSION);
  31. $this->assertSame(PHP_INT_SIZE * 8, $c->getPhpArchitecture());
  32. $this->assertSame(class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale());
  33. $this->assertSame(date_default_timezone_get(), $c->getPhpTimezone());
  34. $this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
  35. $this->assertNull($c->getToken());
  36. $this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
  37. $this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
  38. $this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
  39. }
  40. }
  41. class KernelForTest extends Kernel
  42. {
  43. public function getName()
  44. {
  45. return 'testkernel';
  46. }
  47. public function registerBundles()
  48. {
  49. }
  50. public function getBundles()
  51. {
  52. return [];
  53. }
  54. public function registerContainerConfiguration(LoaderInterface $loader)
  55. {
  56. }
  57. }