Skip to content

Commit e4bb6c3

Browse files
authored
MCLOUD-6939: Errors occur running magento commands in composer cloud docker installation (#2)
1 parent e3b13ca commit e4bb6c3

File tree

5 files changed

+109
-8
lines changed

5 files changed

+109
-8
lines changed

config/schema.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ variables:
176176
- stage:
177177
global:
178178
SKIP_HTML_MINIFICATION: true
179+
SKIP_COMPOSER_DUMP_AUTOLOAD:
180+
description: Skip running compose dump-autoload command
181+
type: boolean
182+
stages:
183+
- build
184+
default:
185+
build: false
186+
examples:
187+
- stage:
188+
build:
189+
SKIP_COMPOSER_DUMP_AUTOLOAD: true
179190
SCD_ON_DEMAND:
180191
description: Enable generation of static content when requested by a user.
181192
Pre-loading the cache using the post_deploy hook reduces site downtime.

src/Config/Stage/BuildInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ interface BuildInterface extends StageConfigInterface
3030
* Magento quality patches list
3131
*/
3232
public const VAR_QUALITY_PATCHES = 'QUALITY_PATCHES';
33+
34+
/**
35+
* Skip composer dump-autoload
36+
*/
37+
public const VAR_SKIP_COMPOSER_DUMP_AUTOLOAD = 'SKIP_COMPOSER_DUMP_AUTOLOAD';
3338
}

src/Step/Build/ComposerDumpAutoload.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
namespace Magento\MagentoCloud\Step\Build;
99

1010
use Magento\MagentoCloud\App\Error;
11+
use Magento\MagentoCloud\Config\ConfigException;
1112
use Magento\MagentoCloud\Step\StepException;
1213
use Magento\MagentoCloud\Step\StepInterface;
1314
use Magento\MagentoCloud\Shell\ShellException;
1415
use Magento\MagentoCloud\Shell\ShellInterface;
16+
use Magento\MagentoCloud\Config\Stage\BuildInterface;
17+
use Psr\Log\LoggerInterface;
1518

1619
/**
1720
* @inheritdoc
@@ -23,12 +26,25 @@ class ComposerDumpAutoload implements StepInterface
2326
*/
2427
private $shell;
2528

29+
/**
30+
* @var BuildInterface
31+
*/
32+
private $stageConfig;
33+
/**
34+
* @var LoggerInterface
35+
*/
36+
private $logger;
37+
2638
/**
2739
* @param ShellInterface $shell
40+
* @param BuildInterface $stageConfig
41+
* @param LoggerInterface $logger
2842
*/
29-
public function __construct(ShellInterface $shell)
43+
public function __construct(ShellInterface $shell, BuildInterface $stageConfig, LoggerInterface $logger)
3044
{
3145
$this->shell = $shell;
46+
$this->stageConfig = $stageConfig;
47+
$this->logger = $logger;
3248
}
3349

3450
/**
@@ -37,7 +53,17 @@ public function __construct(ShellInterface $shell)
3753
public function execute()
3854
{
3955
try {
56+
if ($this->stageConfig->get(BuildInterface::VAR_SKIP_COMPOSER_DUMP_AUTOLOAD)) {
57+
$this->logger->info(sprintf(
58+
'The composer dump-autoload command was skipped as %s variable is set to true',
59+
BuildInterface::VAR_SKIP_COMPOSER_DUMP_AUTOLOAD
60+
));
61+
62+
return;
63+
}
4064
$this->shell->execute('composer dump-autoload -o --ansi --no-interaction');
65+
} catch (ConfigException $e) {
66+
throw new StepException($e->getMessage(), $e->getCode(), $e);
4167
} catch (ShellException $e) {
4268
throw new StepException($e->getMessage(), Error::BUILD_COMPOSER_DUMP_AUTOLOAD_FAILED, $e);
4369
}

src/Test/Unit/Config/SchemaTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public function testGetDefaultsForBuild(): void
7777
BuildInterface::VAR_SCD_MAX_EXEC_TIME => null,
7878
BuildInterface::VAR_ERROR_REPORT_DIR_NESTING_LEVEL => 1,
7979
BuildInterface::VAR_SCD_USE_BALER => false,
80-
BuildInterface::VAR_QUALITY_PATCHES => []
80+
BuildInterface::VAR_QUALITY_PATCHES => [],
81+
BuildInterface::VAR_SKIP_COMPOSER_DUMP_AUTOLOAD => false,
8182
],
8283
$this->schema->getDefaults(StageConfigInterface::STAGE_BUILD)
8384
);

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

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
namespace Magento\MagentoCloud\Test\Unit\Step\Build;
99

1010
use Magento\MagentoCloud\App\Error;
11+
use Magento\MagentoCloud\Config\ConfigException;
12+
use Magento\MagentoCloud\Config\Stage\BuildInterface;
1113
use Magento\MagentoCloud\Step\Build\ComposerDumpAutoload;
1214
use Magento\MagentoCloud\Shell\ShellException;
1315
use Magento\MagentoCloud\Shell\ShellInterface;
1416
use Magento\MagentoCloud\Step\StepException;
1517
use PHPUnit\Framework\MockObject\MockObject;
1618
use PHPUnit\Framework\TestCase;
19+
use Psr\Log\LoggerInterface;
1720

1821
/**
1922
* @inheritdoc
@@ -28,18 +31,31 @@ class ComposerDumpAutoloadTest extends TestCase
2831
/**
2932
* @var ShellInterface|MockObject
3033
*/
31-
private $shell;
34+
private $shellMock;
35+
36+
/**
37+
* @var BuildInterface|MockObject
38+
*/
39+
private $stageConfigMock;
40+
41+
/**
42+
* @var LoggerInterface|MockObject
43+
*/
44+
private $loggerMock;
3245

3346
/**
3447
* @inheritdoc
3548
*/
3649
protected function setUp(): void
3750
{
38-
$this->shell = $this->getMockBuilder(ShellInterface::class)
39-
->getMockForAbstractClass();
51+
$this->shellMock = $this->getMockForAbstractClass(ShellInterface::class);
52+
$this->stageConfigMock = $this->getMockForAbstractClass(BuildInterface::class);
53+
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
4054

4155
$this->step = new ComposerDumpAutoload(
42-
$this->shell
56+
$this->shellMock,
57+
$this->stageConfigMock,
58+
$this->loggerMock
4359
);
4460
}
4561

@@ -48,13 +64,37 @@ protected function setUp(): void
4864
*/
4965
public function testExecute(): void
5066
{
51-
$this->shell->expects($this->once())
67+
$this->stageConfigMock->expects($this->once())
68+
->method('get')
69+
->with(BuildInterface::VAR_SKIP_COMPOSER_DUMP_AUTOLOAD)
70+
->willReturn(false);
71+
$this->shellMock->expects($this->once())
5272
->method('execute')
5373
->with('composer dump-autoload -o --ansi --no-interaction');
5474

5575
$this->step->execute();
5676
}
5777

78+
/**
79+
* @throws StepException
80+
*/
81+
public function testExecuteDumpSkipped(): void
82+
{
83+
$this->stageConfigMock->expects($this->once())
84+
->method('get')
85+
->with(BuildInterface::VAR_SKIP_COMPOSER_DUMP_AUTOLOAD)
86+
->willReturn(true);
87+
$this->loggerMock->expects($this->once())
88+
->method('info')
89+
->with(
90+
'The composer dump-autoload command was skipped as SKIP_COMPOSER_DUMP_AUTOLOAD variable is set to true'
91+
);
92+
$this->shellMock->expects($this->never())
93+
->method('execute');
94+
95+
$this->step->execute();
96+
}
97+
5898
/**
5999
* @throws StepException
60100
*/
@@ -64,11 +104,29 @@ public function testExecuteWithException(): void
64104
$this->expectExceptionMessage('something went wrong');
65105
$this->expectExceptionCode(Error::BUILD_COMPOSER_DUMP_AUTOLOAD_FAILED);
66106

67-
$this->shell->expects($this->once())
107+
$this->shellMock->expects($this->once())
68108
->method('execute')
69109
->with('composer dump-autoload -o --ansi --no-interaction')
70110
->willThrowException(new ShellException('something went wrong'));
71111

72112
$this->step->execute();
73113
}
114+
115+
/**
116+
* @throws StepException
117+
*/
118+
public function testExecuteWithConfigException(): void
119+
{
120+
$this->expectException(StepException::class);
121+
$this->expectExceptionMessage('something went wrong');
122+
$this->expectExceptionCode(10);
123+
124+
$this->stageConfigMock->expects($this->once())
125+
->method('get')
126+
->willThrowException(new ConfigException('something went wrong', 10));
127+
$this->shellMock->expects($this->never())
128+
->method('execute');
129+
130+
$this->step->execute();
131+
}
74132
}

0 commit comments

Comments
 (0)