JobUpdateTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 JobUpdateTest 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. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Update\Queue
  19. */
  20. private $queue;
  21. public function setUp()
  22. {
  23. $this->status = $this->getMock('Magento\Update\Status', [], [], '', false);
  24. $this->composerApp = $this->getMock('Magento\Composer\MagentoComposerApplication', [], [], '', false);
  25. $this->queue = $this->getMock('Magento\Update\Queue', [], [], '', false);
  26. }
  27. public function testExecute()
  28. {
  29. $jobUpdate = new \Magento\Update\Queue\JobUpdate(
  30. 'setup:upgrade',
  31. ['components' => [['name' => 'vendor/package', 'version' => '1.0']]],
  32. $this->queue,
  33. $this->composerApp,
  34. $this->status
  35. );
  36. $this->status->expects($this->atLeastOnce())->method('add');
  37. $this->composerApp->expects($this->at(0))
  38. ->method('runComposerCommand')
  39. ->with(['command' => 'require', 'packages' => ['vendor/package 1.0'], '--no-update' => true])
  40. ->willReturn('Success');
  41. $this->composerApp->expects($this->at(1))
  42. ->method('runComposerCommand')
  43. ->with(['command' => 'update'])
  44. ->willReturn('Success');
  45. $this->queue->expects($this->once())->method('addJobs')->with([['name' => 'setup:upgrade', 'params' => []]]);
  46. $jobUpdate->execute();
  47. }
  48. /**
  49. * @expectedException \RuntimeException
  50. * @expectedExceptionMessage Cannot find component to update
  51. */
  52. public function testExecuteNoRequire()
  53. {
  54. $jobUpdate = new \Magento\Update\Queue\JobUpdate(
  55. 'setup:upgrade',
  56. [],
  57. $this->queue,
  58. $this->composerApp,
  59. $this->status
  60. );
  61. $this->composerApp->expects($this->never())->method('runComposerCommand');
  62. $this->queue->expects($this->never())->method('addJobs');
  63. $jobUpdate->execute();
  64. }
  65. /**
  66. * @expectedException \RuntimeException
  67. * @expectedExceptionMessage Exception
  68. */
  69. public function testExecuteException()
  70. {
  71. $jobUpdate = new \Magento\Update\Queue\JobUpdate(
  72. 'setup:upgrade',
  73. ['components' => [['name' => 'vendor/package', 'version' => '1.0']]],
  74. $this->queue,
  75. $this->composerApp,
  76. $this->status
  77. );
  78. $this->status->expects($this->atLeastOnce())->method('add');
  79. $this->composerApp->expects($this->at(0))
  80. ->method('runComposerCommand')
  81. ->with(['command' => 'require', 'packages' => ['vendor/package 1.0'], '--no-update' => true])
  82. ->willReturn('Success');
  83. $this->composerApp->expects($this->at(1))
  84. ->method('runComposerCommand')
  85. ->with(['command' => 'update'])
  86. ->will($this->throwException(new \Exception('Exception')));
  87. $this->status->expects($this->once())->method('setUpdateError')->with(true);
  88. $jobUpdate->execute();
  89. }
  90. }