Skip to content

Commit 697fad2

Browse files
MAGECLOUD-1186: No exception on patching error (#70)
1 parent 3024a5e commit 697fad2

File tree

2 files changed

+49
-27
lines changed

2 files changed

+49
-27
lines changed

src/Process/Build/ApplyPatches.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
namespace Magento\MagentoCloud\Process\Build;
77

8-
use Magento\MagentoCloud\Package\MagentoVersion;
8+
use Magento\MagentoCloud\Filesystem\DirectoryList;
9+
use Magento\MagentoCloud\Filesystem\Driver\File;
910
use Magento\MagentoCloud\Process\ProcessInterface;
1011
use Magento\MagentoCloud\Shell\ShellInterface;
1112
use Psr\Log\LoggerInterface;
@@ -26,23 +27,31 @@ class ApplyPatches implements ProcessInterface
2627
private $logger;
2728

2829
/**
29-
* @var MagentoVersion
30+
* @var File
3031
*/
31-
private $magentoVersion;
32+
private $file;
33+
34+
/**
35+
* @var DirectoryList
36+
*/
37+
private $directoryList;
3238

3339
/**
3440
* @param ShellInterface $shell
3541
* @param LoggerInterface $logger
36-
* @param MagentoVersion $magentoVersion
42+
* @param File $file
43+
* @param DirectoryList $directoryList
3744
*/
3845
public function __construct(
3946
ShellInterface $shell,
4047
LoggerInterface $logger,
41-
MagentoVersion $magentoVersion
48+
File $file,
49+
DirectoryList $directoryList
4250
) {
4351
$this->shell = $shell;
4452
$this->logger = $logger;
45-
$this->magentoVersion = $magentoVersion;
53+
$this->file = $file;
54+
$this->directoryList = $directoryList;
4655
}
4756

4857
/**
@@ -52,12 +61,14 @@ public function execute()
5261
{
5362
$this->logger->info('Applying patches.');
5463

55-
try {
56-
if ($this->magentoVersion->isGreaterOrEqual('2.2')) {
57-
$this->shell->execute('php vendor/bin/m2-apply-patches');
58-
}
59-
} catch (\Exception $exception) {
60-
$this->logger->warning('Patching was failed. Skipping.');
64+
$patchScript = $this->directoryList->getMagentoRoot() . '/vendor/bin/m2-apply-patches';
65+
66+
if (!$this->file->isExists($patchScript)) {
67+
$this->logger->warning('Package with patches was not found.');
68+
69+
return;
6170
}
71+
72+
$this->shell->execute('php ' . $patchScript);
6273
}
6374
}

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
namespace Magento\MagentoCloud\Test\Unit\Process\Build;
77

8-
use Magento\MagentoCloud\Package\MagentoVersion;
8+
use Magento\MagentoCloud\Filesystem\DirectoryList;
9+
use Magento\MagentoCloud\Filesystem\Driver\File;
910
use Magento\MagentoCloud\Process\Build\ApplyPatches;
1011
use Magento\MagentoCloud\Shell\ShellInterface;
1112
use PHPUnit\Framework\TestCase;
@@ -33,9 +34,14 @@ class ApplyPatchesTest extends TestCase
3334
private $shellMock;
3435

3536
/**
36-
* @var MagentoVersion|Mock
37+
* @var File|Mock
3738
*/
38-
private $magentoVersionMock;
39+
private $fileMock;
40+
41+
/**
42+
* @var DirectoryList|Mock
43+
*/
44+
private $directoryListMock;
3945

4046
/**
4147
* @inheritdoc
@@ -46,48 +52,53 @@ protected function setUp()
4652
->getMockForAbstractClass();
4753
$this->shellMock = $this->getMockBuilder(ShellInterface::class)
4854
->getMockForAbstractClass();
49-
$this->magentoVersionMock = $this->getMockBuilder(MagentoVersion::class)
55+
$this->fileMock = $this->getMockBuilder(File::class)
5056
->disableOriginalConstructor()
5157
->getMock();
58+
$this->directoryListMock = $this->createMock(DirectoryList::class);
5259

5360
$this->process = new ApplyPatches(
5461
$this->shellMock,
5562
$this->loggerMock,
56-
$this->magentoVersionMock
63+
$this->fileMock,
64+
$this->directoryListMock
5765
);
5866

5967
parent::setUp();
6068
}
6169

6270
public function testExecute()
6371
{
72+
$this->directoryListMock->method('getMagentoRoot')
73+
->willReturn('magento_root');
6474
$this->loggerMock->expects($this->once())
6575
->method('info')
6676
->with('Applying patches.');
6777
$this->shellMock->expects($this->once())
6878
->method('execute')
69-
->with('php vendor/bin/m2-apply-patches');
70-
$this->magentoVersionMock->method('isGreaterOrEqual')
71-
->with('2.2')
79+
->with('php magento_root/vendor/bin/m2-apply-patches');
80+
$this->fileMock->method('isExists')
81+
->with('magento_root/vendor/bin/m2-apply-patches')
7282
->willReturn(true);
7383

7484
$this->process->execute();
7585
}
7686

7787
public function testExecuteWithoutPatches()
7888
{
89+
$this->directoryListMock->method('getMagentoRoot')
90+
->willReturn('magento_root');
7991
$this->loggerMock->expects($this->once())
8092
->method('info')
8193
->with('Applying patches.');
82-
$this->magentoVersionMock->method('isGreaterOrEqual')
83-
->with('2.2')
84-
->willReturn(true);
94+
$this->fileMock->method('isExists')
95+
->with('magento_root/vendor/bin/m2-apply-patches')
96+
->willReturn(false);
8597
$this->loggerMock->expects($this->once())
8698
->method('warning')
87-
->with('Patching was failed. Skipping.');
88-
$this->shellMock->expects($this->once())
89-
->method('execute')
90-
->willThrowException(new \Exception('Patching failed.'));
99+
->with('Package with patches was not found.');
100+
$this->shellMock->expects($this->never())
101+
->method('execute');
91102

92103
$this->process->execute();
93104
}

0 commit comments

Comments
 (0)