AddAnnotatedClassesToCachePassTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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(array('Foo'), array())[0]);
  23. $this->assertSame('Foo', $expand(array('\\Foo'), array())[0]);
  24. $this->assertSame('Foo', $expand(array('Foo'), array('\\Foo'))[0]);
  25. $this->assertSame('Foo', $expand(array('Foo'), array('Foo'))[0]);
  26. $this->assertSame('Foo', $expand(array('\\Foo'), array('\\Foo\\Bar'))[0]);
  27. $this->assertSame('Foo', $expand(array('Foo'), array('\\Foo\\Bar'))[0]);
  28. $this->assertSame('Foo', $expand(array('\\Foo'), array('\\Foo\\Bar\\Acme'))[0]);
  29. $this->assertSame('Foo\\Bar', $expand(array('Foo\\'), array('\\Foo\\Bar'))[0]);
  30. $this->assertSame('Foo\\Bar\\Acme', $expand(array('Foo\\'), array('\\Foo\\Bar\\Acme'))[0]);
  31. $this->assertEmpty($expand(array('Foo\\'), array('\\Foo')));
  32. $this->assertSame('Acme\\Foo\\Bar', $expand(array('**\\Foo\\'), array('\\Acme\\Foo\\Bar'))[0]);
  33. $this->assertEmpty($expand(array('**\\Foo\\'), array('\\Foo\\Bar')));
  34. $this->assertEmpty($expand(array('**\\Foo\\'), array('\\Acme\\Foo')));
  35. $this->assertEmpty($expand(array('**\\Foo\\'), array('\\Foo')));
  36. $this->assertSame('Acme\\Foo', $expand(array('**\\Foo'), array('\\Acme\\Foo'))[0]);
  37. $this->assertEmpty($expand(array('**\\Foo'), array('\\Acme\\Foo\\AcmeBundle')));
  38. $this->assertEmpty($expand(array('**\\Foo'), array('\\Acme\\FooBar\\AcmeBundle')));
  39. $this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\*\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
  40. $this->assertEmpty($expand(array('Foo\\*\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar')));
  41. $this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
  42. $this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(array('Foo\\**\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar'))[0]);
  43. $this->assertSame('Acme\\Bar', $expand(array('*\\Bar'), array('\\Acme\\Bar'))[0]);
  44. $this->assertEmpty($expand(array('*\\Bar'), array('\\Bar')));
  45. $this->assertEmpty($expand(array('*\\Bar'), array('\\Foo\\Acme\\Bar')));
  46. $this->assertSame('Foo\\Acme\\Bar', $expand(array('**\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
  47. $this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(array('**\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar'))[0]);
  48. $this->assertEmpty($expand(array('**\\Bar'), array('\\Bar')));
  49. $this->assertSame('Foo\\Bar', $expand(array('Foo\\*'), array('\\Foo\\Bar'))[0]);
  50. $this->assertEmpty($expand(array('Foo\\*'), array('\\Foo\\Acme\\Bar')));
  51. $this->assertSame('Foo\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Bar'))[0]);
  52. $this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Acme\\Bar'))[0]);
  53. $this->assertSame(array('Foo\\Bar'), $expand(array('Foo\\*'), array('Foo\\Bar', 'Foo\\BarTest')));
  54. $this->assertSame(array('Foo\\Bar', 'Foo\\BarTest'), $expand(array('Foo\\*', 'Foo\\*Test'), array('Foo\\Bar', 'Foo\\BarTest')));
  55. $this->assertSame(
  56. 'Acme\\FooBundle\\Controller\\DefaultController',
  57. $expand(array('**Bundle\\Controller\\'), array('\\Acme\\FooBundle\\Controller\\DefaultController'))[0]
  58. );
  59. $this->assertSame(
  60. 'FooBundle\\Controller\\DefaultController',
  61. $expand(array('**Bundle\\Controller\\'), array('\\FooBundle\\Controller\\DefaultController'))[0]
  62. );
  63. $this->assertSame(
  64. 'Acme\\FooBundle\\Controller\\Bar\\DefaultController',
  65. $expand(array('**Bundle\\Controller\\'), array('\\Acme\\FooBundle\\Controller\\Bar\\DefaultController'))[0]
  66. );
  67. $this->assertSame(
  68. 'Bundle\\Controller\\Bar\\DefaultController',
  69. $expand(array('**Bundle\\Controller\\'), array('\\Bundle\\Controller\\Bar\\DefaultController'))[0]
  70. );
  71. $this->assertSame(
  72. 'Acme\\Bundle\\Controller\\Bar\\DefaultController',
  73. $expand(array('**Bundle\\Controller\\'), array('\\Acme\\Bundle\\Controller\\Bar\\DefaultController'))[0]
  74. );
  75. $this->assertSame('Foo\\Bar', $expand(array('Foo\\Bar'), array())[0]);
  76. $this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Acme\\Bar'))[0]);
  77. }
  78. }