QueueTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Test\Unit\Process;
  7. use Magento\Deploy\Process\Queue;
  8. use Magento\Deploy\Package\Package;
  9. use Magento\Deploy\Service\DeployPackage;
  10. use Magento\Framework\App\State as AppState;
  11. use Magento\Framework\Locale\ResolverInterface as LocaleResolver;
  12. use Magento\Framework\App\ResourceConnection;
  13. use Psr\Log\LoggerInterface;
  14. use PHPUnit_Framework_MockObject_MockObject as Mock;
  15. /**
  16. * Deployment Queue class unit tests
  17. *
  18. * @see Queue
  19. */
  20. class QueueTest extends \PHPUnit\Framework\TestCase
  21. {
  22. /**
  23. * @var Queue
  24. */
  25. private $queue;
  26. /**
  27. * @var AppState|Mock
  28. */
  29. private $appState;
  30. /**
  31. * @var LocaleResolver|Mock
  32. */
  33. private $localeResolver;
  34. /**
  35. * @var ResourceConnection|Mock
  36. */
  37. private $resourceConnection;
  38. /**
  39. * @var LoggerInterface|Mock
  40. */
  41. private $logger;
  42. /**
  43. * @var DeployPackage|Mock
  44. */
  45. private $deployPackageService;
  46. /**
  47. * @inheritdoc
  48. */
  49. protected function setUp()
  50. {
  51. $this->appState = $this->createMock(AppState::class);
  52. $this->localeResolver = $this->getMockForAbstractClass(
  53. LocaleResolver::class,
  54. ['setLocale'],
  55. '',
  56. false
  57. );
  58. $this->resourceConnection = $this->createMock(ResourceConnection::class);
  59. $this->logger = $this->getMockForAbstractClass(
  60. LoggerInterface::class,
  61. ['notice', 'info'],
  62. '',
  63. false
  64. );
  65. $this->deployPackageService = $this->createPartialMock(DeployPackage::class, ['deploy']);
  66. $this->queue = new Queue(
  67. $this->appState,
  68. $this->localeResolver,
  69. $this->resourceConnection,
  70. $this->logger,
  71. $this->deployPackageService,
  72. [],
  73. 1
  74. );
  75. }
  76. /**
  77. * @see Queue:add()
  78. */
  79. public function testAdd()
  80. {
  81. $package = $this->createMock(Package::class);
  82. $package->expects($this->once())->method('getPath')->willReturn('path');
  83. $this->assertEquals(true, $this->queue->add($package));
  84. $packages = $this->queue->getPackages();
  85. $this->assertEquals(
  86. $package,
  87. isset($packages['path']['package']) ? $packages['path']['package'] : null
  88. );
  89. }
  90. /**
  91. * @see Queue::process()
  92. */
  93. public function testProcess()
  94. {
  95. $package = $this->createMock(Package::class);
  96. $package->expects($this->any())->method('getState')->willReturn(0);
  97. $package->expects($this->exactly(2))->method('getParent')->willReturn(true);
  98. $package->expects($this->any())->method('getArea')->willReturn('area');
  99. $package->expects($this->any())->method('getPath')->willReturn('path');
  100. $package->expects($this->any())->method('getFiles')->willReturn([]);
  101. $this->appState->expects($this->once())->method('emulateAreaCode');
  102. $this->queue->add($package, []);
  103. $this->resourceConnection->expects(self::never())->method('closeConnection');
  104. $this->assertEquals(0, $this->queue->process());
  105. }
  106. }