PearPackageExtractorTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Downloader;
  12. use Composer\Downloader\PearPackageExtractor;
  13. use Composer\Test\TestCase;
  14. class PearPackageExtractorTest extends TestCase
  15. {
  16. public function testShouldExtractPackage_1_0()
  17. {
  18. $state = libxml_disable_entity_loader(true);
  19. $extractor = $this->getMockForAbstractClass('Composer\Downloader\PearPackageExtractor', array(), '', false);
  20. $method = new \ReflectionMethod($extractor, 'buildCopyActions');
  21. $method->setAccessible(true);
  22. $fileActions = $method->invoke($extractor, __DIR__ . '/Fixtures/Package_v1.0', array('php' => '/'), array());
  23. libxml_disable_entity_loader($state);
  24. $expectedFileActions = array(
  25. 'Gtk.php' => array(
  26. 'from' => 'PEAR_Frontend_Gtk-0.4.0/Gtk.php',
  27. 'to' => 'PEAR/Frontend/Gtk.php',
  28. 'role' => 'php',
  29. 'tasks' => array(),
  30. ),
  31. 'Gtk/Config.php' => array(
  32. 'from' => 'PEAR_Frontend_Gtk-0.4.0/Gtk/Config.php',
  33. 'to' => 'PEAR/Frontend/Gtk/Config.php',
  34. 'role' => 'php',
  35. 'tasks' => array(),
  36. ),
  37. 'Gtk/xpm/black_close_icon.xpm' => array(
  38. 'from' => 'PEAR_Frontend_Gtk-0.4.0/Gtk/xpm/black_close_icon.xpm',
  39. 'to' => 'PEAR/Frontend/Gtk/xpm/black_close_icon.xpm',
  40. 'role' => 'php',
  41. 'tasks' => array(),
  42. ),
  43. );
  44. $this->assertSame($expectedFileActions, $fileActions);
  45. }
  46. public function testShouldExtractPackage_2_0()
  47. {
  48. $state = libxml_disable_entity_loader(true);
  49. $extractor = $this->getMockForAbstractClass('Composer\Downloader\PearPackageExtractor', array(), '', false);
  50. $method = new \ReflectionMethod($extractor, 'buildCopyActions');
  51. $method->setAccessible(true);
  52. $fileActions = $method->invoke($extractor, __DIR__ . '/Fixtures/Package_v2.0', array('php' => '/'), array());
  53. libxml_disable_entity_loader($state);
  54. $expectedFileActions = array(
  55. 'URL.php' => array(
  56. 'from' => 'Net_URL-1.0.15/URL.php',
  57. 'to' => 'Net/URL.php',
  58. 'role' => 'php',
  59. 'tasks' => array(),
  60. ),
  61. );
  62. $this->assertSame($expectedFileActions, $fileActions);
  63. }
  64. public function testShouldExtractPackage_2_1()
  65. {
  66. $state = libxml_disable_entity_loader(true);
  67. $extractor = $this->getMockForAbstractClass('Composer\Downloader\PearPackageExtractor', array(), '', false);
  68. $method = new \ReflectionMethod($extractor, 'buildCopyActions');
  69. $method->setAccessible(true);
  70. $fileActions = $method->invoke($extractor, __DIR__ . '/Fixtures/Package_v2.1', array('php' => '/', 'script' => '/bin'), array());
  71. libxml_disable_entity_loader($state);
  72. $expectedFileActions = array(
  73. 'php/Zend/Authentication/Storage/StorageInterface.php' => array(
  74. 'from' => 'Zend_Authentication-2.0.0beta4/php/Zend/Authentication/Storage/StorageInterface.php',
  75. 'to' => '/php/Zend/Authentication/Storage/StorageInterface.php',
  76. 'role' => 'php',
  77. 'tasks' => array(),
  78. ),
  79. 'php/Zend/Authentication/Result.php' => array(
  80. 'from' => 'Zend_Authentication-2.0.0beta4/php/Zend/Authentication/Result.php',
  81. 'to' => '/php/Zend/Authentication/Result.php',
  82. 'role' => 'php',
  83. 'tasks' => array(),
  84. ),
  85. 'php/Test.php' => array(
  86. 'from' => 'Zend_Authentication-2.0.0beta4/php/Test.php',
  87. 'to' => '/php/Test.php',
  88. 'role' => 'script',
  89. 'tasks' => array(
  90. array(
  91. 'from' => '@version@',
  92. 'to' => 'version',
  93. ),
  94. ),
  95. ),
  96. 'renamedFile.php' => array(
  97. 'from' => 'Zend_Authentication-2.0.0beta4/renamedFile.php',
  98. 'to' => 'correctFile.php',
  99. 'role' => 'php',
  100. 'tasks' => array(),
  101. ),
  102. );
  103. $this->assertSame($expectedFileActions, $fileActions);
  104. }
  105. public function testShouldPerformReplacements()
  106. {
  107. $from = tempnam($this->getUniqueTmpDirectory(), 'pear-extract');
  108. $to = $from.'-to';
  109. $original = 'replaced: @placeholder@; not replaced: @another@; replaced again: @placeholder@';
  110. $expected = 'replaced: value; not replaced: @another@; replaced again: value';
  111. file_put_contents($from, $original);
  112. $extractor = new PearPackageExtractor($from);
  113. $method = new \ReflectionMethod($extractor, 'copyFile');
  114. $method->setAccessible(true);
  115. $method->invoke($extractor, $from, $to, array(array('from' => '@placeholder@', 'to' => 'variable')), array('variable' => 'value'));
  116. $result = file_get_contents($to);
  117. unlink($to);
  118. unlink($from);
  119. $this->assertEquals($expected, $result);
  120. }
  121. }