-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from magento-commerce/develop
MCLOUD-11293: Release ECE-Tools 2002.1.16
- Loading branch information
Showing
12 changed files
with
295 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MagentoCloud\Step\Build; | ||
|
||
use Magento\MagentoCloud\App\Error; | ||
use Magento\MagentoCloud\Config\ConfigException; | ||
use Magento\MagentoCloud\Config\GlobalSection; | ||
use Magento\MagentoCloud\Config\StageConfigInterface; | ||
use Magento\MagentoCloud\Shell\MagentoShell; | ||
use Magento\MagentoCloud\Shell\ShellException; | ||
use Magento\MagentoCloud\Shell\ShellFactory; | ||
use Magento\MagentoCloud\Step\StepException; | ||
use Magento\MagentoCloud\Step\StepInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Runs a command to generate a module for webhooks and enables this module in case when | ||
* it is enabled in configuration | ||
*/ | ||
class EnableWebhooks implements StepInterface | ||
{ | ||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var MagentoShell | ||
*/ | ||
private $magentoShell; | ||
|
||
/** | ||
* @var GlobalSection | ||
*/ | ||
private $globalConfig; | ||
|
||
/** | ||
* @param LoggerInterface $logger | ||
* @param ShellFactory $shellFactory | ||
* @param GlobalSection $globalConfig | ||
*/ | ||
public function __construct( | ||
LoggerInterface $logger, | ||
ShellFactory $shellFactory, | ||
GlobalSection $globalConfig | ||
) { | ||
$this->logger = $logger; | ||
$this->magentoShell = $shellFactory->createMagento(); | ||
$this->globalConfig = $globalConfig; | ||
} | ||
|
||
/** | ||
* Generates and enables a module for Commerce webhooks | ||
* if @see StageConfigInterface::VAR_ENABLE_WEBHOOKS set to true | ||
* | ||
* {@inheritDoc} | ||
*/ | ||
public function execute() | ||
{ | ||
try { | ||
if (!$this->globalConfig->get(StageConfigInterface::VAR_ENABLE_WEBHOOKS)) { | ||
return; | ||
} | ||
} catch (ConfigException $e) { | ||
throw new StepException($e->getMessage(), $e->getCode(), $e); | ||
} | ||
|
||
try { | ||
$this->logger->notice('Generating module for Commerce webhooks'); | ||
$this->magentoShell->execute('webhooks:generate:module'); | ||
} catch (ShellException $e) { | ||
$this->logger->error( | ||
'Failed to generate the AdobeCommerceWebhookPlugins module. ' . | ||
'Refer to the Commerce webhooks documentation to determine if all ' . | ||
'required modules have been installed. ' . | ||
'Error: ' . $e->getMessage() | ||
); | ||
throw new StepException($e->getMessage(), Error::GLOBAL_WEBHOOKS_MODULE_GENERATE_FAILED, $e); | ||
} | ||
|
||
try { | ||
$this->logger->notice('Enabling module for Commerce webhooks'); | ||
$this->magentoShell->execute('module:enable Magento_AdobeCommerceWebhookPlugins'); | ||
} catch (ShellException $e) { | ||
$this->logger->error('Failed to enable module for Commerce webhooks: ' . $e->getMessage()); | ||
throw new StepException($e->getMessage(), Error::GLOBAL_WEBHOOKS_MODULE_ENABLEMENT_FAILED, $e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MagentoCloud\Test\Unit\Step\Build; | ||
|
||
use Magento\MagentoCloud\App\Error; | ||
use Magento\MagentoCloud\Config\GlobalSection; | ||
use Magento\MagentoCloud\Config\StageConfigInterface; | ||
use Magento\MagentoCloud\Shell\MagentoShell; | ||
use Magento\MagentoCloud\Shell\ShellException; | ||
use Magento\MagentoCloud\Shell\ShellFactory; | ||
use Magento\MagentoCloud\Step\Build\EnableWebhooks; | ||
use Magento\MagentoCloud\Step\StepException; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
class EnableWebhooksTest extends TestCase | ||
{ | ||
/** | ||
* @var EnableWebhooks | ||
*/ | ||
private $step; | ||
|
||
/** | ||
* @var LoggerInterface|MockObject | ||
*/ | ||
private $loggerMock; | ||
|
||
/** | ||
* @var MagentoShell|MockObject | ||
*/ | ||
private $magentoShellMock; | ||
|
||
/** | ||
* @var GlobalSection|MockObject | ||
*/ | ||
private $globalConfigMock; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); | ||
$this->magentoShellMock = $this->createMock(MagentoShell::class); | ||
/** @var ShellFactory|MockObject $shellFactoryMock */ | ||
$shellFactoryMock = $this->createMock(ShellFactory::class); | ||
$shellFactoryMock->expects($this->once()) | ||
->method('createMagento') | ||
->willReturn($this->magentoShellMock); | ||
$this->globalConfigMock = $this->createMock(GlobalSection::class); | ||
|
||
$this->step = new EnableWebhooks( | ||
$this->loggerMock, | ||
$shellFactoryMock, | ||
$this->globalConfigMock | ||
); | ||
} | ||
|
||
/** | ||
* @return void | ||
* @throws StepException | ||
*/ | ||
public function testExecuteWebhooksNotEnabled() | ||
{ | ||
$this->globalConfigMock->expects(self::once()) | ||
->method('get') | ||
->with(StageConfigInterface::VAR_ENABLE_WEBHOOKS) | ||
->willReturn(false); | ||
|
||
$this->magentoShellMock->expects(self::never()) | ||
->method('execute'); | ||
$this->loggerMock->expects(self::never()) | ||
->method('notice'); | ||
|
||
$this->step->execute(); | ||
} | ||
|
||
/** | ||
* @return void | ||
* @throws StepException | ||
*/ | ||
public function testExecuteGenerateCommandFailed() | ||
{ | ||
$this->expectException(StepException::class); | ||
$this->expectExceptionMessage('error during module generation'); | ||
$this->expectExceptionCode(Error::GLOBAL_WEBHOOKS_MODULE_GENERATE_FAILED); | ||
|
||
$this->globalConfigMock->expects(self::once()) | ||
->method('get') | ||
->with(StageConfigInterface::VAR_ENABLE_WEBHOOKS) | ||
->willReturn(true); | ||
$this->magentoShellMock->expects(self::once()) | ||
->method('execute') | ||
->with('webhooks:generate:module') | ||
->willThrowException(new ShellException('error during module generation')); | ||
$this->loggerMock->expects(self::once()) | ||
->method('notice'); | ||
$this->loggerMock->expects(self::once()) | ||
->method('error'); | ||
|
||
$this->step->execute(); | ||
} | ||
|
||
/** | ||
* @return void | ||
* @throws StepException | ||
*/ | ||
public function testExecuteEnableModuleCommandFailed() | ||
{ | ||
$this->expectException(StepException::class); | ||
$this->expectExceptionMessage('error during module enablement'); | ||
$this->expectExceptionCode(Error::GLOBAL_WEBHOOKS_MODULE_ENABLEMENT_FAILED); | ||
|
||
$this->globalConfigMock->expects(self::once()) | ||
->method('get') | ||
->with(StageConfigInterface::VAR_ENABLE_WEBHOOKS) | ||
->willReturn(true); | ||
$this->magentoShellMock->expects(self::at(0)) | ||
->method('execute') | ||
->with('webhooks:generate:module'); | ||
$this->magentoShellMock->expects(self::at(1)) | ||
->method('execute') | ||
->with('module:enable Magento_AdobeCommerceWebhookPlugins') | ||
->willThrowException(new ShellException('error during module enablement')); | ||
$this->loggerMock->expects(self::exactly(2)) | ||
->method('notice'); | ||
$this->loggerMock->expects(self::once()) | ||
->method('error'); | ||
|
||
$this->step->execute(); | ||
} | ||
|
||
/** | ||
* @return void | ||
* @throws StepException | ||
*/ | ||
public function testExecuteSuccess() | ||
{ | ||
$this->globalConfigMock->expects(self::once()) | ||
->method('get') | ||
->with(StageConfigInterface::VAR_ENABLE_WEBHOOKS) | ||
->willReturn(true); | ||
$this->magentoShellMock->expects(self::at(0)) | ||
->method('execute') | ||
->with('webhooks:generate:module'); | ||
$this->magentoShellMock->expects(self::at(1)) | ||
->method('execute') | ||
->with('module:enable Magento_AdobeCommerceWebhookPlugins'); | ||
$this->loggerMock->expects(self::exactly(2)) | ||
->method('notice'); | ||
$this->loggerMock->expects(self::never()) | ||
->method('error'); | ||
|
||
$this->step->execute(); | ||
} | ||
} |