ConfigDataCollectorTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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->assertRegExp('~^'.preg_quote($c->getPhpVersion(), '~').'~', PHP_VERSION);
  29. $this->assertRegExp('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', PHP_VERSION);
  30. $this->assertSame(PHP_INT_SIZE * 8, $c->getPhpArchitecture());
  31. $this->assertSame(class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale());
  32. $this->assertSame(date_default_timezone_get(), $c->getPhpTimezone());
  33. $this->assertSame(Kernel::VERSION, $c->getSymfonyVersion());
  34. $this->assertNull($c->getToken());
  35. $this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug());
  36. $this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache());
  37. $this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN), $c->hasApcu());
  38. }
  39. /**
  40. * @group legacy
  41. * @expectedDeprecation The "$name" argument in method "Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector::__construct()" is deprecated since Symfony 4.2.
  42. * @expectedDeprecation The "$version" argument in method "Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector::__construct()" is deprecated since Symfony 4.2.
  43. * @expectedDeprecation The method "Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector::getApplicationName()" is deprecated since Symfony 4.2.
  44. * @expectedDeprecation The method "Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector::getApplicationVersion()" is deprecated since Symfony 4.2.
  45. */
  46. public function testLegacy()
  47. {
  48. $c = new ConfigDataCollector('name', null);
  49. $c->collect(new Request(), new Response());
  50. $this->assertSame('name', $c->getApplicationName());
  51. $this->assertNull($c->getApplicationVersion());
  52. }
  53. }
  54. class KernelForTest extends Kernel
  55. {
  56. public function registerBundles()
  57. {
  58. }
  59. public function getBundles()
  60. {
  61. return [];
  62. }
  63. public function registerContainerConfiguration(LoaderInterface $loader)
  64. {
  65. }
  66. }