diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 93c49950af..3aefdf690e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['7.1', '7.2', '7.3', '7.4'] + php-versions: ['7.2', '7.3', '7.4'] steps: - name: Checkout uses: actions/checkout@v1 diff --git a/.gitignore b/.gitignore index a317184a3d..112c0cabdc 100755 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /auth.json /codeception.yml /_workdir +/*.code-workspace diff --git a/composer.json b/composer.json index 17add7d95e..66a1e985e4 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "magento/ece-tools", "description": "Provides tools to build and deploy Magento 2 Enterprise Edition", "type": "magento2-component", - "version": "2002.1.7", + "version": "2002.1.8", "license": "OSL-3.0", "repositories": { "repo.magento.com": { @@ -16,25 +16,25 @@ "ext-json": "*", "ext-sockets": "*", "colinmollenhour/credis": "^1.6.0", - "composer/composer": "^1.4||^2.0", + "composer/composer": "^1.4 || ^2.0", "composer/semver": "@stable", "graylog2/gelf-php": "^1.4.2", - "guzzlehttp/guzzle": "^6.2", + "guzzlehttp/guzzle": "^6.3||^7.3", "illuminate/config": "^5.5", "magento/magento-cloud-components": "^1.0.8", "magento/magento-cloud-docker": "^1.0.0", "magento/magento-cloud-patches": "^1.0.11", "magento/quality-patches": "^1.1.0", - "monolog/monolog": "^1.16", - "nesbot/carbon": "^1.0||^2.0", + "monolog/monolog": "^1.25 || ^2.3", + "nesbot/carbon": "^1.0 || ^2.0", "psr/container": "^1.0", "psr/log": "^1.0", - "symfony/config": "^4.4", - "symfony/console": "^2.8||^4.0", - "symfony/dependency-injection": "^3.3||^4.3", - "symfony/process": "^2.1||^4.1", - "symfony/serializer": "^2.8||^3.3||^4.0", - "symfony/yaml": "^3.3||^4.0" + "symfony/config": "^4.4 || ^5.1", + "symfony/console": "^2.8 || ^4.0 || ^5.1", + "symfony/dependency-injection": "^3.3 || ^4.3 || ^5.1", + "symfony/process": "^2.1 || ^4.1 || ^5.1", + "symfony/serializer": "^2.8 || ^3.3 || ^4.0", + "symfony/yaml": "^3.3 || ^4.0 || ^5.1" }, "require-dev": { "codeception/codeception": "^2.5.3", diff --git a/src/App/Logger/Formatter/JsonErrorFormatter.php b/src/App/Logger/Formatter/JsonErrorFormatter.php index 3abab27252..cf2ea2e1cb 100644 --- a/src/App/Logger/Formatter/JsonErrorFormatter.php +++ b/src/App/Logger/Formatter/JsonErrorFormatter.php @@ -30,7 +30,7 @@ class JsonErrorFormatter extends JsonFormatter /** * @param ErrorInfo $errorInfo * @param ReaderInterface $reader - * @param int $batchMode + * @param 1|2 $batchMode * @param bool $appendNewline */ public function __construct( @@ -50,22 +50,22 @@ public function __construct( * * {@inheritDoc} */ - public function format(array $record) + public function format(array $record): string { try { if (!isset($record['context']['errorCode'])) { - return false; + return ''; } $loggedErrors = $this->reader->read(); if (isset($loggedErrors[$record['context']['errorCode']])) { - return false; + return ''; } return parent::format($this->formatLog($record)); - } catch (\Exception $e) { - return false; + } catch (\Exception $exception) { + return ''; } } @@ -98,6 +98,7 @@ private function formatLog(array $record): array } ksort($errorInfo); + return $errorInfo; } } diff --git a/src/App/Logger/Formatter/LineFormatter.php b/src/App/Logger/Formatter/LineFormatter.php index 195587fe0d..eb8db4ee3f 100644 --- a/src/App/Logger/Formatter/LineFormatter.php +++ b/src/App/Logger/Formatter/LineFormatter.php @@ -20,7 +20,7 @@ class LineFormatter extends \Monolog\Formatter\LineFormatter /** * @inheritDoc */ - public function format(array $record) + public function format(array $record): string { $errorLevels = [ Logger::getLevelName(Logger::WARNING), diff --git a/src/App/Logger/Gelf/Handler.php b/src/App/Logger/Gelf/Handler.php index 9b19836af9..c4a39dc79c 100644 --- a/src/App/Logger/Gelf/Handler.php +++ b/src/App/Logger/Gelf/Handler.php @@ -21,7 +21,7 @@ class Handler extends GelfHandler * @param array $record * @codeCoverageIgnore */ - protected function write(array $record) + protected function write(array $record): void { try { parent::write($record); diff --git a/src/App/Logger/Gelf/HandlerFactory.php b/src/App/Logger/Gelf/HandlerFactory.php index a755fa1548..af95df496b 100644 --- a/src/App/Logger/Gelf/HandlerFactory.php +++ b/src/App/Logger/Gelf/HandlerFactory.php @@ -33,11 +33,11 @@ public function __construct(TransportFactory $transportFactory) * Creates instance of Gelf handler. * * @param Repository $configuration - * @param int $minLevel + * @param mixed $minLevel * @return Handler * @throws LoggerException */ - public function create(Repository $configuration, int $minLevel): Handler + public function create(Repository $configuration, $minLevel): Handler { $this->increaseSocketTimeout(); diff --git a/src/App/Logger/Gelf/MessageFormatter.php b/src/App/Logger/Gelf/MessageFormatter.php index 6090532904..3ddd2d3972 100644 --- a/src/App/Logger/Gelf/MessageFormatter.php +++ b/src/App/Logger/Gelf/MessageFormatter.php @@ -8,6 +8,7 @@ namespace Magento\MagentoCloud\App\Logger\Gelf; use Monolog\Formatter\GelfMessageFormatter; +use Gelf\Message; /** * Extends functionality of GelfMessageFormatter. @@ -33,7 +34,7 @@ public function setAdditional(array $additional) /** * @inheritdoc */ - public function format(array $record) + public function format(array $record): Message { $message = parent::format($record); diff --git a/src/App/Logger/HandlerFactory.php b/src/App/Logger/HandlerFactory.php index a455508893..45d93a7250 100644 --- a/src/App/Logger/HandlerFactory.php +++ b/src/App/Logger/HandlerFactory.php @@ -7,35 +7,36 @@ namespace Magento\MagentoCloud\App\Logger; -use Illuminate\Contracts\Config\Repository; use Magento\MagentoCloud\App\Logger\Gelf\HandlerFactory as GelfHandlerFactory; +use Magento\MagentoCloud\App\LoggerException; +use Magento\MagentoCloud\Config\ConfigException; use Magento\MagentoCloud\Config\GlobalSection; use Magento\MagentoCloud\Config\Log as LogConfig; -use Monolog\Handler\HandlerInterface; +use Monolog\Handler\AbstractProcessingHandler; use Monolog\Handler\NativeMailerHandler; use Monolog\Handler\SlackHandler; use Monolog\Handler\StreamHandler; use Monolog\Handler\SyslogHandler; use Monolog\Handler\SyslogUdpHandler; +use Monolog\Logger; /** * The handler factory. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class HandlerFactory { - const HANDLER_STREAM = 'stream'; - const HANDLER_FILE = 'file'; - const HANDLER_FILE_ERROR = 'file_errors'; - const HANDLER_EMAIL = 'email'; - const HANDLER_SLACK = 'slack'; - const HANDLER_GELF = 'gelf'; - const HANDLER_SYSLOG = 'syslog'; - const HANDLER_SYSLOG_UDP = 'syslog_udp'; + private const UNDEFINED_LEVEL = 0; - /** - * @var LevelResolver - */ - private $levelResolver; + public const HANDLER_STREAM = 'stream'; + public const HANDLER_FILE = 'file'; + public const HANDLER_FILE_ERROR = 'file_errors'; + public const HANDLER_EMAIL = 'email'; + public const HANDLER_SLACK = 'slack'; + public const HANDLER_GELF = 'gelf'; + public const HANDLER_SYSLOG = 'syslog'; + public const HANDLER_SYSLOG_UDP = 'syslog_udp'; /** * @var LogConfig @@ -53,18 +54,15 @@ class HandlerFactory private $globalConfig; /** - * @param LevelResolver $levelResolver * @param LogConfig $logConfig * @param GelfHandlerFactory $gelfHandlerFactory * @param GlobalSection $globalConfig */ public function __construct( - LevelResolver $levelResolver, LogConfig $logConfig, GelfHandlerFactory $gelfHandlerFactory, GlobalSection $globalConfig ) { - $this->levelResolver = $levelResolver; $this->logConfig = $logConfig; $this->gelfHandlerFactory = $gelfHandlerFactory; $this->globalConfig = $globalConfig; @@ -72,80 +70,113 @@ public function __construct( /** * @param string $handler - * @return HandlerInterface + * @return AbstractProcessingHandler + * @throws LoggerException + * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - public function create(string $handler): HandlerInterface + public function create(string $handler): AbstractProcessingHandler { - $configuration = $this->logConfig->get($handler); - $levelOverride = $this->globalConfig->get(GlobalSection::VAR_MIN_LOGGING_LEVEL); - $defaultLevel = $levelOverride ?: LogConfig::LEVEL_NOTICE; - $minLevel = $this->levelResolver->resolve($configuration->get('min_level', $defaultLevel)); - - switch ($handler) { - case static::HANDLER_FILE: - $handlerInstance = new StreamHandler( - $configuration->get('file'), - $this->levelResolver->resolve($configuration->get('min_level', LogConfig::LEVEL_DEBUG)) - ); - break; - case static::HANDLER_FILE_ERROR: - $handlerInstance = new StreamHandler( - $configuration->get('file'), - $this->levelResolver->resolve($configuration->get('min_level', LogConfig::LEVEL_WARNING)) - ); - break; - case static::HANDLER_STREAM: - $defaultLevelStream = $levelOverride ?: LogConfig::LEVEL_INFO; - $handlerInstance = new StreamHandler( - $configuration->get('stream'), - $this->levelResolver->resolve($configuration->get('min_level', $defaultLevelStream)) - ); - break; - case static::HANDLER_EMAIL: - $handlerInstance = new NativeMailerHandler( - $configuration->get('to'), - $configuration->get('subject', 'Log from Magento Cloud'), - $configuration->get('from'), - $minLevel - ); - break; - case static::HANDLER_SLACK: - $handlerInstance = new SlackHandler( - $configuration->get('token'), - $configuration->get('channel', 'general'), - $configuration->get('username', 'Slack Log Notifier'), - true, - null, - $minLevel - ); - break; - case static::HANDLER_SYSLOG: - $handlerInstance = new SyslogHandler( - $configuration->get('ident'), - $configuration->get('facility', LOG_USER), - $minLevel, - true, - $configuration->get('logopts', LOG_PID) - ); - break; - case static::HANDLER_SYSLOG_UDP: - $handlerInstance = new SyslogUdpHandler( - $configuration->get('host'), - $configuration->get('port'), - $configuration->get('facility', LOG_USER), - $minLevel, - true, - $configuration->get('ident', 'php') - ); - break; - case static::HANDLER_GELF: - $handlerInstance = $this->gelfHandlerFactory->create($configuration, $minLevel); - break; - default: - throw new \Exception('Unknown type of log handler: ' . $handler); + try { + $levelOverride = $this->globalConfig->get(GlobalSection::VAR_MIN_LOGGING_LEVEL); + $minLevel = !empty($levelOverride) ? $this->normalizeLevel($levelOverride) : self::UNDEFINED_LEVEL; + + $configuration = $this->logConfig->get($handler); + } catch (ConfigException $exception) { + throw new LoggerException($exception->getMessage(), $exception->getCode(), $exception); + } + + if ($customMinLevel = $configuration->get('min_level')) { + $minLevel = $this->normalizeLevel((string)$customMinLevel); + } + + try { + switch ($handler) { + case static::HANDLER_FILE: + $handlerInstance = new StreamHandler( + $configuration->get('file'), + $minLevel ?: Logger::DEBUG + ); + break; + case static::HANDLER_FILE_ERROR: + $handlerInstance = new StreamHandler( + $configuration->get('file'), + $minLevel ?: Logger::WARNING + ); + break; + case static::HANDLER_STREAM: + $defaultLevelStream = !empty($levelOverride) ? + $this->normalizeLevel($levelOverride) + : Logger::INFO; + $handlerInstance = new StreamHandler( + $configuration->get('stream'), + $minLevel ?: $defaultLevelStream + ); + break; + case static::HANDLER_EMAIL: + $handlerInstance = new NativeMailerHandler( + $configuration->get('to'), + $configuration->get('subject', 'Log from Magento Cloud'), + $configuration->get('from'), + $minLevel ?: Logger::NOTICE + ); + break; + case static::HANDLER_SLACK: + $handlerInstance = new SlackHandler( + $configuration->get('token'), + $configuration->get('channel', 'general'), + $configuration->get('username', 'Slack Log Notifier'), + true, + null, + $minLevel ?: Logger::NOTICE + ); + break; + case static::HANDLER_SYSLOG: + $handlerInstance = new SyslogHandler( + $configuration->get('ident'), + $configuration->get('facility', LOG_USER), + $minLevel ?: Logger::NOTICE, + true, + $configuration->get('logopts', LOG_PID) + ); + break; + case static::HANDLER_SYSLOG_UDP: + $handlerInstance = new SyslogUdpHandler( + $configuration->get('host'), + $configuration->get('port'), + $configuration->get('facility', LOG_USER), + $minLevel ?: Logger::NOTICE, + true, + $configuration->get('ident', 'php') + ); + break; + case static::HANDLER_GELF: + $handlerInstance = $this->gelfHandlerFactory->create($configuration, $minLevel); + break; + default: + throw new LoggerException('Unknown type of log handler: ' . $handler); + } + } catch (\Exception $exception) { + throw new LoggerException($exception->getMessage(), $exception->getCode(), $exception); } return $handlerInstance; } + + /** + * @param string $level + * @return int + * @throws LoggerException + */ + private function normalizeLevel(string $level): int + { + /** @phpstan-ignore-next-line */ + $normalizedLevel = Logger::toMonologLevel($level); + + if (!is_int($normalizedLevel)) { + throw new LoggerException('Logger lever is incorrect'); + } + + return $normalizedLevel; + } } diff --git a/src/App/Logger/LevelResolver.php b/src/App/Logger/LevelResolver.php deleted file mode 100644 index 2ff2e49826..0000000000 --- a/src/App/Logger/LevelResolver.php +++ /dev/null @@ -1,39 +0,0 @@ - Logger::DEBUG, - 'info' => Logger::INFO, - 'notice' => Logger::NOTICE, - 'warning' => Logger::WARNING, - 'error' => Logger::ERROR, - 'critical' => Logger::CRITICAL, - 'alert' => Logger::ALERT, - 'emergency' => Logger::EMERGENCY, - ]; - - /** - * @param string $level - * @return int - */ - public function resolve(string $level): int - { - return $this->mapLevels[strtolower($level)] ?? Logger::NOTICE; - } -} diff --git a/src/App/Logger/Pool.php b/src/App/Logger/Pool.php index 901c50172c..bfa45cd93e 100644 --- a/src/App/Logger/Pool.php +++ b/src/App/Logger/Pool.php @@ -9,7 +9,7 @@ use Magento\MagentoCloud\App\Error; use Magento\MagentoCloud\App\LoggerException; -use Monolog\Handler\HandlerInterface; +use Monolog\Handler\AbstractProcessingHandler; use Magento\MagentoCloud\Config\Log as LogConfig; use Exception; use Symfony\Component\Yaml\Exception\ParseException; @@ -20,7 +20,7 @@ class Pool { /** - * @var HandlerInterface[] + * @var AbstractProcessingHandler[] */ private $handlers; @@ -55,8 +55,8 @@ public function __construct( } /** - * @return HandlerInterface[] - * @throws LoggerException If can't create handlers from config. + * @return AbstractProcessingHandler[] + * @throws LoggerException */ public function getHandlers(): array { diff --git a/src/Command/DbDump.php b/src/Command/DbDump.php index 0e5f4d101e..128b9e3d0a 100644 --- a/src/Command/DbDump.php +++ b/src/Command/DbDump.php @@ -28,6 +28,7 @@ class DbDump extends Command public const NAME = 'db-dump'; public const ARGUMENT_DATABASES = 'databases'; public const OPTION_REMOVE_DEFINERS = 'remove-definers'; + public const OPTION_DUMP_DIRECTORY = 'dump-directory'; /** * @var DumpProcessor @@ -78,6 +79,12 @@ protected function configure(): void InputOption::VALUE_NONE, 'Remove definers from the database dump' ); + $this->addOption( + self::OPTION_DUMP_DIRECTORY, + 'a', + InputOption:: VALUE_REQUIRED, + 'Use alternative directory for saving dump' + ); parent::configure(); } @@ -116,7 +123,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->logger->info('Starting backup.'); $this->dumpProcessor->execute( (bool)$input->getOption(self::OPTION_REMOVE_DEFINERS), - $databases + $databases, + (string)$input->getOption(self::OPTION_DUMP_DIRECTORY) ); $this->logger->info('Backup completed.'); } catch (\Exception $exception) { diff --git a/src/Config/Log.php b/src/Config/Log.php index 60fbf421de..58995095d4 100644 --- a/src/Config/Log.php +++ b/src/Config/Log.php @@ -82,9 +82,7 @@ public function __construct( * Returns array of handlers configs with keys as handler name. * * @return array - * @throws FileSystemException - * @throws UndefinedPackageException - * @throws ParseException + * @throws ConfigException */ public function getHandlers(): array { @@ -94,40 +92,44 @@ public function getHandlers(): array /** * @param string $handler * @return Repository - * @throws \Exception + * @throws ConfigException */ public function get(string $handler): Repository { - if (!isset($this->getConfig()[$handler])) { - throw new \Exception('Configuration for ' . $handler . ' is not found'); + $config = $this->getConfig(); + + if (!isset($config[$handler])) { + throw new ConfigException('Configuration for ' . $handler . ' is not found'); } return $this->repositoryFactory->create( - $this->getConfig()[$handler] + $config[$handler] ); } /** * @return array - * @throws ParseException - * @throws FileSystemException - * @throws UndefinedPackageException + * @throws ConfigException */ private function getConfig(): array { - if ($this->config === null) { - $this->config = array_replace_recursive( - [ - HandlerFactory::HANDLER_STREAM => ['stream' => 'php://stdout'], - HandlerFactory::HANDLER_FILE => ['file' => $this->fileList->getCloudLog()], - HandlerFactory::HANDLER_FILE_ERROR => [ - 'file' => $this->fileList->getCloudErrorLog(), - 'min_level' => self::LEVEL_WARNING, - 'formatter' => $this->errorFormatterFactory->create() + try { + if ($this->config === null) { + $this->config = array_replace_recursive( + [ + HandlerFactory::HANDLER_STREAM => ['stream' => 'php://stdout'], + HandlerFactory::HANDLER_FILE => ['file' => $this->fileList->getCloudLog()], + HandlerFactory::HANDLER_FILE_ERROR => [ + 'file' => $this->fileList->getCloudErrorLog(), + 'min_level' => self::LEVEL_WARNING, + 'formatter' => $this->errorFormatterFactory->create() + ], ], - ], - $this->reader->read()[static::SECTION_CONFIG] ?? [] - ); + $this->reader->read()[static::SECTION_CONFIG] ?? [] + ); + } + } catch (ParseException | FileSystemException | UndefinedPackageException $exception) { + throw new ConfigException($exception->getMessage(), $exception->getCode(), $exception); } return $this->config; diff --git a/src/Config/Validator/Build/ComposerFile.php b/src/Config/Validator/Build/ComposerFile.php index a5e4ca61cc..0b213c551d 100644 --- a/src/Config/Validator/Build/ComposerFile.php +++ b/src/Config/Validator/Build/ComposerFile.php @@ -84,7 +84,7 @@ public function __construct( public function validate(): Validator\ResultInterface { try { - if (!$this->magentoVersion->isGreaterOrEqual('2.3')) { + if (!$this->magentoVersion->isGreaterOrEqual('2.3') || $this->magentoVersion->isGreaterOrEqual('2.4.3')) { return $this->resultFactory->success(); } diff --git a/src/DB/DumpGenerator.php b/src/DB/DumpGenerator.php index 7cfe85681a..ec40f33107 100644 --- a/src/DB/DumpGenerator.php +++ b/src/DB/DumpGenerator.php @@ -85,14 +85,20 @@ public function __construct( * @param string $database * @param ConnectionInterface $connectionData * @param bool $removeDefiners + * @param string $alternativeDestination * * @throws UndefinedPackageException * @throws ShellException */ - public function create(string $database, ConnectionInterface $connectionData, bool $removeDefiners) - { + public function create( + string $database, + ConnectionInterface $connectionData, + bool $removeDefiners, + string $alternativeDestination + ) { $dumpFileName = sprintf(self::DUMP_FILE_NAME_TEMPLATE, $database, time()); - $temporaryDirectory = sys_get_temp_dir(); + $temporaryDirectory = !empty($alternativeDestination) ? $alternativeDestination + : $this->directoryList->getVar(); $dumpFile = $temporaryDirectory . '/' . $dumpFileName; $lockFile = $this->directoryList->getVar() . '/' . self::LOCK_FILE_NAME; diff --git a/src/DB/DumpProcessor.php b/src/DB/DumpProcessor.php index b1ae5ee84b..ab011df485 100644 --- a/src/DB/DumpProcessor.php +++ b/src/DB/DumpProcessor.php @@ -126,13 +126,14 @@ public function __construct( * * @param array $databases * @param bool $removeDefiners + * @param string $alternativeDestination * * @throws ConfigException * @throws FileSystemException * @throws GenericException * @throws UndefinedPackageException */ - public function execute(bool $removeDefiners, array $databases = []) + public function execute(bool $removeDefiners, array $databases = [], string $alternativeDestination = '') { try { if (empty($databases)) { @@ -157,7 +158,8 @@ public function execute(bool $removeDefiners, array $databases = []) $this->dumpGenerator->create( self::DATABASE_MAP[$connection], $this->connectionFactory->create($connection), - $removeDefiners + $removeDefiners, + $alternativeDestination ); } } finally { diff --git a/src/Step/ValidateConfiguration.php b/src/Step/ValidateConfiguration.php index 551be7f692..893c24c512 100644 --- a/src/Step/ValidateConfiguration.php +++ b/src/Step/ValidateConfiguration.php @@ -89,6 +89,7 @@ private function collectErrors(): array /* @var $validators ValidatorInterface[] */ foreach ($this->validators as $level => $validators) { + /** @phpstan-ignore-next-line */ $level = Logger::toMonologLevel($level); foreach ($validators as $name => $validator) { if (!$validator instanceof ValidatorInterface) { diff --git a/src/Test/Functional/Acceptance/AcceptanceCe71Cest.php b/src/Test/Functional/Acceptance/Acceptance72Ce22Cest.php similarity index 76% rename from src/Test/Functional/Acceptance/AcceptanceCe71Cest.php rename to src/Test/Functional/Acceptance/Acceptance72Ce22Cest.php index b17a6ecd3f..33e40a4d44 100644 --- a/src/Test/Functional/Acceptance/AcceptanceCe71Cest.php +++ b/src/Test/Functional/Acceptance/Acceptance72Ce22Cest.php @@ -14,13 +14,13 @@ /** * @inheritDoc * - * @group php71 + * @group php72 * @group edition-ce */ -class AcceptanceCe71Cest extends AcceptanceCeCest +class Acceptance72Ce22Cest extends AcceptanceCeCest { /** * @var string */ - protected $magentoCloudTemplate = '2.2.9'; + protected $magentoCloudTemplate = '2.2.10'; } diff --git a/src/Test/Functional/Acceptance/AdminCredential21Cest.php b/src/Test/Functional/Acceptance/AdminCredential21Cest.php deleted file mode 100644 index 3ff42875fe..0000000000 --- a/src/Test/Functional/Acceptance/AdminCredential21Cest.php +++ /dev/null @@ -1,19 +0,0 @@ -expectedLogs, [ 'INFO: Start creation DB dump for main database...', - 'INFO: Finished DB dump for main database, it can be found here: /tmp/dump-main', + 'INFO: Finished DB dump for main database, it can be found here: /app/var/dump-main', ] )); $I->doNotSeeInOutput(['quote', 'sales']); @@ -153,11 +153,11 @@ private function partRunDbDumpWithSplitDbArch(CliTester $I) $this->expectedLogs, [ 'INFO: Start creation DB dump for main database...', - 'INFO: Finished DB dump for main database, it can be found here: /tmp/dump-main', + 'INFO: Finished DB dump for main database, it can be found here: /app/var/dump-main', 'INFO: Start creation DB dump for quote database...', - 'INFO: Finished DB dump for quote database, it can be found here: /tmp/dump-quote', + 'INFO: Finished DB dump for quote database, it can be found here: /app/var/dump-quote', 'INFO: Start creation DB dump for sales database...', - 'INFO: Finished DB dump for sales database, it can be found here: /tmp/dump-sales', + 'INFO: Finished DB dump for sales database, it can be found here: /app/var/dump-sales', ] )); @@ -167,9 +167,9 @@ private function partRunDbDumpWithSplitDbArch(CliTester $I) $this->expectedLogs, [ 'INFO: Start creation DB dump for quote database...', - 'INFO: Finished DB dump for quote database, it can be found here: /tmp/dump-quote', + 'INFO: Finished DB dump for quote database, it can be found here: /app/var/dump-quote', 'INFO: Start creation DB dump for sales database...', - 'INFO: Finished DB dump for sales database, it can be found here: /tmp/dump-sales', + 'INFO: Finished DB dump for sales database, it can be found here: /app/var/dump-sales', ] )); $I->doNotSeeInOutput('main'); diff --git a/src/Test/Functional/Acceptance/Cron21Cest.php b/src/Test/Functional/Acceptance/Cron21Cest.php deleted file mode 100644 index 5a8c18d279..0000000000 --- a/src/Test/Functional/Acceptance/Cron21Cest.php +++ /dev/null @@ -1,32 +0,0 @@ - '2.1.18', - 'variables' => [ - 'MAGENTO_CLOUD_VARIABLES' => [ - 'ADMIN_EMAIL' => 'admin@example.com', - 'ADMIN_LOCALE' => 'ar_KW' - ], - ], - ], - ]; - } -} diff --git a/src/Test/Functional/Acceptance/Cron22Cest.php b/src/Test/Functional/Acceptance/Cron22Cest.php index 6e38fa1fc3..4360a00095 100644 --- a/src/Test/Functional/Acceptance/Cron22Cest.php +++ b/src/Test/Functional/Acceptance/Cron22Cest.php @@ -8,7 +8,7 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; /** - * @group php71 + * @group php72 */ class Cron22Cest extends CronCest { @@ -19,7 +19,7 @@ protected function cronDataProvider(): array { return [ [ - 'version' => '2.2.0', + 'version' => '2.2.10', 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'ADMIN_EMAIL' => 'admin@example.com', @@ -28,32 +28,14 @@ protected function cronDataProvider(): array ], ], [ - 'version' => '2.2.4', + 'version' => '2.2.11', 'variables' => [ 'MAGENTO_CLOUD_VARIABLES' => [ 'ADMIN_EMAIL' => 'admin@example.com', 'ADMIN_LOCALE' => 'ar_KW' ], ], - ], - [ - 'version' => '2.2.5', - 'variables' => [ - 'MAGENTO_CLOUD_VARIABLES' => [ - 'ADMIN_EMAIL' => 'admin@example.com', - 'ADMIN_LOCALE' => 'ar_KW' - ], - ], - ], - [ - 'version' => '2.2.8', - 'variables' => [ - 'MAGENTO_CLOUD_VARIABLES' => [ - 'ADMIN_EMAIL' => 'admin@example.com', - 'ADMIN_LOCALE' => 'fr_FR' - ], - ], - ], + ] ]; } } diff --git a/src/Test/Functional/Acceptance/ElasticSearch22Cest.php b/src/Test/Functional/Acceptance/ElasticSearch22Cest.php index 04b28d3f7d..35deff0d9e 100644 --- a/src/Test/Functional/Acceptance/ElasticSearch22Cest.php +++ b/src/Test/Functional/Acceptance/ElasticSearch22Cest.php @@ -8,7 +8,7 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; /** - * @group php71 + * @group php72 */ class ElasticSearch22Cest extends ElasticSearchCest { @@ -19,12 +19,12 @@ protected function elasticDataProvider(): array { return [ [ - 'magento' => '2.2.8', + 'magento' => '2.2.10', 'removeES' => true, 'expectedResult' => ['engine' => 'mysql'], ], [ - 'magento' => '2.2.8', + 'magento' => '2.2.10', 'removeES' => false, 'expectedResult' => [ 'engine' => 'elasticsearch6', diff --git a/src/Test/Functional/Acceptance/RedisPhp71Cest.php b/src/Test/Functional/Acceptance/RedisPhp72M22Cest.php similarity index 92% rename from src/Test/Functional/Acceptance/RedisPhp71Cest.php rename to src/Test/Functional/Acceptance/RedisPhp72M22Cest.php index a2a6a15bdc..2b603f8a74 100644 --- a/src/Test/Functional/Acceptance/RedisPhp71Cest.php +++ b/src/Test/Functional/Acceptance/RedisPhp72M22Cest.php @@ -8,9 +8,9 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; /** - * @group php71 + * @group php72 */ -class RedisPhp71Cest extends RedisCest +class RedisPhp72M22Cest extends RedisCest { /** * @return array @@ -19,7 +19,7 @@ protected function defaultConfigurationDataProvider(): array { return [ [ - 'version' => '2.2.9', + 'version' => '2.2.10', ], ]; } @@ -31,7 +31,7 @@ protected function wrongConfigurationDataProvider(): array { return [ [ - 'version' => '2.2.9', + 'version' => '2.2.10', 'wrongConfiguration' => [ 'stage' => [ 'deploy' => [ @@ -46,7 +46,7 @@ protected function wrongConfigurationDataProvider(): array . '\'\Magento\Framework\Cache\Backend\Redis\'', ], [ - 'version' => '2.2.9', + 'version' => '2.2.10', 'wrongConfiguration' => [ 'stage' => [ 'deploy' => [ @@ -71,7 +71,7 @@ protected function goodConfigurationDataProvider(): array { return [ [ - 'version' => '2.2.9', + 'version' => '2.2.10', 'backendModel' => [ 'stage' => [ 'deploy' => [ diff --git a/src/Test/Functional/Acceptance/Upgrade21Cest.php b/src/Test/Functional/Acceptance/Upgrade21Cest.php deleted file mode 100644 index 7abe8c4f6e..0000000000 --- a/src/Test/Functional/Acceptance/Upgrade21Cest.php +++ /dev/null @@ -1,67 +0,0 @@ -prepareWorkplace($I, $data['from']); - $I->generateDockerCompose('--mode=production'); - $this->assert($I); - $I->assertTrue($I->cleanDirectories(['/vendor/*', '/setup/*'])); - $I->stopEnvironment(true); - $I->addDependencyToComposer('magento/magento-cloud-metapackage', $data['to']); - $I->composerUpdate(); - $this->assert($I); - } - - /** - * @param \CliTester $I - * @throws \Robo\Exception\TaskException - */ - protected function assert(\CliTester $I): void - { - - $I->runDockerComposeCommand('run build cloud-build'); - $I->startEnvironment(); - $I->runDockerComposeCommand('run deploy cloud-deploy'); - $I->runDockerComposeCommand('run deploy cloud-post-deploy'); - - $I->amOnPage('/'); - $I->see('Home page'); - $I->see('CMS homepage content goes here.'); - } - - /** - * @return array - */ - protected function testProvider(): array - { - return [ - ['from' => '2.1.16', 'to' => '>=2.2.0 <2.2.1'] - ]; - } -} diff --git a/src/Test/Functional/Acceptance/Upgrade22Cest.php b/src/Test/Functional/Acceptance/Upgrade22Cest.php index 033e5dcf7b..ac7acb7b14 100644 --- a/src/Test/Functional/Acceptance/Upgrade22Cest.php +++ b/src/Test/Functional/Acceptance/Upgrade22Cest.php @@ -8,17 +8,60 @@ namespace Magento\MagentoCloud\Test\Functional\Acceptance; /** - * @group php71 + * @group php72 */ -class Upgrade22Cest extends Upgrade21Cest +class Upgrade22Cest extends AbstractCest { + /** + * @param \CliTester $I + */ + public function _before(\CliTester $I): void + { + // Do nothing... + } + + /** + * @param \CliTester $I + * @param \Codeception\Example $data + * @throws \Robo\Exception\TaskException + * @dataProvider testProvider + */ + public function test(\CliTester $I, \Codeception\Example $data): void + { + $this->prepareWorkplace($I, $data['from']); + $I->generateDockerCompose('--mode=production'); + $this->assert($I); + $I->assertTrue($I->cleanDirectories(['/vendor/*', '/setup/*'])); + $I->stopEnvironment(true); + $I->addDependencyToComposer('magento/magento-cloud-metapackage', $data['to']); + $I->composerUpdate(); + $this->assert($I); + } + + /** + * @param \CliTester $I + * @throws \Robo\Exception\TaskException + */ + protected function assert(\CliTester $I): void + { + + $I->runDockerComposeCommand('run build cloud-build'); + $I->startEnvironment(); + $I->runDockerComposeCommand('run deploy cloud-deploy'); + $I->runDockerComposeCommand('run deploy cloud-post-deploy'); + + $I->amOnPage('/'); + $I->see('Home page'); + $I->see('CMS homepage content goes here.'); + } + /** * @return array */ protected function testProvider(): array { return [ - ['from' => '2.2.0', 'to' => '2.2.*'] + ['from' => '2.2.10', 'to' => '2.2.*'] ]; } } diff --git a/src/Test/Functional/Acceptance/Upgrade23Cest.php b/src/Test/Functional/Acceptance/Upgrade23Cest.php index 71118df21a..2997559162 100644 --- a/src/Test/Functional/Acceptance/Upgrade23Cest.php +++ b/src/Test/Functional/Acceptance/Upgrade23Cest.php @@ -10,7 +10,7 @@ /** * @group php72 */ -class Upgrade23Cest extends Upgrade21Cest +class Upgrade23Cest extends Upgrade22Cest { /** * @return array diff --git a/src/Test/Functional/Acceptance/UpgradeCest.php b/src/Test/Functional/Acceptance/UpgradeCest.php index 9d0ac24b2b..ebac0e8c73 100644 --- a/src/Test/Functional/Acceptance/UpgradeCest.php +++ b/src/Test/Functional/Acceptance/UpgradeCest.php @@ -12,7 +12,7 @@ * * @group php73 */ -class UpgradeCest extends Upgrade21Cest +class UpgradeCest extends Upgrade22Cest { /** * @var boolean diff --git a/src/Test/Unit/App/Logger/Formatter/JsonErrorFormatterTest.php b/src/Test/Unit/App/Logger/Formatter/JsonErrorFormatterTest.php index 3bf3a5f5be..2ba7383e3a 100644 --- a/src/Test/Unit/App/Logger/Formatter/JsonErrorFormatterTest.php +++ b/src/Test/Unit/App/Logger/Formatter/JsonErrorFormatterTest.php @@ -14,9 +14,6 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * @inheritDoc - */ class JsonErrorFormatterTest extends TestCase { /** @@ -37,7 +34,7 @@ class JsonErrorFormatterTest extends TestCase /** * @inheritDoc */ - protected function setUp() + protected function setUp(): void { $this->errorInfoMock = $this->createMock(ErrorInfo::class); $this->readerMock = $this->getMockForAbstractClass(ReaderInterface::class); @@ -48,7 +45,7 @@ protected function setUp() ); } - public function testFormat() + public function testFormat(): void { $this->readerMock->expects($this->once()) ->method('read') @@ -67,7 +64,7 @@ public function testFormat() ); } - public function testFormatEmptyError() + public function testFormatEmptyError(): void { $this->readerMock->expects($this->once()) ->method('read') @@ -86,7 +83,7 @@ public function testFormatEmptyError() ); } - public function testFormatMessageAlreadyLogged() + public function testFormatMessageAlreadyLogged(): void { $this->readerMock->expects($this->once()) ->method('read') @@ -96,27 +93,27 @@ public function testFormatMessageAlreadyLogged() $this->errorInfoMock->expects($this->never()) ->method('get'); - $this->assertFalse( + $this->assertEmpty( $this->jsonErrorFormatter->format(['message' => 'some error', 'context' => ['errorCode' => 11]]) ); } - public function testFormatNoErrorCode() + public function testFormatNoErrorCode(): void { $this->readerMock->expects($this->never()) ->method('read'); $this->errorInfoMock->expects($this->never()) ->method('get'); - $this->assertFalse($this->jsonErrorFormatter->format(['message' => 'test'])); + $this->assertEmpty($this->jsonErrorFormatter->format(['message' => 'test'])); } - public function testFormatWithException() + public function testFormatWithException(): void { $this->readerMock->expects($this->once()) ->method('read') ->willThrowException(new FileSystemException('error')); - $this->assertFalse($this->jsonErrorFormatter->format(['message' => 'test', 'context' => ['errorCode' => 11]])); + $this->assertEmpty($this->jsonErrorFormatter->format(['message' => 'test', 'context' => ['errorCode' => 11]])); } } diff --git a/src/Test/Unit/App/Logger/HandlerFactoryTest.php b/src/Test/Unit/App/Logger/HandlerFactoryTest.php index 81c666b3b0..ba64619121 100644 --- a/src/Test/Unit/App/Logger/HandlerFactoryTest.php +++ b/src/Test/Unit/App/Logger/HandlerFactoryTest.php @@ -11,7 +11,6 @@ use Magento\MagentoCloud\App\Logger\Gelf\Handler as GelfHandler; use Magento\MagentoCloud\App\Logger\Gelf\HandlerFactory as GelfHandlerFactory; use Magento\MagentoCloud\App\Logger\HandlerFactory; -use Magento\MagentoCloud\App\Logger\LevelResolver; use Magento\MagentoCloud\Config\GlobalSection; use Magento\MagentoCloud\Config\Log as LogConfig; use Monolog\Handler\AbstractHandler; @@ -26,16 +25,10 @@ use PHPUnit\Framework\TestCase; /** - * @inheritdoc - * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class HandlerFactoryTest extends TestCase { - /** - * @var LevelResolver|MockObject - */ - private $levelResolverMock; /** * @var LogConfig|MockObject @@ -67,14 +60,12 @@ class HandlerFactoryTest extends TestCase */ protected function setUp() { - $this->levelResolverMock = $this->createMock(LevelResolver::class); $this->logConfigMock = $this->createMock(LogConfig::class); $this->repositoryMock = $this->createMock(Repository::class); $this->gelfHandlerFactoryMock = $this->createMock(GelfHandlerFactory::class); $this->globalConfigMock = $this->createMock(GlobalSection::class); $this->handlerFactory = new HandlerFactory( - $this->levelResolverMock, $this->logConfigMock, $this->gelfHandlerFactoryMock, $this->globalConfigMock @@ -97,12 +88,6 @@ public function testCreateWithWrongHandlerFromFile() ['min_level', LogConfig::LEVEL_NOTICE, LogConfig::LEVEL_NOTICE], ['min_level', LogConfig::LEVEL_INFO, LogConfig::LEVEL_INFO], ]); - $this->levelResolverMock - ->method('resolve') - ->willReturnMap([ - [LogConfig::LEVEL_NOTICE, Logger::NOTICE], - [LogConfig::LEVEL_INFO, Logger::INFO] - ]); $this->handlerFactory->create($handler); } @@ -154,14 +139,6 @@ public function testCreate( ->method('get') ->with(GlobalSection::VAR_MIN_LOGGING_LEVEL) ->willReturn($minLevelOverride); - $this->levelResolverMock - ->method('resolve') - ->willReturnMap([ - [LogConfig::LEVEL_NOTICE, Logger::NOTICE], - [LogConfig::LEVEL_INFO, Logger::INFO], - [LogConfig::LEVEL_WARNING, Logger::WARNING], - [LogConfig::LEVEL_DEBUG, Logger::DEBUG], - ]); /** @var AbstractHandler $handler */ $handler = $this->handlerFactory->create($handlerName); @@ -225,8 +202,8 @@ public function createDataProvider() 'handler' => HandlerFactory::HANDLER_FILE, 'repositoryMockReturnMap' => [ ['file', null, 'var/log/cloud.log'], - ['min_level', LogConfig::LEVEL_NOTICE, LogConfig::LEVEL_INFO], - ['min_level', LogConfig::LEVEL_DEBUG, LogConfig::LEVEL_INFO], + ['min_level', null, LogConfig::LEVEL_INFO], + ['min_level', null, LogConfig::LEVEL_INFO], ], 'minLevelOverride' => '', 'expectedClass' => StreamHandler::class, @@ -236,8 +213,7 @@ public function createDataProvider() 'handler' => HandlerFactory::HANDLER_FILE, 'repositoryMockReturnMap' => [ ['file', null, 'var/log/cloud.log'], - ['min_level', LogConfig::LEVEL_INFO, LogConfig::LEVEL_DEBUG], - ['min_level', LogConfig::LEVEL_DEBUG, LogConfig::LEVEL_DEBUG], + ['min_level', null, LogConfig::LEVEL_DEBUG] ], 'minLevelOverride' => LogConfig::LEVEL_INFO, 'expectedClass' => StreamHandler::class, @@ -273,7 +249,7 @@ public function createDataProvider() 'repositoryMockReturnMap' => [ ['to', null, 'user@example.com'], ['from', null, 'user2@example.com'], - ['subject', 'Log form Magento Cloud', 'someSubject'], + ['subject', 'Log from Magento Cloud', 'someSubject'], ['min_level', LogConfig::LEVEL_NOTICE, LogConfig::LEVEL_NOTICE], ['min_level', LogConfig::LEVEL_INFO, LogConfig::LEVEL_INFO], ], diff --git a/src/Test/Unit/App/Logger/LevelResolverTest.php b/src/Test/Unit/App/Logger/LevelResolverTest.php deleted file mode 100644 index cc7a5516e7..0000000000 --- a/src/Test/Unit/App/Logger/LevelResolverTest.php +++ /dev/null @@ -1,77 +0,0 @@ -environmentMock = $this->createMock(Environment::class); - - $this->levelResolver = new LevelResolver($this->environmentMock); - } - - /** - * @param string $level - * @param int $expectedResult - * @dataProvider resolveDataProvider - */ - public function testResolve(string $level, int $expectedResult) - { - $this->assertSame($expectedResult, $this->levelResolver->resolve($level)); - } - - /** - * @return array - */ - public function resolveDataProvider(): array - { - return [ - ['level' => 'debug', Logger::DEBUG], - ['level' => 'info', Logger::INFO], - ['level' => 'notice', Logger::NOTICE], - ['level' => 'warning', Logger::WARNING], - ['level' => 'error', Logger::ERROR], - ['level' => 'critical', Logger::CRITICAL], - ['level' => 'alert', Logger::ALERT], - ['level' => 'emergency', Logger::EMERGENCY], - ['level' => 'someLevel', Logger::NOTICE], - ['level' => 'debUg', Logger::DEBUG], - ['level' => 'INFO', Logger::INFO], - ['level' => 'noTice', Logger::NOTICE], - ['level' => 'waRning', Logger::WARNING], - ['level' => 'errOr', Logger::ERROR], - ['level' => 'criTical', Logger::CRITICAL], - ['level' => 'alErt', Logger::ALERT], - ['level' => 'Emergency', Logger::EMERGENCY], - ['level' => 'invalid', Logger::NOTICE], - ]; - } -} diff --git a/src/Test/Unit/App/Logger/PoolTest.php b/src/Test/Unit/App/Logger/PoolTest.php index ab02653754..4bc9f49512 100644 --- a/src/Test/Unit/App/Logger/PoolTest.php +++ b/src/Test/Unit/App/Logger/PoolTest.php @@ -14,15 +14,12 @@ use Magento\MagentoCloud\App\LoggerException; use Magento\MagentoCloud\App\Logger\Formatter\LineFormatter; use Magento\MagentoCloud\App\Logger\HandlerFactory; -use Monolog\Handler\HandlerInterface; use Magento\MagentoCloud\Config\Log as LogConfig; +use Monolog\Handler\AbstractProcessingHandler; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Yaml\Exception\ParseException; -/** - * @inheritdoc - */ class PoolTest extends TestCase { /** @@ -60,7 +57,7 @@ protected function setUp() /** * @throws \Exception */ - public function testGetHandlers() + public function testGetHandlers(): void { $jsonErrorFormatterMock = $this->createMock(JsonErrorFormatter::class); $this->logConfigMock->expects($this->once()) @@ -77,20 +74,52 @@ public function testGetHandlers() ->method('create') ->willReturn($formatterMock); - $slackHandlerMock = $this->getMockForAbstractClass(HandlerInterface::class); + $slackHandlerMock = $this->getMockForAbstractClass( + AbstractProcessingHandler::class, + [], + '', + true, + true, + true, + ['setFormatter'] + ); $slackHandlerMock->expects($this->once()) ->method('setFormatter') ->with($formatterMock) ->willReturnSelf(); - $emailHandlerMock = $this->getMockForAbstractClass(HandlerInterface::class); + $emailHandlerMock = $this->getMockForAbstractClass( + AbstractProcessingHandler::class, + [], + '', + true, + true, + true, + ['setFormatter'] + ); $emailHandlerMock->expects($this->once()) ->method('setFormatter') ->with($formatterMock) ->willReturnSelf(); - $syslogHandler = $this->getMockForAbstractClass(HandlerInterface::class); + $syslogHandler = $this->getMockForAbstractClass( + AbstractProcessingHandler::class, + [], + '', + true, + true, + true, + ['setFormatter'] + ); $syslogHandler->expects($this->never()) ->method('setFormatter'); - $errorHandler = $this->getMockForAbstractClass(HandlerInterface::class); + $errorHandler = $this->getMockForAbstractClass( + AbstractProcessingHandler::class, + [], + '', + true, + true, + true, + ['setFormatter'] + ); $errorHandler->expects($this->once()) ->method('setFormatter') ->with($jsonErrorFormatterMock) diff --git a/src/Test/Unit/Config/Validator/Build/ComposerFileTest.php b/src/Test/Unit/Config/Validator/Build/ComposerFileTest.php index 6b36a98d04..c64b03ac43 100644 --- a/src/Test/Unit/Config/Validator/Build/ComposerFileTest.php +++ b/src/Test/Unit/Config/Validator/Build/ComposerFileTest.php @@ -68,14 +68,14 @@ protected function setUp(): void } /** - * @throws UndefinedPackageException + * @inheritdoc */ public function testValidateCorrectComposerJson(): void { - $this->magentoVersionMock->expects($this->once()) + $this->magentoVersionMock->expects($this->exactly(2)) ->method('isGreaterOrEqual') - ->with('2.3') - ->willReturn(true); + ->withConsecutive(['2.3'], ['2.4.3']) + ->willReturnOnConsecutiveCalls(true, false); $this->fileListMock->expects($this->once()) ->method('getMagentoComposer') ->willReturn(__DIR__ . '/_files/correct_composer_2.3.json'); @@ -86,14 +86,14 @@ public function testValidateCorrectComposerJson(): void } /** - * @throws UndefinedPackageException + * @inheritdoc */ public function testValidateCorrectLaminasComposerJson(): void { - $this->magentoVersionMock->expects($this->once()) + $this->magentoVersionMock->expects($this->exactly(2)) ->method('isGreaterOrEqual') - ->with('2.3') - ->willReturn(true); + ->withConsecutive(['2.3'], ['2.4.3']) + ->willReturnOnConsecutiveCalls(true, false); $this->fileListMock->expects($this->once()) ->method('getMagentoComposer') ->willReturn(__DIR__ . '/_files/correct_composer_2.3_2.json'); @@ -104,14 +104,32 @@ public function testValidateCorrectLaminasComposerJson(): void } /** - * @throws UndefinedPackageException + * @inheritdoc + */ + public function testValidateCorrectAutoload243ComposerJson(): void + { + $this->magentoVersionMock->expects($this->exactly(2)) + ->method('isGreaterOrEqual') + ->withConsecutive(['2.3'], ['2.4.3']) + ->willReturnOnConsecutiveCalls(true, false); + $this->fileListMock->expects($this->once()) + ->method('getMagentoComposer') + ->willReturn(__DIR__ . '/_files/correct_composer_2.3_2.json'); + $this->resultFactoryMock->expects($this->once()) + ->method('success'); + + $this->validator->validate(); + } + + /** + * @inheritdoc */ public function testValidateWrongComposerJson(): void { - $this->magentoVersionMock->expects($this->once()) + $this->magentoVersionMock->expects($this->exactly(2)) ->method('isGreaterOrEqual') - ->with('2.3') - ->willReturn(true); + ->withConsecutive(['2.3'], ['2.4.3']) + ->willReturnOnConsecutiveCalls(true, false); $this->fileListMock->expects($this->once()) ->method('getMagentoComposer') ->willReturn(__DIR__ . '/_files/wrong_composer_2.3.json'); @@ -133,14 +151,14 @@ public function testValidateWrongComposerJson(): void } /** - * @throws UndefinedPackageException + * @inheritdoc */ public function testValidateMagentoLower23(): void { - $this->magentoVersionMock->expects($this->once()) + $this->magentoVersionMock->expects($this->exactly(1)) ->method('isGreaterOrEqual') - ->with('2.3') - ->willReturn(false); + ->withConsecutive(['2.3']) + ->willReturnOnConsecutiveCalls(false); $this->fileListMock->expects($this->never()) ->method('getMagentoComposer'); $this->resultFactoryMock->expects($this->once()) @@ -150,14 +168,31 @@ public function testValidateMagentoLower23(): void } /** - * @throws UndefinedPackageException + * @inheritdoc + */ + public function testValidateMagentoHigherEqual243(): void + { + $this->magentoVersionMock->expects($this->exactly(2)) + ->method('isGreaterOrEqual') + ->withConsecutive(['2.3'], ['2.4.3']) + ->willReturnOnConsecutiveCalls(true, true); + $this->fileListMock->expects($this->never()) + ->method('getMagentoComposer'); + $this->resultFactoryMock->expects($this->once()) + ->method('success'); + + $this->validator->validate(); + } + + /** + * @inheritdoc */ public function testValidateComposerFileNotExists(): void { - $this->magentoVersionMock->expects($this->once()) + $this->magentoVersionMock->expects($this->exactly(2)) ->method('isGreaterOrEqual') - ->with('2.3') - ->willReturn(true); + ->withConsecutive(['2.3'], ['2.4.3']) + ->willReturnOnConsecutiveCalls(true, false); $this->fileListMock->expects($this->once()) ->method('getMagentoComposer') ->willReturn(__DIR__ . '/_files/file_not_exists.json'); diff --git a/src/Test/Unit/DB/DumpGeneratorTest.php b/src/Test/Unit/DB/DumpGeneratorTest.php index 589d52502b..b27114299a 100644 --- a/src/Test/Unit/DB/DumpGeneratorTest.php +++ b/src/Test/Unit/DB/DumpGeneratorTest.php @@ -132,7 +132,7 @@ public function testCreate(bool $removeDefiners) $dumpFilePath, $removeDefiners )); - $this->dumpGenerator->create('main', $this->connectionDataMock, $removeDefiners); + $this->dumpGenerator->create('main', $this->connectionDataMock, $removeDefiners, ''); } /** @@ -173,7 +173,7 @@ public function testCreateWithException() )) ->willThrowException($exception); $this->expectExceptionObject($exception); - $this->dumpGenerator->create('main', $this->connectionDataMock, false); + $this->dumpGenerator->create('main', $this->connectionDataMock, false, ''); } public function testFailedCreationLockFile() @@ -190,7 +190,7 @@ public function testFailedCreationLockFile() ->with('Could not get the lock file!'); $this->shellMock->expects($this->never()) ->method('execute'); - $this->dumpGenerator->create('main', $this->connectionDataMock, false); + $this->dumpGenerator->create('main', $this->connectionDataMock, false, ''); } public function testLockedFile() @@ -207,7 +207,7 @@ public function testLockedFile() ); $this->shellMock->expects($this->never()) ->method('execute'); - $this->dumpGenerator->create('main', $this->connectionDataMock, false); + $this->dumpGenerator->create('main', $this->connectionDataMock, false, ''); } private function getDumpFilePath(string $type): string diff --git a/src/Test/Unit/Http/TransferStatsHandlerTest.php b/src/Test/Unit/Http/TransferStatsHandlerTest.php index 259c7408f4..a244c09562 100644 --- a/src/Test/Unit/Http/TransferStatsHandlerTest.php +++ b/src/Test/Unit/Http/TransferStatsHandlerTest.php @@ -15,6 +15,7 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\UriInterface; use Psr\Log\LoggerInterface; /** @@ -53,7 +54,14 @@ public function setUp() public function testStatHandlerRedirect() { - $mockRequest = $this->createMock(RequestInterface::class); + $mockUriInterface = $this->createMock(UriInterface::class); + $mockRequest = $this->getMockBuilder(RequestInterface::class) + ->disableOriginalConstructor() + ->setMethods(['getUri']) + ->getMockForAbstractClass(); + $mockRequest->expects($this->any()) + ->method('getUri') + ->willReturn($mockUriInterface); $mockResponse = $this->createMock(ResponseInterface::class); $stats = new TransferStats($mockRequest, $mockResponse); @@ -70,7 +78,20 @@ public function testStatHandlerRedirect() public function testStatHandlerTransferTime() { - $mockRequest = $this->createMock(RequestInterface::class); + $mockUriInterface = $this->getMockBuilder(UriInterface::class) + ->disableOriginalConstructor() + ->setMethods(['__toString']) + ->getMockForAbstractClass(); + $mockUriInterface->expects($this->any()) + ->method('__toString') + ->willReturn('/'); + $mockRequest = $this->getMockBuilder(RequestInterface::class) + ->disableOriginalConstructor() + ->setMethods(['getUri']) + ->getMockForAbstractClass(); + $mockRequest->expects($this->any()) + ->method('getUri') + ->willReturn($mockUriInterface); $stats = new TransferStats($mockRequest, null, 3.1415926); @@ -109,13 +130,24 @@ public function testStatHandlerTransferTime() public function testStatHandlerCurlStats() { - $mockRequest = $this->createMock(RequestInterface::class); + $mockUriInterface = $this->getMockBuilder(UriInterface::class) + ->disableOriginalConstructor() + ->setMethods(['__toString']) + ->getMockForAbstractClass(); + $mockUriInterface->expects($this->any()) + ->method('__toString') + ->willReturn('/customer'); + $mockRequest = $this->getMockBuilder(RequestInterface::class) + ->disableOriginalConstructor() + ->setMethods(['getUri']) + ->getMockForAbstractClass(); + $mockRequest->expects($this->any()) + ->method('getUri') + ->willReturn($mockUriInterface); $mockResponse = $this->createMock(ResponseInterface::class); $stats = new TransferStats($mockRequest, $mockResponse, 3.1415926, null, [CURLINFO_STARTTRANSFER_TIME => 0.62]); - $mockRequest->method('getUri') - ->wilLReturn('/customer'); $mockResponse->expects($this->once()) ->method('getStatusCode') ->willReturn(200); diff --git a/tests/functional/_data/modules/Magento/CronTest/composer.json b/tests/functional/_data/modules/Magento/CronTest/composer.json index 5634c71edf..fa4c7a84a1 100644 --- a/tests/functional/_data/modules/Magento/CronTest/composer.json +++ b/tests/functional/_data/modules/Magento/CronTest/composer.json @@ -2,7 +2,7 @@ "name": "magento/module-cron-test", "description": "N/A", "require": { - "php": "7.0.2|7.0.4|~7.0.6|~7.1.0" + "php": "~7.2.0" }, "type": "magento2-module", "version": "100.2.0", diff --git a/tests/static/phpcs-ruleset.xml b/tests/static/phpcs-ruleset.xml index b5ae2aa527..3875e88326 100644 --- a/tests/static/phpcs-ruleset.xml +++ b/tests/static/phpcs-ruleset.xml @@ -23,7 +23,9 @@ - + + Test + _files _file