You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IgnoreManagerTest.php 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /*
  3. * This file is part of the Fxp Composer Asset Plugin package.
  4. *
  5. * (c) François Pluchino <francois.pluchino@gmail.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 Fxp\Composer\AssetPlugin\Tests\Installer;
  11. use Composer\Util\Filesystem;
  12. use Fxp\Composer\AssetPlugin\Installer\IgnoreManager;
  13. /**
  14. * Tests of manager of ignore patterns.
  15. *
  16. * @author Martin Hasoň <martin.hason@gmail.com>
  17. */
  18. class IgnoreManagerTest extends \PHPUnit_Framework_TestCase
  19. {
  20. /**
  21. * @var string
  22. */
  23. private $target;
  24. protected function setUp()
  25. {
  26. $fs = new Filesystem();
  27. $this->target = sys_get_temp_dir().'/composer-foo';
  28. foreach ($this->getFixtureFiles() as $filename) {
  29. $path = $this->target.'/'.$filename;
  30. $fs->ensureDirectoryExists(dirname($path));
  31. @file_put_contents($path, '');
  32. }
  33. }
  34. protected function tearDown()
  35. {
  36. $fs = new Filesystem();
  37. $fs->remove($this->target);
  38. }
  39. /**
  40. * @return array
  41. */
  42. protected function getFixtureFiles()
  43. {
  44. return array(
  45. '.hidden',
  46. 'CHANGELOG',
  47. 'README',
  48. 'lib/autoload.php',
  49. 'src/.hidden',
  50. 'src/doc',
  51. 'src/foo/.hidden',
  52. 'src/foo/empty.html',
  53. 'src/foo/empty.md',
  54. 'src/foo/empty.txt',
  55. 'src/foo/small.txt',
  56. 'src/lib/empty.txt',
  57. 'src/lib/foo/empty.txt',
  58. 'src/lib/foo/small.txt',
  59. 'src/tests/empty.html',
  60. 'tests/bootstrap.php',
  61. );
  62. }
  63. public function testDeleteIgnoredFiles()
  64. {
  65. $ignorer = new IgnoreManager($this->target);
  66. $ignorer->addPattern('.*');
  67. $ignorer->addPattern('**/.*');
  68. $ignorer->addPattern('README');
  69. $ignorer->addPattern('**/*.md');
  70. $ignorer->addPattern('lib');
  71. $ignorer->addPattern('tests');
  72. $ignorer->addPattern('**/doc');
  73. $ignorer->addPattern('src/foo/*.txt');
  74. $ignorer->addPattern('!src/foo/small.txt');
  75. $ignorer->cleanup();
  76. $this->assertFileNotExists($this->target.'/.hidden');
  77. $this->assertFileExists($this->target.'/CHANGELOG');
  78. $this->assertFileNotExists($this->target.'/README');
  79. $this->assertFileNotExists($this->target.'/lib/autoload.php');
  80. $this->assertFileNotExists($this->target.'/lib');
  81. $this->assertFileNotExists($this->target.'/src/.hidden');
  82. $this->assertFileNotExists($this->target.'/src/doc');
  83. $this->assertFileExists($this->target.'/src');
  84. $this->assertFileNotExists($this->target.'/src/foo/.hidden');
  85. $this->assertFileExists($this->target.'/src/foo/empty.html');
  86. $this->assertFileNotExists($this->target.'/src/foo/empty.md');
  87. $this->assertFileNotExists($this->target.'/src/foo/empty.txt');
  88. $this->assertFileExists($this->target.'/src/foo/small.txt');
  89. $this->assertFileExists($this->target.'/src/foo');
  90. $this->assertFileExists($this->target.'/src/lib/empty.txt');
  91. $this->assertFileExists($this->target.'/src/lib');
  92. $this->assertFileExists($this->target.'/src/lib/foo/empty.txt');
  93. $this->assertFileExists($this->target.'/src/lib/foo/small.txt');
  94. $this->assertFileExists($this->target.'/src/lib/foo');
  95. $this->assertFileExists($this->target.'/src/tests/empty.html');
  96. $this->assertFileExists($this->target.'/src/tests');
  97. $this->assertFileNotExists($this->target.'/tests/bootstrap.php');
  98. $this->assertFileNotExists($this->target.'/tests');
  99. }
  100. public function testDeleteIgnoredFilesWithDisabledManager()
  101. {
  102. $ignorer = new IgnoreManager($this->target);
  103. $ignorer->setEnabled(false);
  104. $ignorer->addPattern('.*');
  105. $ignorer->addPattern('**/.*');
  106. $ignorer->addPattern('README');
  107. $ignorer->addPattern('**/*.md');
  108. $ignorer->addPattern('lib');
  109. $ignorer->addPattern('tests');
  110. $ignorer->addPattern('**/doc');
  111. $ignorer->addPattern('src/foo/*.txt');
  112. $ignorer->addPattern('!src/foo/small.txt');
  113. $ignorer->cleanup();
  114. $this->assertFileExists($this->target.'/.hidden');
  115. $this->assertFileExists($this->target.'/CHANGELOG');
  116. $this->assertFileExists($this->target.'/README');
  117. $this->assertFileExists($this->target.'/lib/autoload.php');
  118. $this->assertFileExists($this->target.'/lib');
  119. $this->assertFileExists($this->target.'/src/.hidden');
  120. $this->assertFileExists($this->target.'/src/doc');
  121. $this->assertFileExists($this->target.'/src');
  122. $this->assertFileExists($this->target.'/src/foo/.hidden');
  123. $this->assertFileExists($this->target.'/src/foo/empty.html');
  124. $this->assertFileExists($this->target.'/src/foo/empty.md');
  125. $this->assertFileExists($this->target.'/src/foo/empty.txt');
  126. $this->assertFileExists($this->target.'/src/foo/small.txt');
  127. $this->assertFileExists($this->target.'/src/foo');
  128. $this->assertFileExists($this->target.'/src/lib/empty.txt');
  129. $this->assertFileExists($this->target.'/src/lib');
  130. $this->assertFileExists($this->target.'/src/lib/foo/empty.txt');
  131. $this->assertFileExists($this->target.'/src/lib/foo/small.txt');
  132. $this->assertFileExists($this->target.'/src/lib/foo');
  133. $this->assertFileExists($this->target.'/src/tests/empty.html');
  134. $this->assertFileExists($this->target.'/src/tests');
  135. $this->assertFileExists($this->target.'/tests/bootstrap.php');
  136. $this->assertFileExists($this->target.'/tests');
  137. }
  138. public function testIgnoreAllFilesExceptAFew()
  139. {
  140. $ignorer = new IgnoreManager($this->target);
  141. $ignorer->addPattern('*');
  142. $ignorer->addPattern('**/.*');
  143. $ignorer->addPattern('!README');
  144. $ignorer->addPattern('!lib/*');
  145. $ignorer->addPattern('!tests');
  146. $ignorer->cleanup();
  147. $this->assertFileNotExists($this->target.'/.hidden');
  148. $this->assertFileNotExists($this->target.'/CHANGELOG');
  149. $this->assertFileExists($this->target.'/README');
  150. $this->assertFileExists($this->target.'/lib/autoload.php');
  151. $this->assertFileExists($this->target.'/lib');
  152. $this->assertFileNotExists($this->target.'/src/.hidden');
  153. $this->assertFileNotExists($this->target.'/src/doc');
  154. $this->assertFileNotExists($this->target.'/src');
  155. $this->assertFileNotExists($this->target.'/src/foo/.hidden');
  156. $this->assertFileNotExists($this->target.'/src/foo/empty.html');
  157. $this->assertFileNotExists($this->target.'/src/foo/empty.md');
  158. $this->assertFileNotExists($this->target.'/src/foo/empty.txt');
  159. $this->assertFileNotExists($this->target.'/src/foo/small.txt');
  160. $this->assertFileNotExists($this->target.'/src/foo');
  161. $this->assertFileNotExists($this->target.'/src/lib/empty.txt');
  162. $this->assertFileNotExists($this->target.'/src/lib');
  163. $this->assertFileNotExists($this->target.'/src/lib/foo/empty.txt');
  164. $this->assertFileNotExists($this->target.'/src/lib/foo/small.txt');
  165. $this->assertFileNotExists($this->target.'/src/lib/foo');
  166. $this->assertFileNotExists($this->target.'/src/tests/empty.html');
  167. $this->assertFileNotExists($this->target.'/src/tests');
  168. $this->assertFileExists($this->target.'/tests/bootstrap.php');
  169. $this->assertFileExists($this->target.'/tests');
  170. }
  171. }