PearPackageExtractorTest.php 5.0 KB

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