ArchiveCommandTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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\Command;
  12. use Composer\Composer;
  13. use Composer\Config;
  14. use Composer\Factory;
  15. use Composer\Test\TestCase;
  16. use Symfony\Component\Console\Input\ArrayInput;
  17. class ArchiveCommandTest extends TestCase
  18. {
  19. public function testUsesConfigFromComposerObject()
  20. {
  21. $input = new ArrayInput(array());
  22. $output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
  23. ->getMock();
  24. $ed = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
  25. ->disableOriginalConstructor()->getMock();
  26. $composer = new Composer;
  27. $config = new Config;
  28. $config->merge(array('config' => array('archive-format' => 'zip')));
  29. $composer->setConfig($config);
  30. $manager = $this->getMockBuilder('Composer\Package\Archiver\ArchiveManager')
  31. ->disableOriginalConstructor()->getMock();
  32. $package = $this->getMockBuilder('Composer\Package\RootPackageInterface')
  33. ->getMock();
  34. $manager->expects($this->once())->method('archive')
  35. ->with($package, 'zip', '.', null, false)->willReturn(getcwd());
  36. $composer->setArchiveManager($manager);
  37. $composer->setEventDispatcher($ed);
  38. $composer->setPackage($package);
  39. $command = $this->getMockBuilder('Composer\Command\ArchiveCommand')
  40. ->setMethods(array(
  41. 'mergeApplicationDefinition',
  42. 'bind',
  43. 'getSynopsis',
  44. 'initialize',
  45. 'isInteractive',
  46. 'getComposer',
  47. ))->getMock();
  48. $command->expects($this->atLeastOnce())->method('getComposer')
  49. ->willReturn($composer);
  50. $command->method('isInteractive')->willReturn(false);
  51. $command->run($input, $output);
  52. }
  53. public function testUsesConfigFromFactoryWhenComposerIsNotDefined()
  54. {
  55. $input = new ArrayInput(array());
  56. $output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
  57. ->getMock();
  58. $config = Factory::createConfig();
  59. $command = $this->getMockBuilder('Composer\Command\ArchiveCommand')
  60. ->setMethods(array(
  61. 'mergeApplicationDefinition',
  62. 'bind',
  63. 'getSynopsis',
  64. 'initialize',
  65. 'isInteractive',
  66. 'getComposer',
  67. 'archive',
  68. ))->getMock();
  69. $command->expects($this->once())->method('getComposer')
  70. ->willReturn(null);
  71. $command->expects($this->once())->method('archive')
  72. ->with(
  73. $this->isInstanceOf('Composer\IO\IOInterface'),
  74. $config,
  75. null,
  76. null,
  77. 'tar',
  78. '.',
  79. null,
  80. false,
  81. null
  82. )->willReturn(0);
  83. $command->method('isInteractive')->willReturn(false);
  84. $this->assertEquals(0, $command->run($input, $output));
  85. }
  86. }