CompactDeployTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Test\Unit\Strategy;
  7. use Magento\Deploy\Strategy\CompactDeploy;
  8. use Magento\Deploy\Package\Package;
  9. use Magento\Deploy\Package\PackagePool;
  10. use Magento\Deploy\Process\Queue;
  11. use PHPUnit_Framework_MockObject_MockObject as Mock;
  12. /**
  13. * Compact deployment service class implementation unit tests
  14. *
  15. * @see CompactDeploy
  16. */
  17. class CompactDeployTest extends \PHPUnit\Framework\TestCase
  18. {
  19. /**
  20. * @var CompactDeploy
  21. */
  22. private $strategy;
  23. /**
  24. * Mock of package pool object
  25. *
  26. * @var PackagePool|Mock
  27. */
  28. private $packagePool;
  29. /**
  30. * Mock of deployment queue object
  31. *
  32. * @var Queue|Mock
  33. */
  34. private $queue;
  35. /**
  36. * @var array
  37. */
  38. private $options = [];
  39. /**
  40. * @var array
  41. */
  42. private $packages = [];
  43. /**
  44. * @inheritdoc
  45. */
  46. protected function setUp()
  47. {
  48. $this->options = [
  49. 'opt1' => '',
  50. 'opt2' => ''
  51. ];
  52. $virtualPackage = $this->createMock(Package::class);
  53. $virtualPackage->expects($this->exactly(1))
  54. ->method('isVirtual')
  55. ->willReturn(true);
  56. $virtualPackage->expects($this->atLeastOnce())
  57. ->method('getParentPackages')
  58. ->willReturn([]);
  59. $virtualPackage->expects($this->never())
  60. ->method('setParam')
  61. ->willReturn('virtual');
  62. $realPackage = $this->createMock(Package::class);
  63. $realPackage->expects($this->exactly(1))
  64. ->method('isVirtual')
  65. ->willReturn(false);
  66. $realPackage->expects($this->atLeastOnce())
  67. ->method('getParentPackages')
  68. ->willReturn([]);
  69. $realPackage->expects($this->exactly(1))
  70. ->method('setParam')
  71. ->willReturn('virtual');
  72. $this->packages = [
  73. 'virtual' => $virtualPackage,
  74. 'real' => $realPackage
  75. ];
  76. $this->packagePool = $this->createPartialMock(PackagePool::class, ['getPackagesForDeployment']);
  77. $this->packagePool->expects($this->once())
  78. ->method('getPackagesForDeployment')
  79. ->with($this->options)
  80. ->willReturn($this->packages);
  81. $this->queue = $this->createPartialMock(Queue::class, ['add', 'process']);
  82. $this->queue->expects($this->exactly(2))->method('add');
  83. $this->queue->expects($this->exactly(1))->method('process');
  84. $this->strategy = new CompactDeploy(
  85. $this->packagePool,
  86. $this->queue
  87. );
  88. }
  89. /**
  90. * @see CompactDeploy::deploy()
  91. */
  92. public function testDeploy()
  93. {
  94. $this->assertEquals(
  95. $this->packages,
  96. $this->strategy->deploy($this->options)
  97. );
  98. }
  99. }