Skip to content

Commit

Permalink
MAGECLOUD-4269: Refactor ValidateConfiguration to pass string levels (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
oshmyheliuk authored and shiftedreality committed Dec 5, 2019
1 parent 9e88440 commit 5f05f4e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
7 changes: 5 additions & 2 deletions scenario/build/generate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
<arguments>
<argument name="logger" xsi:type="object">Psr\Log\LoggerInterface</argument>
<argument name="validators" xsi:type="array">
<item name="500" xsi:type="array">
<item name="critical" xsi:type="array">
<item name="composer" xsi:type="object" priority="100">Magento\MagentoCloud\Config\Validator\Build\ComposerFile</item>
<item name="stage-config" xsi:type="object" priority="200">Magento\MagentoCloud\Config\Validator\Build\StageConfig</item>
</item>
<item name="300" xsi:type="array">
<item name="warning" xsi:type="array">
<item name="config-file-exists" xsi:type="object" priority="100">Magento\MagentoCloud\Config\Validator\Build\ConfigFileExists</item>
<item name="deprecated-ini" xsi:type="object" priority="200">Magento\MagentoCloud\Config\Validator\Build\UnsupportedBuildOptionsIni</item>
<item name="modules-exists" xsi:type="object" priority="300">Magento\MagentoCloud\Config\Validator\Build\ModulesExists</item>
<item name="appropriate-version" xsi:type="object" priority="400">Magento\MagentoCloud\Config\Validator\Build\AppropriateVersion</item>
<item name="scd-options-ignorance" xsi:type="object" priority="500">Magento\MagentoCloud\Config\Validator\Build\ScdOptionsIgnorance</item>
<item name="ideal-state" xsi:type="object" priority="600">Magento\MagentoCloud\Config\Validator\IdealState</item>
</item>
<item name="notice" xsi:type="array">
<item name="ideal-state" xsi:type="object" priority="600">Magento\MagentoCloud\Config\Validator\IdealState</item>
</item>
</argument>
</arguments>
</step>
Expand Down
6 changes: 3 additions & 3 deletions scenario/deploy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
<arguments>
<argument name="logger" xsi:type="object">Psr\Log\LoggerInterface</argument>
<argument name="validators" xsi:type="array">
<item name="500" xsi:type="array">
<item name="critical" xsi:type="array">
<item name="database-configuration" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\DatabaseConfiguration</item>
<item name="search-configuration" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\SearchConfiguration</item>
<item name="resource-configuration" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\ResourceConfiguration</item>
<item name="session-configuration" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\SessionConfiguration</item>
<item name="elasticsuite-integrity" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\ElasticSuiteIntegrity</item>
</item>
<item name="300" xsi:type="array">
<item name="warning" xsi:type="array">
<item name="report-dir-nesting-level" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\ReportDirNestingLevel</item>
<item name="admin-data" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\AdminData</item>
<item name="php-version" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\PhpVersion</item>
Expand All @@ -43,7 +43,7 @@
<item name="service-version" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\ServiceVersion</item>
<item name="service-eol-warning" xsi:type="object">ServiceEol.Warnings</item>
</item>
<item name="250" xsi:type="array">
<item name="notice" xsi:type="array">
<item name="service-eol-notice" xsi:type="object">ServiceEol.Notices</item>
</item>
</argument>
Expand Down
2 changes: 1 addition & 1 deletion scenario/post-deploy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<arguments>
<argument name="logger" xsi:type="object">Psr\Log\LoggerInterface</argument>
<argument name="validators" xsi:type="array">
<item name="300" xsi:type="array">
<item name="warning" xsi:type="array">
<item name="debug-logging" xsi:type="object" priority="100">Magento\MagentoCloud\Config\Validator\Deploy\DebugLogging</item>
</item>
</argument>
Expand Down
5 changes: 4 additions & 1 deletion src/Step/ValidateConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\MagentoCloud\Step;

use Magento\MagentoCloud\App\Logger;
use Magento\MagentoCloud\Config\Validator\Result\Error;
use Magento\MagentoCloud\Config\ValidatorInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -64,7 +65,8 @@ public function execute()
}

/**
* Returns all validation messages grouped by validation level
* Returns all validation messages grouped by validation level.
* Converts validation level to integer value using @see Logger::toMonologLevel() method
*
* @return array
*/
Expand All @@ -74,6 +76,7 @@ private function collectMessages(): array

/* @var $validators ValidatorInterface[] */
foreach ($this->validators as $level => $validators) {
$level = Logger::toMonologLevel($level);
foreach ($validators as $name => $validator) {
if (!$validator instanceof ValidatorInterface) {
$this->logger->info(sprintf('Validator "%s" was skipped', $name));
Expand Down
42 changes: 42 additions & 0 deletions src/Test/Unit/Step/ValidateConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,48 @@ public function testExecuteWithWarningAndCriticalMessage()
$step->execute();
}

public function testExecuteTypeStringLevel()
{
$this->expectException(StepException::class);
$this->expectExceptionMessage('Fix configuration with given suggestions');

$this->loggerMock->expects($this->once())
->method('notice')
->with('Validating configuration');
$this->loggerMock->expects($this->exactly(2))
->method('log')
->withConsecutive(
[
Logger::NOTICE,
'Fix configuration with given suggestions:'
. PHP_EOL . '- some notice'
. PHP_EOL . ' some notice suggestion'
],
[
Logger::WARNING,
'Fix configuration with given suggestions:'
. PHP_EOL . '- some warning'
. PHP_EOL . ' some warning suggestion'
]
);

$step = new ValidateConfiguration(
$this->loggerMock,
[
'critical' => [
$this->createValidatorWithError('Critical error', 'some critical suggestion'),
],
'warning' => [
$this->createValidatorWithError('some warning', 'some warning suggestion'),
],
'notice' => [
$this->createValidatorWithError('some notice', 'some notice suggestion'),
],
]
);
$step->execute();
}

/**
* @param string $error
* @param string $suggestion
Expand Down

0 comments on commit 5f05f4e

Please sign in to comment.