Skip to content

Commit 8c6c81d

Browse files
MAGECLOUD-1045: Prepare infrastructure for integration tests (#35)
1 parent 975189d commit 8c6c81d

36 files changed

+881
-197
lines changed

.travis.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
sudo: false
22
dist: trusty
3-
3+
services:
4+
- mysql
45
language: php
56
php:
67
- 7.0
78
- 7.1
89
env:
910
global:
1011
- COMPOSER_BIN_DIR=~/bin
12+
matrix:
13+
- TEST_SUITE=static
14+
- TEST_SUITE=unit
15+
- TEST_SUITE=integration
16+
matrix:
17+
exclude:
18+
- php: 7.1
19+
env: TEST_SUITE=integration
1120
cache:
1221
apt: true
1322
directories:
1423
- $HOME/.composer/cache
15-
install: composer install --no-interaction --prefer-dist
16-
script: composer test
24+
install:
25+
- composer install --no-interaction
26+
before_install:
27+
- mysql -e 'CREATE DATABASE IF NOT EXISTS integration_tests;'
28+
script:
29+
- if [ $TEST_SUITE == "static" ]; then phpcs src --standard=tests/static/phpcs-ruleset.xml -p -n; fi;
30+
- if [ $TEST_SUITE == "static" ]; then phpmd src xml tests/static/phpmd-ruleset.xml; fi;
31+
- if [ $TEST_SUITE == "unit" ]; then phpunit --configuration tests/unit/phpunit.xml.dist; fi;
32+
- if [ $TEST_SUITE == "integration" ]; then phpunit --configuration tests/integration/phpunit.xml.dist; fi;

composer.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Provides tools to build and deploy Magento 2 Enterprise Edition",
44
"version": "2002.0",
55
"license": [
6-
"OSL-3.0",
7-
"AFL-3.0"
6+
"OSL-3.0",
7+
"AFL-3.0"
88
],
99
"require": {
1010
"php": "^7.0",
@@ -13,7 +13,8 @@
1313
"illuminate/container": "^5.5",
1414
"psr/log": "^1.0",
1515
"psr/container": "^1.0",
16-
"composer/composer": "@stable"
16+
"composer/composer": "@stable",
17+
"composer/semver": "^1.4"
1718
},
1819
"require-dev": {
1920
"phpunit/phpunit": "~6.2.0",
@@ -22,8 +23,11 @@
2223
"phpmd/phpmd": "@stable",
2324
"php-mock/php-mock-phpunit": "^2.0"
2425
},
25-
"bin":[
26-
"m2-ece-build", "m2-ece-deploy", "m2-ece-scd-dump", "bin/ece-tools"
26+
"bin": [
27+
"m2-ece-build",
28+
"m2-ece-deploy",
29+
"m2-ece-scd-dump",
30+
"bin/ece-tools"
2731
],
2832
"autoload": {
2933
"psr-4": {
@@ -32,10 +36,11 @@
3236
},
3337
"scripts": {
3438
"test": [
35-
"phpunit src",
36-
"phpcs src --standard=phpcs-ruleset.xml -p -n",
37-
"phpmd src xml phpmd-ruleset.xml"
39+
"phpcs src --standard=tests/static/phpcs-ruleset.xml -p -n",
40+
"phpmd src xml tests/static/phpmd-ruleset.xml",
41+
"phpunit --configuration tests/unit/phpunit.xml.dist"
3842
]
3943
},
44+
"process-timeout": 600,
4045
"prefer-stable": true
4146
}

phpunit.xml.dist

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Magento/MagentoCloud/App/Container.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public function __construct(string $root, array $config)
5656
$this->singleton(\Magento\MagentoCloud\Config\Build::class);
5757
$this->singleton(\Magento\MagentoCloud\Config\Deploy::class);
5858
$this->singleton(\Psr\Log\LoggerInterface::class, $this->createLogger('default'));
59-
$this->singleton(\Magento\MagentoCloud\Util\ComponentInfo::class);
59+
$this->singleton(\Magento\MagentoCloud\Package\Manager::class);
60+
$this->singleton(\Magento\MagentoCloud\Package\MagentoVersion::class);
6061
$this->singleton(\Magento\MagentoCloud\Util\UrlManager::class);
6162
$this->singleton(
6263
\Magento\MagentoCloud\DB\ConnectionInterface::class,
@@ -104,7 +105,6 @@ public function __construct(string $root, array $config)
104105
$this->make(DeployProcess\InstallUpdate\Install\Setup::class),
105106
$this->make(DeployProcess\InstallUpdate\Install\SecureAdmin::class),
106107
$this->make(DeployProcess\InstallUpdate\ConfigUpdate::class),
107-
$this->make(DeployProcess\InstallUpdate\Install\ImportDeploymentConfig::class),
108108
],
109109
]);
110110
});

src/Magento/MagentoCloud/Application.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ class Application extends \Symfony\Component\Console\Application
2727
public function __construct(ContainerInterface $container)
2828
{
2929
$this->container = $container;
30-
$composer = $container->get(Composer::class);
3130

3231
parent::__construct(
33-
$composer->getPackage()->getPrettyName(),
34-
$composer->getPackage()->getPrettyVersion()
32+
$container->get(Composer::class)->getPackage()->getPrettyName(),
33+
$container->get(Composer::class)->getPackage()->getPrettyVersion()
3534
);
3635
}
3736

src/Magento/MagentoCloud/Command/Build.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
class Build extends Command
1919
{
20+
const NAME = 'build';
21+
2022
/**
2123
* @var ProcessInterface
2224
*/
@@ -46,7 +48,7 @@ public function __construct(
4648
*/
4749
protected function configure()
4850
{
49-
$this->setName('build')
51+
$this->setName(static::NAME)
5052
->setDescription('Builds application');
5153

5254
parent::configure();

src/Magento/MagentoCloud/Command/Deploy.php

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

5052
parent::configure();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MagentoCloud\Package;
7+
8+
use Composer\Semver\Comparator;
9+
10+
class MagentoVersion
11+
{
12+
/**
13+
* @var Manager
14+
*/
15+
private $manager;
16+
17+
/**
18+
* @var Comparator
19+
*/
20+
private $comparator;
21+
22+
/**
23+
* @param Manager $manager
24+
* @param Comparator $comparator
25+
*/
26+
public function __construct(Manager $manager, Comparator $comparator)
27+
{
28+
$this->manager = $manager;
29+
$this->comparator = $comparator;
30+
}
31+
32+
/**
33+
* @param string $version
34+
* @return bool
35+
*/
36+
public function isGreaterOrEqual(string $version): bool
37+
{
38+
$package = $this->manager->get('magento/magento2-base');
39+
40+
return $this->comparator::compare($package->getVersion(), '>=', $version);
41+
}
42+
}

src/Magento/MagentoCloud/Util/ComponentInfo.php renamed to src/Magento/MagentoCloud/Package/Manager.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,32 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\MagentoCloud\Util;
6+
namespace Magento\MagentoCloud\Package;
77

88
use Composer\Composer;
99
use Composer\Package\PackageInterface;
10+
use Composer\Repository\RepositoryInterface;
1011

11-
class ComponentInfo
12+
class Manager
1213
{
1314
/**
1415
* @var Composer
1516
*/
1617
private $composer;
1718

19+
/**
20+
* @var RepositoryInterface
21+
*/
22+
private $repository;
23+
1824
/**
1925
* @param Composer $composer
2026
*/
2127
public function __construct(
2228
Composer $composer
2329
) {
2430
$this->composer = $composer;
31+
$this->repository = $composer->getLocker()->getLockedRepository();
2532
}
2633

2734
/**
@@ -30,13 +37,11 @@ public function __construct(
3037
* @param array $packages The array of packages names
3138
* @return string
3239
*/
33-
public function get(array $packages = ['magento/ece-tools', 'magento/magento2-base']): string
40+
public function getPrettyInfo(array $packages = ['magento/ece-tools', 'magento/magento2-base']): string
3441
{
35-
$repository = $this->composer->getLocker()->getLockedRepository();
36-
3742
$versions = [];
3843
foreach ($packages as $packageName) {
39-
$package = $repository->findPackage($packageName, '*');
44+
$package = $this->repository->findPackage($packageName, '*');
4045
if ($package instanceof PackageInterface) {
4146
$versions[] = sprintf(
4247
'%s version: %s',
@@ -48,4 +53,21 @@ public function get(array $packages = ['magento/ece-tools', 'magento/magento2-ba
4853

4954
return '(' . implode(', ', $versions) . ')';
5055
}
56+
57+
/**
58+
* @param string $packageName
59+
* @param string $version
60+
* @return PackageInterface
61+
* @throws \Exception
62+
*/
63+
public function get(string $packageName, string $version = '*'): PackageInterface
64+
{
65+
$package = $this->repository->findPackage($packageName, $version);
66+
67+
if (!$package instanceof PackageInterface) {
68+
throw new \Exception('Package was not found');
69+
}
70+
71+
return $package;
72+
}
5173
}

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

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

8+
use Magento\MagentoCloud\Package\MagentoVersion;
89
use Magento\MagentoCloud\Process\ProcessInterface;
910
use Magento\MagentoCloud\Shell\ShellInterface;
1011
use Psr\Log\LoggerInterface;
@@ -24,14 +25,24 @@ class ApplyPatches implements ProcessInterface
2425
*/
2526
private $logger;
2627

28+
/**
29+
* @var MagentoVersion
30+
*/
31+
private $magentoVersion;
32+
2733
/**
2834
* @param ShellInterface $shell
2935
* @param LoggerInterface $logger
36+
* @param MagentoVersion $magentoVersion
3037
*/
31-
public function __construct(ShellInterface $shell, LoggerInterface $logger)
32-
{
38+
public function __construct(
39+
ShellInterface $shell,
40+
LoggerInterface $logger,
41+
MagentoVersion $magentoVersion
42+
) {
3343
$this->shell = $shell;
3444
$this->logger = $logger;
45+
$this->magentoVersion = $magentoVersion;
3546
}
3647

3748
/**
@@ -42,7 +53,9 @@ public function execute()
4253
$this->logger->info('Applying patches.');
4354

4455
try {
45-
$this->shell->execute('php vendor/bin/m2-apply-patches');
56+
if ($this->magentoVersion->isGreaterOrEqual('2.2')) {
57+
$this->shell->execute('php vendor/bin/m2-apply-patches');
58+
}
4659
} catch (\Exception $exception) {
4760
$this->logger->warning('Patching was failed. Skipping.');
4861
}

0 commit comments

Comments
 (0)