SupportServiceProviderTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace Illuminate\Tests\Support;
  3. use Illuminate\Foundation\Application;
  4. use Illuminate\Support\ServiceProvider;
  5. use Mockery as m;
  6. use PHPUnit\Framework\TestCase;
  7. class SupportServiceProviderTest extends TestCase
  8. {
  9. protected function setUp(): void
  10. {
  11. ServiceProvider::$publishes = [];
  12. ServiceProvider::$publishGroups = [];
  13. $app = m::mock(Application::class)->makePartial();
  14. $one = new ServiceProviderForTestingOne($app);
  15. $one->boot();
  16. $two = new ServiceProviderForTestingTwo($app);
  17. $two->boot();
  18. }
  19. protected function tearDown(): void
  20. {
  21. m::close();
  22. }
  23. public function testPublishableServiceProviders()
  24. {
  25. $toPublish = ServiceProvider::publishableProviders();
  26. $expected = [
  27. ServiceProviderForTestingOne::class,
  28. ServiceProviderForTestingTwo::class,
  29. ];
  30. $this->assertEquals($expected, $toPublish, 'Publishable service providers do not return expected set of providers.');
  31. }
  32. public function testPublishableGroups()
  33. {
  34. $toPublish = ServiceProvider::publishableGroups();
  35. $this->assertEquals(['some_tag', 'tag_one', 'tag_two'], $toPublish, 'Publishable groups do not return expected set of groups.');
  36. }
  37. public function testSimpleAssetsArePublishedCorrectly()
  38. {
  39. $toPublish = ServiceProvider::pathsToPublish(ServiceProviderForTestingOne::class);
  40. $this->assertArrayHasKey('source/unmarked/one', $toPublish, 'Service provider does not return expected published path key.');
  41. $this->assertArrayHasKey('source/tagged/one', $toPublish, 'Service provider does not return expected published path key.');
  42. $this->assertEquals(['source/unmarked/one' => 'destination/unmarked/one', 'source/tagged/one' => 'destination/tagged/one', 'source/tagged/multiple' => 'destination/tagged/multiple'], $toPublish, 'Service provider does not return expected set of published paths.');
  43. }
  44. public function testMultipleAssetsArePublishedCorrectly()
  45. {
  46. $toPublish = ServiceProvider::pathsToPublish(ServiceProviderForTestingTwo::class);
  47. $this->assertArrayHasKey('source/unmarked/two/a', $toPublish, 'Service provider does not return expected published path key.');
  48. $this->assertArrayHasKey('source/unmarked/two/b', $toPublish, 'Service provider does not return expected published path key.');
  49. $this->assertArrayHasKey('source/unmarked/two/c', $toPublish, 'Service provider does not return expected published path key.');
  50. $this->assertArrayHasKey('source/tagged/two/a', $toPublish, 'Service provider does not return expected published path key.');
  51. $this->assertArrayHasKey('source/tagged/two/b', $toPublish, 'Service provider does not return expected published path key.');
  52. $expected = [
  53. 'source/unmarked/two/a' => 'destination/unmarked/two/a',
  54. 'source/unmarked/two/b' => 'destination/unmarked/two/b',
  55. 'source/unmarked/two/c' => 'destination/tagged/two/a',
  56. 'source/tagged/two/a' => 'destination/tagged/two/a',
  57. 'source/tagged/two/b' => 'destination/tagged/two/b',
  58. ];
  59. $this->assertEquals($expected, $toPublish, 'Service provider does not return expected set of published paths.');
  60. }
  61. public function testSimpleTaggedAssetsArePublishedCorrectly()
  62. {
  63. $toPublish = ServiceProvider::pathsToPublish(ServiceProviderForTestingOne::class, 'some_tag');
  64. $this->assertArrayNotHasKey('source/tagged/two/a', $toPublish, 'Service provider does return unexpected tagged path key.');
  65. $this->assertArrayNotHasKey('source/tagged/two/b', $toPublish, 'Service provider does return unexpected tagged path key.');
  66. $this->assertArrayHasKey('source/tagged/one', $toPublish, 'Service provider does not return expected tagged path key.');
  67. $this->assertEquals(['source/tagged/one' => 'destination/tagged/one'], $toPublish, 'Service provider does not return expected set of published tagged paths.');
  68. }
  69. public function testMultipleTaggedAssetsArePublishedCorrectly()
  70. {
  71. $toPublish = ServiceProvider::pathsToPublish(ServiceProviderForTestingTwo::class, 'some_tag');
  72. $this->assertArrayHasKey('source/tagged/two/a', $toPublish, 'Service provider does not return expected tagged path key.');
  73. $this->assertArrayHasKey('source/tagged/two/b', $toPublish, 'Service provider does not return expected tagged path key.');
  74. $this->assertArrayNotHasKey('source/tagged/one', $toPublish, 'Service provider does return unexpected tagged path key.');
  75. $this->assertArrayNotHasKey('source/unmarked/two/c', $toPublish, 'Service provider does return unexpected tagged path key.');
  76. $expected = [
  77. 'source/tagged/two/a' => 'destination/tagged/two/a',
  78. 'source/tagged/two/b' => 'destination/tagged/two/b',
  79. ];
  80. $this->assertEquals($expected, $toPublish, 'Service provider does not return expected set of published tagged paths.');
  81. }
  82. public function testMultipleTaggedAssetsAreMergedCorrectly()
  83. {
  84. $toPublish = ServiceProvider::pathsToPublish(null, 'some_tag');
  85. $this->assertArrayHasKey('source/tagged/two/a', $toPublish, 'Service provider does not return expected tagged path key.');
  86. $this->assertArrayHasKey('source/tagged/two/b', $toPublish, 'Service provider does not return expected tagged path key.');
  87. $this->assertArrayHasKey('source/tagged/one', $toPublish, 'Service provider does not return expected tagged path key.');
  88. $this->assertArrayNotHasKey('source/unmarked/two/c', $toPublish, 'Service provider does return unexpected tagged path key.');
  89. $expected = [
  90. 'source/tagged/one' => 'destination/tagged/one',
  91. 'source/tagged/two/a' => 'destination/tagged/two/a',
  92. 'source/tagged/two/b' => 'destination/tagged/two/b',
  93. ];
  94. $this->assertEquals($expected, $toPublish, 'Service provider does not return expected set of published tagged paths.');
  95. }
  96. }
  97. class ServiceProviderForTestingOne extends ServiceProvider
  98. {
  99. public function register()
  100. {
  101. //
  102. }
  103. public function boot()
  104. {
  105. $this->publishes(['source/unmarked/one' => 'destination/unmarked/one']);
  106. $this->publishes(['source/tagged/one' => 'destination/tagged/one'], 'some_tag');
  107. $this->publishes(['source/tagged/multiple' => 'destination/tagged/multiple'], ['tag_one', 'tag_two']);
  108. }
  109. }
  110. class ServiceProviderForTestingTwo extends ServiceProvider
  111. {
  112. public function register()
  113. {
  114. //
  115. }
  116. public function boot()
  117. {
  118. $this->publishes(['source/unmarked/two/a' => 'destination/unmarked/two/a']);
  119. $this->publishes(['source/unmarked/two/b' => 'destination/unmarked/two/b']);
  120. $this->publishes(['source/unmarked/two/c' => 'destination/tagged/two/a']);
  121. $this->publishes(['source/tagged/two/a' => 'destination/tagged/two/a'], 'some_tag');
  122. $this->publishes(['source/tagged/two/b' => 'destination/tagged/two/b'], 'some_tag');
  123. }
  124. }