PearPackageExtractorTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. class PearPackageExtractorTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testShouldExtractPackage_1_0()
  16. {
  17. $state = libxml_disable_entity_loader(true);
  18. $extractor = $this->getMockForAbstractClass('Composer\Downloader\PearPackageExtractor', array(), '', false);
  19. $method = new \ReflectionMethod($extractor, 'buildCopyActions');
  20. $method->setAccessible(true);
  21. $fileActions = $method->invoke($extractor, __DIR__ . '/Fixtures/Package_v1.0', array('php' => '/'), array());
  22. libxml_disable_entity_loader($state);
  23. $expectedFileActions = array(
  24. 'Gtk.php' => array(
  25. 'from' => 'PEAR_Frontend_Gtk-0.4.0/Gtk.php',
  26. 'to' => 'PEAR/Frontend/Gtk.php',
  27. 'role' => 'php',
  28. 'tasks' => array(),
  29. ),
  30. 'Gtk/Config.php' => array(
  31. 'from' => 'PEAR_Frontend_Gtk-0.4.0/Gtk/Config.php',
  32. 'to' => 'PEAR/Frontend/Gtk/Config.php',
  33. 'role' => 'php',
  34. 'tasks' => array(),
  35. ),
  36. 'Gtk/xpm/black_close_icon.xpm' => array(
  37. 'from' => 'PEAR_Frontend_Gtk-0.4.0/Gtk/xpm/black_close_icon.xpm',
  38. 'to' => 'PEAR/Frontend/Gtk/xpm/black_close_icon.xpm',
  39. 'role' => 'php',
  40. 'tasks' => array(),
  41. )
  42. );
  43. $this->assertSame($expectedFileActions, $fileActions);
  44. }
  45. public function testShouldExtractPackage_2_0()
  46. {
  47. $state = libxml_disable_entity_loader(true);
  48. $extractor = $this->getMockForAbstractClass('Composer\Downloader\PearPackageExtractor', array(), '', false);
  49. $method = new \ReflectionMethod($extractor, 'buildCopyActions');
  50. $method->setAccessible(true);
  51. $fileActions = $method->invoke($extractor, __DIR__ . '/Fixtures/Package_v2.0', array('php' => '/'), array());
  52. libxml_disable_entity_loader($state);
  53. $expectedFileActions = array(
  54. 'URL.php' => array(
  55. 'from' => 'Net_URL-1.0.15/URL.php',
  56. 'to' => 'Net/URL.php',
  57. 'role' => 'php',
  58. 'tasks' => array(),
  59. )
  60. );
  61. $this->assertSame($expectedFileActions, $fileActions);
  62. }
  63. public function testShouldExtractPackage_2_1()
  64. {
  65. $state = libxml_disable_entity_loader(true);
  66. $extractor = $this->getMockForAbstractClass('Composer\Downloader\PearPackageExtractor', array(), '', false);
  67. $method = new \ReflectionMethod($extractor, 'buildCopyActions');
  68. $method->setAccessible(true);
  69. $fileActions = $method->invoke($extractor, __DIR__ . '/Fixtures/Package_v2.1', array('php' => '/', 'script' => '/bin'), array());
  70. libxml_disable_entity_loader($state);
  71. $expectedFileActions = array(
  72. 'php/Zend/Authentication/Storage/StorageInterface.php' => array(
  73. 'from' => 'Zend_Authentication-2.0.0beta4/php/Zend/Authentication/Storage/StorageInterface.php',
  74. 'to' => '/php/Zend/Authentication/Storage/StorageInterface.php',
  75. 'role' => 'php',
  76. 'tasks' => array(),
  77. ),
  78. 'php/Zend/Authentication/Result.php' => array(
  79. 'from' => 'Zend_Authentication-2.0.0beta4/php/Zend/Authentication/Result.php',
  80. 'to' => '/php/Zend/Authentication/Result.php',
  81. 'role' => 'php',
  82. 'tasks' => array(),
  83. ),
  84. 'php/Test.php' => array (
  85. 'from' => 'Zend_Authentication-2.0.0beta4/php/Test.php',
  86. 'to' => '/php/Test.php',
  87. 'role' => 'script',
  88. 'tasks' => array (
  89. array (
  90. 'from' => '@version@',
  91. 'to' => 'version',
  92. )
  93. )
  94. ),
  95. 'renamedFile.php' => array(
  96. 'from' => 'Zend_Authentication-2.0.0beta4/renamedFile.php',
  97. 'to' => 'correctFile.php',
  98. 'role' => 'php',
  99. 'tasks' => array(),
  100. ),
  101. );
  102. $this->assertSame($expectedFileActions, $fileActions);
  103. }
  104. public function testShouldPerformReplacements()
  105. {
  106. $from = tempnam(sys_get_temp_dir(), 'pear-extract');
  107. $to = $from.'-to';
  108. $original = 'replaced: @placeholder@; not replaced: @another@; replaced again: @placeholder@';
  109. $expected = 'replaced: value; not replaced: @another@; replaced again: value';
  110. file_put_contents($from, $original);
  111. $extractor = new PearPackageExtractor($from);
  112. $method = new \ReflectionMethod($extractor, 'copyFile');
  113. $method->setAccessible(true);
  114. $method->invoke($extractor, $from, $to, array(array('from' => '@placeholder@', 'to' => 'variable')), array('variable' => 'value'));
  115. $result = file_get_contents($to);
  116. unlink($to);
  117. unlink($from);
  118. $this->assertEquals($expected, $result);
  119. }
  120. }