LegacyTemplatingAssetHelperPassTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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\DependencyInjection\Compiler;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingAssetHelperPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Definition;
  15. use Symfony\Component\DependencyInjection\Reference;
  16. /**
  17. * @group legacy
  18. */
  19. class LegacyTemplatingAssetHelperPassTest extends TestCase
  20. {
  21. public function getScopesTests()
  22. {
  23. return array(
  24. array('container'),
  25. array('request'),
  26. );
  27. }
  28. /** @dataProvider getScopesTests */
  29. public function testFindLowestScopeInDefaultPackageWithReference($scope)
  30. {
  31. $container = new ContainerBuilder();
  32. $defaultPackage = new Definition('stdClass');
  33. $defaultPackage->setScope($scope);
  34. $container->setDefinition('default_package', $defaultPackage);
  35. $definition = new Definition('stdClass', array(new Reference('default_package')));
  36. $container->setDefinition('templating.helper.assets', $definition);
  37. $profilerPass = new TemplatingAssetHelperPass();
  38. $profilerPass->process($container);
  39. $this->assertSame($scope, $definition->getScope());
  40. }
  41. /** @dataProvider getScopesTests */
  42. public function testFindLowestScopeInDefaultPackageWithDefinition($scope)
  43. {
  44. $container = new ContainerBuilder();
  45. $defaultPackage = new Definition('stdClass');
  46. $defaultPackage->setScope($scope);
  47. $definition = new Definition('stdClass', array($defaultPackage));
  48. $container->setDefinition('templating.helper.assets', $definition);
  49. $profilerPass = new TemplatingAssetHelperPass();
  50. $profilerPass->process($container);
  51. $this->assertSame($scope, $definition->getScope());
  52. }
  53. /** @dataProvider getScopesTests */
  54. public function testFindLowestScopeInNamedPackageWithReference($scope)
  55. {
  56. $container = new ContainerBuilder();
  57. $defaultPackage = new Definition('stdClass');
  58. $container->setDefinition('default_package', $defaultPackage);
  59. $aPackage = new Definition('stdClass');
  60. $container->setDefinition('a_package', $aPackage);
  61. $bPackage = new Definition('stdClass');
  62. $bPackage->setScope($scope);
  63. $container->setDefinition('b_package', $bPackage);
  64. $cPackage = new Definition('stdClass');
  65. $container->setDefinition('c_package', $cPackage);
  66. $definition = new Definition('stdClass', array(new Reference('default_package'), array(
  67. new Reference('a_package'),
  68. new Reference('b_package'),
  69. new Reference('c_package'),
  70. )));
  71. $container->setDefinition('templating.helper.assets', $definition);
  72. $profilerPass = new TemplatingAssetHelperPass();
  73. $profilerPass->process($container);
  74. $this->assertSame($scope, $definition->getScope());
  75. }
  76. /** @dataProvider getScopesTests */
  77. public function testFindLowestScopeInNamedPackageWithDefinition($scope)
  78. {
  79. $container = new ContainerBuilder();
  80. $defaultPackage = new Definition('stdClass');
  81. $aPackage = new Definition('stdClass');
  82. $bPackage = new Definition('stdClass');
  83. $bPackage->setScope($scope);
  84. $cPackage = new Definition('stdClass');
  85. $definition = new Definition('stdClass', array($defaultPackage, array(
  86. $aPackage,
  87. $bPackage,
  88. $cPackage,
  89. )));
  90. $container->setDefinition('templating.helper.assets', $definition);
  91. $profilerPass = new TemplatingAssetHelperPass();
  92. $profilerPass->process($container);
  93. $this->assertSame($scope, $definition->getScope());
  94. }
  95. }