Skip to content

Commit 78596ae

Browse files
authored
MCLOUD-6137: Remove error log at the beginning of deploy phase (magento#736)
1 parent 6e51bb7 commit 78596ae

File tree

2 files changed

+73
-14
lines changed

2 files changed

+73
-14
lines changed

src/Step/Deploy/RemoveDeployFailedFlag.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
namespace Magento\MagentoCloud\Step\Deploy;
99

10+
use Magento\MagentoCloud\Filesystem\Driver\File;
11+
use Magento\MagentoCloud\Filesystem\FileList;
1012
use Magento\MagentoCloud\Filesystem\Flag\Manager;
13+
use Magento\MagentoCloud\Step\StepException;
1114
use Magento\MagentoCloud\Step\StepInterface;
1215

1316
/**
14-
* Removes flags which set during the deploy phase.
17+
* Removes flags and files which could be set during the previous deploy phase.
1518
*/
1619
class RemoveDeployFailedFlag implements StepInterface
1720
{
@@ -20,21 +23,44 @@ class RemoveDeployFailedFlag implements StepInterface
2023
*/
2124
private $manager;
2225

26+
/**
27+
* @var File
28+
*/
29+
private $fileDriver;
30+
31+
/**
32+
* @var FileList
33+
*/
34+
private $fileList;
35+
2336
/**
2437
* @param Manager $manager
38+
* @param File $fileDriver
39+
* @param FileList $fileList
2540
*/
26-
public function __construct(Manager $manager)
27-
{
41+
public function __construct(
42+
Manager $manager,
43+
File $fileDriver,
44+
FileList $fileList
45+
) {
46+
2847
$this->manager = $manager;
48+
$this->fileDriver = $fileDriver;
49+
$this->fileList = $fileList;
2950
}
3051

3152
/**
3253
* @inheritDoc
3354
*/
3455
public function execute()
3556
{
36-
$this->manager->delete(Manager::FLAG_DEPLOY_HOOK_IS_FAILED);
37-
$this->manager->delete(Manager::FLAG_IGNORE_SPLIT_DB);
38-
$this->manager->delete(Manager::FLAG_ENV_FILE_ABSENCE);
57+
try {
58+
$this->manager->delete(Manager::FLAG_DEPLOY_HOOK_IS_FAILED);
59+
$this->manager->delete(Manager::FLAG_IGNORE_SPLIT_DB);
60+
$this->manager->delete(Manager::FLAG_ENV_FILE_ABSENCE);
61+
$this->fileDriver->deleteFile($this->fileList->getCloudErrorLog());
62+
} catch (\Exception $e) {
63+
throw new StepException($e->getMessage(), $e->getCode(), $e);
64+
}
3965
}
4066
}

src/Test/Unit/Step/Deploy/RemoveDeployFailedFlagTest.php

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\MagentoCloud\Test\Unit\Step\Deploy;
99

10+
use Magento\MagentoCloud\Filesystem\Driver\File;
11+
use Magento\MagentoCloud\Filesystem\FileList;
1012
use Magento\MagentoCloud\Filesystem\Flag\Manager;
1113
use Magento\MagentoCloud\Step\Deploy\RemoveDeployFailedFlag;
1214
use Magento\MagentoCloud\Step\StepException;
@@ -26,17 +28,31 @@ class RemoveDeployFailedFlagTest extends TestCase
2628
/**
2729
* @var Manager|MockObject
2830
*/
29-
private $flagManager;
31+
private $flagManagerMock;
32+
33+
/**
34+
* @var File|MockObject
35+
*/
36+
private $fileMock;
37+
38+
/**
39+
* @var FileList|MockObject
40+
*/
41+
private $fileListMock;
3042

3143
/**
3244
* @inheritDoc
3345
*/
3446
protected function setUp(): void
3547
{
36-
$this->flagManager = $this->createMock(Manager::class);
48+
$this->flagManagerMock = $this->createMock(Manager::class);
49+
$this->fileMock = $this->createMock(File::class);
50+
$this->fileListMock = $this->createMock(FileList::class);
3751

3852
$this->step = new RemoveDeployFailedFlag(
39-
$this->flagManager
53+
$this->flagManagerMock,
54+
$this->fileMock,
55+
$this->fileListMock
4056
);
4157
}
4258

@@ -45,13 +61,30 @@ protected function setUp(): void
4561
*/
4662
public function testExecute(): void
4763
{
48-
$this->flagManager->expects($this->at(0))
64+
$filePath = 'file/path/name.txt';
65+
$this->flagManagerMock->expects($this->exactly(3))
4966
->method('delete')
50-
->with(Manager::FLAG_DEPLOY_HOOK_IS_FAILED);
51-
$this->flagManager->expects($this->at(1))
52-
->method('delete')
53-
->with(Manager::FLAG_IGNORE_SPLIT_DB);
67+
->withConsecutive(
68+
[Manager::FLAG_DEPLOY_HOOK_IS_FAILED],
69+
[Manager::FLAG_IGNORE_SPLIT_DB],
70+
[Manager::FLAG_ENV_FILE_ABSENCE]
71+
);
72+
$this->fileListMock->expects($this->once())
73+
->method('getCloudErrorLog')
74+
->willReturn($filePath);
75+
$this->fileMock->expects($this->once())
76+
->method('deleteFile')
77+
->with($filePath);
78+
79+
$this->step->execute();
80+
}
5481

82+
public function testExceptionType()
83+
{
84+
$this->expectException(StepException::class);
85+
$this->flagManagerMock->expects($this->once())
86+
->method('delete')
87+
->willThrowException(new \Exception('txt'));
5588
$this->step->execute();
5689
}
5790
}

0 commit comments

Comments
 (0)