ConfigDataCollectorTest.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\HttpKernel\DataCollector\ConfigDataCollector;
  13. use Symfony\Component\HttpKernel\Kernel;
  14. use Symfony\Component\Config\Loader\LoaderInterface;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  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') && ini_get('opcache.enable'), $c->hasZendOpcache());
  38. $this->assertSame(extension_loaded('apcu') && ini_get('apc.enabled'), $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 array();
  53. }
  54. public function registerContainerConfiguration(LoaderInterface $loader)
  55. {
  56. }
  57. }