JobComponentUninstallTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Copyright © 2013-2017 Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Update\Queue;
  7. class JobComponentUninstallTest extends \PHPUnit_Framework_TestCase
  8. {
  9. /**
  10. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Update\Status
  11. */
  12. private $status;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Composer\MagentoComposerApplication
  15. */
  16. private $composerApp;
  17. public function setUp()
  18. {
  19. $this->status = $this->getMock('Magento\Update\Status', [], [], '', false);
  20. $this->composerApp = $this->getMock('Magento\Composer\MagentoComposerApplication', [], [], '', false);
  21. }
  22. public function testExecute()
  23. {
  24. $jobComponentUninstall = new \Magento\Update\Queue\JobComponentUninstall(
  25. 'component:uninstall',
  26. ['components' => [['name' => 'vendor/package']]],
  27. $this->composerApp,
  28. $this->status
  29. );
  30. $this->status->expects($this->atLeastOnce())->method('add');
  31. $this->composerApp->expects($this->at(0))
  32. ->method('runComposerCommand')
  33. ->with(['command' => 'remove', 'packages' => ['vendor/package'], '--no-update' => true])
  34. ->willReturn('Success');
  35. $this->composerApp->expects($this->at(1))
  36. ->method('runComposerCommand')
  37. ->with(['command' => 'update'])
  38. ->willReturn('Success');
  39. $jobComponentUninstall->execute();
  40. }
  41. /**
  42. * @expectedException \RuntimeException
  43. * @expectedExceptionMessage Cannot find component to uninstall
  44. */
  45. public function testExecuteNoComponent()
  46. {
  47. $jobComponentUninstall = new \Magento\Update\Queue\JobComponentUninstall(
  48. 'component:uninstall',
  49. [],
  50. $this->composerApp,
  51. $this->status
  52. );
  53. $this->composerApp->expects($this->never())->method('runComposerCommand');
  54. $jobComponentUninstall->execute();
  55. }
  56. /**
  57. * @expectedException \RuntimeException
  58. * @expectedExceptionMessage Exception
  59. */
  60. public function testExecuteException()
  61. {
  62. $jobComponentUninstall = new \Magento\Update\Queue\JobComponentUninstall(
  63. 'component:uninstall',
  64. ['components' => [['name' => 'vendor/package']]],
  65. $this->composerApp,
  66. $this->status
  67. );
  68. $this->status->expects($this->atLeastOnce())->method('add');
  69. $this->composerApp->expects($this->at(0))
  70. ->method('runComposerCommand')
  71. ->with(['command' => 'remove', 'packages' => ['vendor/package'], '--no-update' => true])
  72. ->willReturn('Success');
  73. $this->composerApp->expects($this->at(1))
  74. ->method('runComposerCommand')
  75. ->with(['command' => 'update'])
  76. ->will($this->throwException(new \Exception('Exception')));
  77. $this->status->expects($this->once())->method('setUpdateError')->with(true);
  78. $jobComponentUninstall->execute();
  79. }
  80. }