AddAnnotatedClassesToCachePassTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\DependencyInjection;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
  13. class AddAnnotatedClassesToCachePassTest extends TestCase
  14. {
  15. public function testExpandClasses()
  16. {
  17. $r = new \ReflectionClass(AddAnnotatedClassesToCachePass::class);
  18. $pass = $r->newInstanceWithoutConstructor();
  19. $r = new \ReflectionMethod(AddAnnotatedClassesToCachePass::class, 'expandClasses');
  20. $r->setAccessible(true);
  21. $expand = $r->getClosure($pass);
  22. $this->assertSame('Foo', $expand(['Foo'], [])[0]);
  23. $this->assertSame('Foo', $expand(['\\Foo'], [])[0]);
  24. $this->assertSame('Foo', $expand(['Foo'], ['\\Foo'])[0]);
  25. $this->assertSame('Foo', $expand(['Foo'], ['Foo'])[0]);
  26. $this->assertSame('Foo', $expand(['\\Foo'], ['\\Foo\\Bar'])[0]);
  27. $this->assertSame('Foo', $expand(['Foo'], ['\\Foo\\Bar'])[0]);
  28. $this->assertSame('Foo', $expand(['\\Foo'], ['\\Foo\\Bar\\Acme'])[0]);
  29. $this->assertSame('Foo\\Bar', $expand(['Foo\\'], ['\\Foo\\Bar'])[0]);
  30. $this->assertSame('Foo\\Bar\\Acme', $expand(['Foo\\'], ['\\Foo\\Bar\\Acme'])[0]);
  31. $this->assertEmpty($expand(['Foo\\'], ['\\Foo']));
  32. $this->assertSame('Acme\\Foo\\Bar', $expand(['**\\Foo\\'], ['\\Acme\\Foo\\Bar'])[0]);
  33. $this->assertEmpty($expand(['**\\Foo\\'], ['\\Foo\\Bar']));
  34. $this->assertEmpty($expand(['**\\Foo\\'], ['\\Acme\\Foo']));
  35. $this->assertEmpty($expand(['**\\Foo\\'], ['\\Foo']));
  36. $this->assertSame('Acme\\Foo', $expand(['**\\Foo'], ['\\Acme\\Foo'])[0]);
  37. $this->assertEmpty($expand(['**\\Foo'], ['\\Acme\\Foo\\AcmeBundle']));
  38. $this->assertEmpty($expand(['**\\Foo'], ['\\Acme\\FooBar\\AcmeBundle']));
  39. $this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\*\\Bar'], ['\\Foo\\Acme\\Bar'])[0]);
  40. $this->assertEmpty($expand(['Foo\\*\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar']));
  41. $this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**\\Bar'], ['\\Foo\\Acme\\Bar'])[0]);
  42. $this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(['Foo\\**\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar'])[0]);
  43. $this->assertSame('Acme\\Bar', $expand(['*\\Bar'], ['\\Acme\\Bar'])[0]);
  44. $this->assertEmpty($expand(['*\\Bar'], ['\\Bar']));
  45. $this->assertEmpty($expand(['*\\Bar'], ['\\Foo\\Acme\\Bar']));
  46. $this->assertSame('Foo\\Acme\\Bar', $expand(['**\\Bar'], ['\\Foo\\Acme\\Bar'])[0]);
  47. $this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(['**\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar'])[0]);
  48. $this->assertEmpty($expand(['**\\Bar'], ['\\Bar']));
  49. $this->assertSame('Foo\\Bar', $expand(['Foo\\*'], ['\\Foo\\Bar'])[0]);
  50. $this->assertEmpty($expand(['Foo\\*'], ['\\Foo\\Acme\\Bar']));
  51. $this->assertSame('Foo\\Bar', $expand(['Foo\\**'], ['\\Foo\\Bar'])[0]);
  52. $this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**'], ['\\Foo\\Acme\\Bar'])[0]);
  53. $this->assertSame(['Foo\\Bar'], $expand(['Foo\\*'], ['Foo\\Bar', 'Foo\\BarTest']));
  54. $this->assertSame(['Foo\\Bar', 'Foo\\BarTest'], $expand(['Foo\\*', 'Foo\\*Test'], ['Foo\\Bar', 'Foo\\BarTest']));
  55. $this->assertSame(
  56. 'Acme\\FooBundle\\Controller\\DefaultController',
  57. $expand(['**Bundle\\Controller\\'], ['\\Acme\\FooBundle\\Controller\\DefaultController'])[0]
  58. );
  59. $this->assertSame(
  60. 'FooBundle\\Controller\\DefaultController',
  61. $expand(['**Bundle\\Controller\\'], ['\\FooBundle\\Controller\\DefaultController'])[0]
  62. );
  63. $this->assertSame(
  64. 'Acme\\FooBundle\\Controller\\Bar\\DefaultController',
  65. $expand(['**Bundle\\Controller\\'], ['\\Acme\\FooBundle\\Controller\\Bar\\DefaultController'])[0]
  66. );
  67. $this->assertSame(
  68. 'Bundle\\Controller\\Bar\\DefaultController',
  69. $expand(['**Bundle\\Controller\\'], ['\\Bundle\\Controller\\Bar\\DefaultController'])[0]
  70. );
  71. $this->assertSame(
  72. 'Acme\\Bundle\\Controller\\Bar\\DefaultController',
  73. $expand(['**Bundle\\Controller\\'], ['\\Acme\\Bundle\\Controller\\Bar\\DefaultController'])[0]
  74. );
  75. $this->assertSame('Foo\\Bar', $expand(['Foo\\Bar'], [])[0]);
  76. $this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**'], ['\\Foo\\Acme\\Bar'])[0]);
  77. }
  78. }