Skip to content

Commit c80b772

Browse files
Merge pull request #42 from magento-thunder/MAGECLOUD-1062
MAGECLOUD-1062: Eliminate TestCase bootstrap
2 parents fdd74b4 + c08d367 commit c80b772

File tree

21 files changed

+340
-218
lines changed

21 files changed

+340
-218
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ cache:
2121
apt: true
2222
directories:
2323
- $HOME/.composer/cache
24-
install:
25-
- composer install --no-interaction
26-
before_install:
27-
- mysql -e 'CREATE DATABASE IF NOT EXISTS integration_tests;'
24+
before_install: ./tests/travis/before_install.sh
25+
install: composer install --no-interaction
2826
script:
2927
- if [ $TEST_SUITE == "static" ]; then phpcs src --standard=tests/static/phpcs-ruleset.xml -p -n; fi;
3028
- if [ $TEST_SUITE == "static" ]; then phpmd src xml tests/static/phpmd-ruleset.xml; fi;

autoload.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
<?php
2-
3-
define('MAGENTO_ROOT', __DIR__ . '/../../../');
4-
define('BP', __DIR__);
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
define('ECE_BP', __DIR__);
57

68
/**
7-
* This hack is to prevent Composer crash when
8-
* NonComposerComponentRegistration.php was moved from
9-
* app/etc during writable directories mounting.
9+
* This hack is to prevent Composer crash when 'NonComposerComponentRegistration.php'
10+
* was moved from app/etc during writable directories mounting.
1011
*/
11-
if (!file_exists(MAGENTO_ROOT . '/app/etc/NonComposerComponentRegistration.php') &&
12-
file_exists(MAGENTO_ROOT . '/init/app/etc/NonComposerComponentRegistration.php')
12+
$magentoRoot = __DIR__ . '/../../../';
13+
14+
if (!file_exists($magentoRoot . '/app/etc/NonComposerComponentRegistration.php') &&
15+
file_exists($magentoRoot . '/init/app/etc/NonComposerComponentRegistration.php')
1316
) {
1417
copy(
15-
MAGENTO_ROOT . '/init/app/etc/NonComposerComponentRegistration.php',
16-
MAGENTO_ROOT . '/app/etc/NonComposerComponentRegistration.php'
18+
$magentoRoot . '/init/app/etc/NonComposerComponentRegistration.php',
19+
$magentoRoot . '/app/etc/NonComposerComponentRegistration.php'
1720
);
1821
}
1922

bin/ece-tools

100644100755
File mode changed.

src/Magento/MagentoCloud/App/Bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public function __construct(string $root, array $server)
4141
* @param array $server
4242
* @return Bootstrap
4343
*/
44-
public static function create(string $root = BP, array $server = [])
44+
public static function create(string $root = ECE_BP, array $server = [])
4545
{
46-
$server = $server + $_SERVER;
46+
$server = array_replace($_SERVER, $server);
4747

4848
return new self($root, $server);
4949
}

src/Magento/MagentoCloud/Config/Environment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class Environment
1616
{
1717
const STATIC_CONTENT_DEPLOY_FLAG = '.static_content_deploy';
18-
const REGENERATE_FLAG = MAGENTO_ROOT . 'var/.regenerate';
18+
const REGENERATE_FLAG = 'var/.regenerate';
1919

2020
const MAGENTO_PRODUCTION_MODE = 'production';
2121
const MAGENTO_DEVELOPER_MODE = 'developer';

src/Magento/MagentoCloud/Process/Build/MarshallFiles.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ public function execute()
7070
$this->file->createDirectory($enterpriseFolder, 0777);
7171
}
7272

73-
$this->file->copy(
74-
$magentoRoot . '/app/etc/enterprise/di.xml',
75-
$magentoRoot . '/app/enterprise/di.xml'
76-
);
73+
if ($this->file->isExists($magentoRoot . '/app/etc/enterprise/di.xml')) {
74+
$this->file->copy(
75+
$magentoRoot . '/app/etc/enterprise/di.xml',
76+
$magentoRoot . '/app/enterprise/di.xml'
77+
);
78+
}
7779
}
7880
}

src/Magento/MagentoCloud/Process/Deploy/InstallUpdate/Update/Setup.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\MagentoCloud\Process\Deploy\InstallUpdate\Update;
77

88
use Magento\MagentoCloud\Config\Environment;
9+
use Magento\MagentoCloud\Filesystem\DirectoryList;
910
use Magento\MagentoCloud\Filesystem\Driver\File;
1011
use Magento\MagentoCloud\Process\ProcessInterface;
1112
use Magento\MagentoCloud\Shell\ShellInterface;
@@ -37,16 +38,30 @@ class Setup implements ProcessInterface
3738
*/
3839
private $file;
3940

41+
/**
42+
* @var DirectoryList
43+
*/
44+
private $directoryList;
45+
46+
/**
47+
* @param LoggerInterface $logger
48+
* @param Environment $environment
49+
* @param ShellInterface $shell
50+
* @param File $file
51+
* @param DirectoryList $directoryList
52+
*/
4053
public function __construct(
4154
LoggerInterface $logger,
4255
Environment $environment,
4356
ShellInterface $shell,
44-
File $file
57+
File $file,
58+
DirectoryList $directoryList
4559
) {
4660
$this->logger = $logger;
4761
$this->environment = $environment;
4862
$this->shell = $shell;
4963
$this->file = $file;
64+
$this->directoryList = $directoryList;
5065
}
5166

5267
/**
@@ -83,9 +98,11 @@ public function execute()
8398
*/
8499
private function removeRegenerateFlag()
85100
{
86-
if ($this->file->isExists(Environment::REGENERATE_FLAG)) {
101+
$magentoRoot = $this->directoryList->getMagentoRoot();
102+
103+
if ($this->file->isExists($magentoRoot . '/' . Environment::REGENERATE_FLAG)) {
87104
$this->logger->info('Removing .regenerate flag');
88-
$this->file->deleteFile(Environment::REGENERATE_FLAG);
105+
$this->file->deleteFile($magentoRoot . '/' . Environment::REGENERATE_FLAG);
89106
}
90107
}
91108
}

src/Magento/MagentoCloud/Process/Deploy/PreDeploy/RestoreWritableDirectories.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\MagentoCloud\Process\Deploy\PreDeploy;
77

88
use Magento\MagentoCloud\Config\Environment;
9+
use Magento\MagentoCloud\Filesystem\DirectoryList;
910
use Magento\MagentoCloud\Filesystem\Driver\File;
1011
use Magento\MagentoCloud\Process\ProcessInterface;
1112
use Magento\MagentoCloud\Util\BuildDirCopier;
@@ -33,22 +34,30 @@ class RestoreWritableDirectories implements ProcessInterface
3334
*/
3435
private $environment;
3536

37+
/**
38+
* @var DirectoryList
39+
*/
40+
private $directoryList;
41+
3642
/**
3743
* @param LoggerInterface $logger
3844
* @param File $file
3945
* @param BuildDirCopier $buildDirCopier
4046
* @param Environment $environment
47+
* @param DirectoryList $directoryList
4148
*/
4249
public function __construct(
4350
LoggerInterface $logger,
4451
File $file,
4552
BuildDirCopier $buildDirCopier,
46-
Environment $environment
53+
Environment $environment,
54+
DirectoryList $directoryList
4755
) {
4856
$this->logger = $logger;
4957
$this->file = $file;
5058
$this->buildDirCopier = $buildDirCopier;
5159
$this->environment = $environment;
60+
$this->directoryList = $directoryList;
5261
}
5362

5463
/**
@@ -65,9 +74,11 @@ public function execute()
6574
// Restore mounted directories
6675
$this->logger->info('Recoverable directories were copied back.');
6776

68-
if ($this->file->isExists(Environment::REGENERATE_FLAG)) {
77+
$magentoRoot = $this->directoryList->getMagentoRoot();
78+
79+
if ($this->file->isExists($magentoRoot . '/' . Environment::REGENERATE_FLAG)) {
6980
$this->logger->info('Removing var/.regenerate flag');
70-
$this->file->deleteFile(Environment::REGENERATE_FLAG);
81+
$this->file->deleteFile($magentoRoot . '/' . Environment::REGENERATE_FLAG);
7182
}
7283
}
7384
}

src/Magento/MagentoCloud/Test/Integration/AcceptanceTest.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,50 @@
88
use Magento\MagentoCloud\Command\Build;
99
use Magento\MagentoCloud\Command\Deploy;
1010
use Magento\MagentoCloud\Config\Environment;
11+
use PHPUnit\Framework\TestCase;
1112
use Symfony\Component\Console\Tester\CommandTester;
1213

1314
/**
1415
* @inheritdoc
1516
*/
1617
class AcceptanceTest extends TestCase
1718
{
19+
/**
20+
* @inheritdoc
21+
*/
22+
protected function setUp()
23+
{
24+
shell_exec(sprintf(
25+
"cp -f %s %s",
26+
Bootstrap::create()->getConfigFile('config.php'),
27+
Bootstrap::create()->getSandboxDir() . '/app/etc/config.php'
28+
));
29+
}
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
protected function tearDown()
35+
{
36+
$sandboxDir = Bootstrap::create()->getSandboxDir();
37+
38+
shell_exec(sprintf(
39+
"cd %s && php bin/magento setup:uninstall -n",
40+
$sandboxDir
41+
));
42+
shell_exec(sprintf(
43+
"cd %s && rm -rf init",
44+
$sandboxDir
45+
));
46+
}
47+
1848
/**
1949
* @param array $environment
2050
* @dataProvider dataProvider
2151
*/
2252
public function test(array $environment)
2353
{
24-
$application = $this->createApplication($environment);
54+
$application = Bootstrap::create()->createApplication($environment);
2555

2656
$commandTester = new CommandTester(
2757
$application->get(Build::NAME)
@@ -47,10 +77,11 @@ public function dataProvider(): array
4777
'default configuration' => [
4878
'environment' => [],
4979
],
50-
'disabled static content symlinks ' => [
80+
'disabled static content symlinks 3 jobs' => [
5181
'environment' => [
5282
'variables' => [
5383
'STATIC_CONTENT_SYMLINK' => Environment::VAL_DISABLED,
84+
'STATIC_CONTENT_THREADS' => 3,
5485
],
5586
],
5687
],

0 commit comments

Comments
 (0)