Skip to content

Commit 05fcd40

Browse files
authored
MC-36032: ece-patches apply command updates (magento#761)
1 parent 2c17f5b commit 05fcd40

File tree

4 files changed

+36
-79
lines changed

4 files changed

+36
-79
lines changed

src/Patch/Manager.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,21 @@ public function __construct(
5151
/**
5252
* Applies all needed patches.
5353
*
54-
* @param array $qualityPatches
5554
* @throws ShellException
5655
* @throws ConfigException
5756
*/
58-
public function apply(array $qualityPatches = []): void
57+
public function apply(): void
5958
{
60-
$this->logger->notice('Applying patches');
61-
62-
$command = 'php ./vendor/bin/ece-patches apply';
63-
64-
if ($qualityPatches) {
65-
$command .= sprintf(" '%s'", implode("' '", $qualityPatches));
66-
}
67-
6859
if ($this->globalSection->get(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)) {
69-
$command .= ' --git-installation 1';
60+
$this->logger->info('Git-based installation. Skipping patches applying');
61+
62+
return;
7063
}
7164

72-
$command .= ' --no-interaction';
65+
$this->logger->notice('Applying patches');
7366

7467
try {
75-
$this->shell->execute($command);
68+
$this->shell->execute('php ./vendor/bin/ece-patches apply --no-interaction');
7669
} catch (ShellException $exception) {
7770
$this->logger->error($exception->getMessage());
7871
throw $exception;

src/Step/Build/ApplyPatches.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\MagentoCloud\App\Error;
1111
use Magento\MagentoCloud\Config\ConfigException;
12-
use Magento\MagentoCloud\Config\Stage\BuildInterface;
1312
use Magento\MagentoCloud\Patch\Manager;
1413
use Magento\MagentoCloud\Shell\ShellException;
1514
use Magento\MagentoCloud\Step\StepException;
@@ -25,21 +24,12 @@ class ApplyPatches implements StepInterface
2524
*/
2625
private $manager;
2726

28-
/**
29-
* @var BuildInterface
30-
*/
31-
private $stageConfig;
32-
3327
/**
3428
* @param Manager $manager
35-
* @param BuildInterface $stageConfig
3629
*/
37-
public function __construct(
38-
Manager $manager,
39-
BuildInterface $stageConfig
40-
) {
30+
public function __construct(Manager $manager)
31+
{
4132
$this->manager = $manager;
42-
$this->stageConfig = $stageConfig;
4333
}
4434

4535
/**
@@ -48,8 +38,7 @@ public function __construct(
4838
public function execute(): void
4939
{
5040
try {
51-
$qualityPatches = $this->stageConfig->get(BuildInterface::VAR_QUALITY_PATCHES);
52-
$this->manager->apply($qualityPatches);
41+
$this->manager->apply();
5342
} catch (ConfigException $e) {
5443
throw new StepException($e->getMessage(), $e->getCode(), $e);
5544
} catch (ShellException $e) {

src/Test/Unit/Patch/ManagerTest.php

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,34 +59,45 @@ protected function setUp()
5959

6060
/**
6161
* Tests patch applying.
62-
*
63-
* @param bool $deploymentFromGit
64-
* @param string[] $qualityPatches
65-
* @param string $expectedCommand
66-
* @dataProvider applyDataProvider
6762
*/
68-
public function testApply(
69-
bool $deploymentFromGit,
70-
array $qualityPatches,
71-
string $expectedCommand
72-
): void {
63+
public function testApply(): void
64+
{
7365
$this->globalSectionMock->expects($this->once())
7466
->method('get')
7567
->with(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)
76-
->willReturn($deploymentFromGit);
68+
->willReturn(false);
7769

7870
$processMock = $this->getMockForAbstractClass(ProcessInterface::class);
7971
$this->shellMock->expects($this->once())
8072
->method('execute')
81-
->with($expectedCommand)
73+
->with('php ./vendor/bin/ece-patches apply --no-interaction')
8274
->willReturn($processMock);
8375
$this->loggerMock->method('notice')
8476
->withConsecutive(
8577
['Applying patches'],
8678
['End of applying patches']
8779
);
8880

89-
$this->manager->apply($qualityPatches);
81+
$this->manager->apply();
82+
}
83+
84+
/**
85+
* Tests with git-based Magento.
86+
*/
87+
public function testApplyGit(): void
88+
{
89+
$this->globalSectionMock->expects($this->once())
90+
->method('get')
91+
->with(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)
92+
->willReturn(true);
93+
94+
$this->shellMock->expects($this->never())
95+
->method('execute');
96+
$this->loggerMock->expects($this->once())
97+
->method('info')
98+
->with('Git-based installation. Skipping patches applying');
99+
100+
$this->manager->apply();
90101
}
91102

92103
/**
@@ -99,23 +110,7 @@ public function applyDataProvider(): array
99110
'deploymentFromGit' => false,
100111
'qualityPatches' => [],
101112
'expectedCommand' => 'php ./vendor/bin/ece-patches apply --no-interaction'
102-
],
103-
[
104-
'deploymentFromGit' => true,
105-
'qualityPatches' => [],
106-
'expectedCommand' => 'php ./vendor/bin/ece-patches apply --git-installation 1 --no-interaction'
107-
],
108-
[
109-
'deploymentFromGit' => true,
110-
'qualityPatches' => ['MC-11111', 'MC-22222'],
111-
'expectedCommand' =>
112-
'php ./vendor/bin/ece-patches apply \'MC-11111\' \'MC-22222\' --git-installation 1 --no-interaction'
113-
],
114-
[
115-
'deploymentFromGit' => false,
116-
'qualityPatches' => ['MC-32365'],
117-
'expectedCommand' => 'php ./vendor/bin/ece-patches apply \'MC-32365\' --no-interaction'
118-
],
113+
]
119114
];
120115
}
121116

src/Test/Unit/Step/Build/ApplyPatchesTest.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,23 @@ class ApplyPatchesTest extends TestCase
3232
*/
3333
private $managerMock;
3434

35-
/**
36-
* @var BuildInterface|MockObject
37-
*/
38-
private $stageConfigMock;
39-
4035
/**
4136
* @inheritdoc
4237
*/
4338
protected function setUp()
4439
{
4540
$this->managerMock = $this->createMock(Manager::class);
46-
$this->stageConfigMock = $this->getMockForAbstractClass(BuildInterface::class);
4741

48-
$this->step = new ApplyPatches($this->managerMock, $this->stageConfigMock);
42+
$this->step = new ApplyPatches($this->managerMock);
4943
}
5044

5145
/**
5246
* @throws StepException
5347
*/
5448
public function testExecute(): void
5549
{
56-
$qualityPatches = ['MC-3456', 'MC-45678'];
57-
$this->stageConfigMock->expects($this->once())
58-
->method('get')
59-
->with(BuildInterface::VAR_QUALITY_PATCHES)
60-
->willReturn($qualityPatches);
6150
$this->managerMock->expects($this->once())
62-
->method('apply')
63-
->with($qualityPatches);
51+
->method('apply');
6452

6553
$this->step->execute();
6654
}
@@ -70,10 +58,6 @@ public function testExecute(): void
7058
*/
7159
public function testExecuteWithConfigException(): void
7260
{
73-
$this->stageConfigMock->expects($this->once())
74-
->method('get')
75-
->with(BuildInterface::VAR_QUALITY_PATCHES)
76-
->willReturn([]);
7761
$this->managerMock->expects($this->once())
7862
->method('apply')
7963
->willThrowException(new ConfigException('config not found', Error::BUILD_CONFIG_NOT_DEFINED));
@@ -90,10 +74,6 @@ public function testExecuteWithConfigException(): void
9074
*/
9175
public function testExecuteWithShellException(): void
9276
{
93-
$this->stageConfigMock->expects($this->once())
94-
->method('get')
95-
->with(BuildInterface::VAR_QUALITY_PATCHES)
96-
->willReturn([]);
9777
$this->managerMock->expects($this->once())
9878
->method('apply')
9979
->willThrowException(new ShellException('command failed'));

0 commit comments

Comments
 (0)