Skip to content

Commit 7ddb18c

Browse files
MAGECLOUD-1057: Add possibility to change SCD strategy
1 parent b5ffb97 commit 7ddb18c

File tree

6 files changed

+320
-8
lines changed

6 files changed

+320
-8
lines changed

src/Magento/MagentoCloud/Command/ConfigDump.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
class ConfigDump extends Command
1919
{
20+
const NAME = 'dump';
21+
2022
/**
2123
* @var LoggerInterface
2224
*/
@@ -44,7 +46,7 @@ public function __construct(ProcessInterface $process, LoggerInterface $logger)
4446
*/
4547
protected function configure()
4648
{
47-
$this->setName('dump')
49+
$this->setName(static::NAME)
4850
->setDescription('Dump static content');
4951

5052
parent::configure();

src/Magento/MagentoCloud/Filesystem/FileSystemException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/**
99
* Filesystem exception
10+
* @codeCoverageIgnore
1011
*/
1112
class FileSystemException extends \Exception
1213
{
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Unit;
7+
8+
use Composer\Composer;
9+
use Composer\Package\PackageInterface;
10+
use Magento\MagentoCloud\Application;
11+
use Magento\MagentoCloud\Command\Build;
12+
use Magento\MagentoCloud\Command\ConfigDump;
13+
use Magento\MagentoCloud\Command\Deploy;
14+
use PHPUnit\Framework\TestCase;
15+
use Psr\Container\ContainerInterface;
16+
17+
class ApplicationTest extends TestCase
18+
{
19+
/**
20+
* @var Application
21+
*/
22+
private $application;
23+
24+
/**
25+
* @var ContainerInterface|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $containerMock;
28+
29+
/**
30+
* @var Composer|\PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
private $composerMock;
33+
34+
/**
35+
* @var PackageInterface|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
private $packageMock;
38+
39+
/**
40+
* @var Build|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $buildCommandMock;
43+
44+
/**
45+
* @var Deploy|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $deployCommandMock;
48+
49+
/**
50+
* @var ConfigDump|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $configDumpCommand;
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
public function setUp()
58+
{
59+
$this->containerMock = $this->getMockForAbstractClass(ContainerInterface::class);
60+
$this->packageMock = $this->getMockForAbstractClass(PackageInterface::class);
61+
$this->composerMock = $this->createMock(Composer::class);
62+
$this->buildCommandMock = $this->createMock(Build::class);
63+
$this->deployCommandMock = $this->createMock(Deploy::class);
64+
$this->configDumpCommand = $this->createMock(Deploy::class);
65+
66+
$this->buildCommandMock->method('getName')
67+
->willReturn(Build::NAME);
68+
$this->buildCommandMock->method('isEnabled')
69+
->willReturn(true);
70+
$this->buildCommandMock->method('getDefinition')
71+
->willReturn([]);
72+
$this->buildCommandMock->method('getAliases')
73+
->willReturn([]);
74+
$this->deployCommandMock->method('getName')
75+
->willReturn(Deploy::NAME);
76+
$this->deployCommandMock->method('isEnabled')
77+
->willReturn(true);
78+
$this->deployCommandMock->method('getDefinition')
79+
->willReturn([]);
80+
$this->deployCommandMock->method('getAliases')
81+
->willReturn([]);
82+
$this->configDumpCommand->method('getName')
83+
->willReturn(ConfigDump::NAME);
84+
$this->configDumpCommand->method('isEnabled')
85+
->willReturn(true);
86+
$this->configDumpCommand->method('getDefinition')
87+
->willReturn([]);
88+
$this->configDumpCommand->method('getAliases')
89+
->willReturn([]);
90+
91+
$this->containerMock->method('get')
92+
->willReturnMap([
93+
[Composer::class, $this->composerMock],
94+
[Build::class, $this->buildCommandMock],
95+
[Deploy::class, $this->deployCommandMock],
96+
[ConfigDump::class, $this->configDumpCommand],
97+
]);
98+
$this->composerMock->method('getPackage')
99+
->willReturn($this->packageMock);
100+
101+
$this->application = new Application(
102+
$this->containerMock
103+
);
104+
}
105+
106+
public function testHasCommand()
107+
{
108+
$this->assertTrue($this->application->has(Build::NAME));
109+
$this->assertTrue($this->application->has(Deploy::NAME));
110+
$this->assertTrue($this->application->has(ConfigDump::NAME));
111+
}
112+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MagentoCloud\Test\Unit\Config\Build;
7+
8+
use Magento\MagentoCloud\Config\Build\Reader;
9+
use Magento\MagentoCloud\Filesystem\DirectoryList;
10+
use Magento\MagentoCloud\Filesystem\Driver\File;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* @inheritdoc
15+
*/
16+
class ReaderTest extends TestCase
17+
{
18+
/**
19+
* @var Reader
20+
*/
21+
private $reader;
22+
23+
/**
24+
* @var File|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $fileMock;
27+
28+
/**
29+
* @var DirectoryList|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $directoryListMock;
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function setUp()
37+
{
38+
$this->fileMock = $this->createMock(File::class);
39+
$this->directoryListMock = $this->createMock(DirectoryList::class);
40+
41+
$this->reader = new Reader(
42+
$this->fileMock,
43+
$this->directoryListMock
44+
);
45+
}
46+
47+
public function testRead()
48+
{
49+
$this->directoryListMock->method('getMagentoRoot')
50+
->willReturn('magento_root');
51+
$this->fileMock->method('isExists')
52+
->with('magento_root/build_options.ini')
53+
->willReturn(true);
54+
$this->fileMock->method('parseIni')
55+
->with('magento_root/build_options.ini')
56+
->willReturn(['some_data']);
57+
58+
$this->assertSame(['some_data'], $this->reader->read());
59+
}
60+
61+
public function testReadNoFile()
62+
{
63+
$this->directoryListMock->method('getMagentoRoot')
64+
->willReturn('magento_root');
65+
$this->fileMock->method('isExists')
66+
->with('magento_root/build_options.ini')
67+
->willReturn(false);
68+
$this->fileMock->expects($this->never())
69+
->method('parseIni');
70+
71+
$this->assertSame([], $this->reader->read());
72+
}
73+
74+
public function testGetPath()
75+
{
76+
$this->directoryListMock->method('getMagentoRoot')
77+
->willReturn('magento_root');
78+
79+
$this->assertSame(
80+
'magento_root/build_options.ini',
81+
$this->reader->getPath()
82+
);
83+
}
84+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MagentoCloud\Test\Unit\Config;
7+
8+
use Magento\MagentoCloud\Config\Build;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* @inheritdoc
13+
*/
14+
class BuildTest extends TestCase
15+
{
16+
/**
17+
* @var Build
18+
*/
19+
private $build;
20+
21+
/**
22+
* @var Build\Reader|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $readerMock;
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
protected function setUp()
30+
{
31+
$this->readerMock = $this->getMockBuilder(Build\Reader::class)
32+
->disableOriginalConstructor()
33+
->getMock();
34+
35+
$this->build = new Build(
36+
$this->readerMock
37+
);
38+
}
39+
40+
public function testGet()
41+
{
42+
$this->readerMock->expects($this->once())
43+
->method('read')
44+
->willReturn([
45+
'key1' => 'value1',
46+
'key2' => 'value2',
47+
]);
48+
49+
$this->assertSame('value1', $this->build->get('key1'));
50+
$this->assertSame('value2', $this->build->get('key2'));
51+
$this->assertSame(null, $this->build->get('undefined'));
52+
$this->assertSame('default_val', $this->build->get('undefined', 'default_val'));
53+
}
54+
55+
public function testGetVerbosityLevel()
56+
{
57+
$this->readerMock->expects($this->once())
58+
->method('read')
59+
->willReturn([
60+
Build::OPT_VERBOSE_COMMANDS => 'enabled',
61+
]);
62+
63+
$this->assertSame(
64+
' -vv ',
65+
$this->build->getVerbosityLevel()
66+
);
67+
}
68+
69+
public function testGetScdStrategy()
70+
{
71+
$this->readerMock->expects($this->once())
72+
->method('read')
73+
->willReturn([
74+
Build::OPT_SCD_STRATEGY => 'quick',
75+
]);
76+
77+
$this->assertSame(
78+
'-s quick',
79+
$this->build->getScdStrategy()
80+
);
81+
}
82+
}

0 commit comments

Comments
 (0)