Ei kuvausta

AddClassesToCachePassTest.php 4.9KB

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