Skip to content

Commit

Permalink
Merge pull request #65 from spryker-sdk/bugfix/supesc-8668/fixed-eval…
Browse files Browse the repository at this point in the history
…uator-for-deprecated-features

SUPESC-8668 Fixed validation for deprecated features.
  • Loading branch information
vol4onok authored Jul 26, 2024
2 parents 1bd136d + d077de3 commit 9bb928a
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/checkers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ parameters:
minimum_allowed_shop_version_checker_doc_url: https://docs.spryker.com/docs/scos/dev/guidelines/keeping-a-project-upgradable/upgradability-guidelines/minimum-allowed-shop-version.html
minimum_allowed_shop_version_checker_version: '202204.0'
minimum_allowed_shop_version_checker_file: '%evaluator_dir%/data/minimum-allowed-package-versions.json'
deprecated_features_checker_file: '%evaluator_dir%/data/deprecated-features.json'

# Npm checker
npm_checker_doc_url: https://docs.spryker.com/docs/scos/dev/guidelines/keeping-a-project-upgradable/upgradability-guidelines/npm-checker.html
Expand Down
4 changes: 4 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ services:
arguments:
$minimumAllowedPackagesFile: '%minimum_allowed_shop_version_checker_file%'

SprykerSdk\Evaluator\Checker\MinimumShopVersionChecker\DeprecatedFeaturesReader:
arguments:
$deprecatedFeaturesFile: '%deprecated_features_checker_file%'

SprykerSdk\Evaluator\Checker\PluginsRegistrationWithRestrictionsChecker\PluginsRegistrationWithRestrictionsChecker:
arguments:
$checkerDocUrl: '%plugin_registration_checker_doc_url%'
Expand Down
1 change: 1 addition & 0 deletions data/deprecated-features.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["spryker-feature\/marketplace-cart-notes","spryker-feature\/custom-order-reference","spryker-feature\/configurable-bundle-note","spryker-feature\/content-item","spryker-feature\/category-image","spryker-feature\/customer-notes","spryker-feature\/development-integration","spryker-feature\/backup","spryker-feature\/data-export","spryker-feature\/multistore","spryker-feature\/product-promotions","spryker-feature\/persistent-cart","spryker-feature\/cart-notes","spryker-feature\/order-threshold","spryker-feature\/split-shipment","spryker-feature\/newsletter-subscription","spryker-feature\/discontinued-products","spryker-feature\/product-validity","spryker-feature\/content-based-shop-navigation","spryker-feature\/product-based-shop-navigation","spryker-feature\/spryker-core-e-commerce","spryker-feature\/purchaise-approval-not-in-october-release","spryker-feature\/raitings-review"]
46 changes: 46 additions & 0 deletions src/Checker/MinimumShopVersionChecker/DeprecatedFeaturesReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

declare(strict_types=1);

namespace SprykerSdk\Evaluator\Checker\MinimumShopVersionChecker;

use InvalidArgumentException;

class DeprecatedFeaturesReader
{
/**
* @var string
*/
protected string $deprecatedFeaturesFile;

/**
* @param string $deprecatedFeaturesFile
*/
public function __construct(string $deprecatedFeaturesFile)
{
$this->deprecatedFeaturesFile = $deprecatedFeaturesFile;
}

/**
* @throws \InvalidArgumentException
*
* @return array<string, string>
*/
public function getDeprecatedFeatures(): array
{
$content = file_get_contents($this->deprecatedFeaturesFile);

if ($content === false) {
throw new InvalidArgumentException(
sprintf('Unable to read file %s. Error: %s', $this->deprecatedFeaturesFile, error_get_last()['message'] ?? '-'),
);
}

return json_decode($content, true, 512, \JSON_THROW_ON_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class MinimumShopVersionChecker extends AbstractChecker
*/
public const MESSAGE_INVALID_PACKAGE = 'The package "%s" version %s is not supported. The minimum allowed version is %s';

/**
* @var string
*/
protected const MESSAGE_DEPRECATED_PACKAGE = 'The package "%s" is deprecated and not supported.';

/**
* @var string
*/
Expand Down Expand Up @@ -57,6 +62,11 @@ class MinimumShopVersionChecker extends AbstractChecker
*/
protected MinimumAllowedPackageVersionsReader $minimumAllowedPackageVersionsReader;

/**
* @var \SprykerSdk\Evaluator\Checker\MinimumShopVersionChecker\DeprecatedFeaturesReader
*/
protected DeprecatedFeaturesReader $deprecatedFeaturesReader;

/**
* @var string
*/
Expand All @@ -70,17 +80,20 @@ class MinimumShopVersionChecker extends AbstractChecker
/**
* @param \SprykerSdk\Evaluator\Reader\ComposerReaderInterface $composerReader
* @param \SprykerSdk\Evaluator\Checker\MinimumShopVersionChecker\MinimumAllowedPackageVersionsReader $minimumAllowedPackageVersionsReader
* @param \SprykerSdk\Evaluator\Checker\MinimumShopVersionChecker\DeprecatedFeaturesReader $deprecatedFeaturesReader
* @param string $minimumFeatureVersion
* @param string $checkerDocUrl
*/
public function __construct(
ComposerReaderInterface $composerReader,
MinimumAllowedPackageVersionsReader $minimumAllowedPackageVersionsReader,
DeprecatedFeaturesReader $deprecatedFeaturesReader,
string $minimumFeatureVersion,
string $checkerDocUrl = ''
) {
$this->composerReader = $composerReader;
$this->minimumAllowedPackageVersionsReader = $minimumAllowedPackageVersionsReader;
$this->deprecatedFeaturesReader = $deprecatedFeaturesReader;
$this->minimumFeatureVersion = $minimumFeatureVersion;
$this->checkerDocUrl = $checkerDocUrl;
}
Expand Down Expand Up @@ -163,6 +176,12 @@ protected function checkFeaturePackage(string $packageName, string $packageVersi
return null;
}

$deprecatedFeatures = $this->deprecatedFeaturesReader->getDeprecatedFeatures();

if (in_array($packageName, $deprecatedFeatures)) {
return $this->createDeprecatedViolation($packageName);
}

return $this->createViolation($packageName, $packageVersion, $this->minimumFeatureVersion);
}

Expand Down Expand Up @@ -201,6 +220,19 @@ protected function createViolation(string $packageName, string $packageVersion,
);
}

/**
* @param string $packageName
*
* @return \SprykerSdk\Evaluator\Dto\ViolationDto
*/
protected function createDeprecatedViolation(string $packageName): ViolationDto
{
return new ViolationDto(
sprintf(static::MESSAGE_DEPRECATED_PACKAGE, $packageName),
sprintf('%s', $packageName),
);
}

/**
* @return string
*/
Expand Down
4 changes: 3 additions & 1 deletion tests/Acceptance/Checker/MinimumShopVersionCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function testReturnViolationWhenProjectHasIssues(): void
+---+-----------------------------------------------------------------------------------------------------------------------+---------------------------------------+
| 1 | The package "spryker-feature/agent-assist" version 202203.0 is not supported. The minimum allowed version is 202204.0 | spryker-feature/agent-assist:202203.0 |
+---+-----------------------------------------------------------------------------------------------------------------------+---------------------------------------+
| 2 | The package "spryker/availability-gui" version 6.5.9 is not supported. The minimum allowed version is 6.6.0 | spryker/availability-gui:6.5.9 |
| 2 | The package "spryker-feature/customer-notes" is deprecated and not supported. | spryker-feature/customer-notes |
+---+-----------------------------------------------------------------------------------------------------------------------+---------------------------------------+
| 3 | The package "spryker/availability-gui" version 6.5.9 is not supported. The minimum allowed version is 6.6.0 | spryker/availability-gui:6.5.9 |
+---+-----------------------------------------------------------------------------------------------------------------------+---------------------------------------+
Read more: https://docs.spryker.com/docs/scos/dev/guidelines/keeping-a-project-upgradable/upgradability-guidelines/minimum-allowed-shop-version.html
Expand Down
1 change: 1 addition & 0 deletions tests/Acceptance/_data/InvalidProject/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"spryker-feature/cart": "^202204.0",
"spryker-feature/catalog": "^202204.0",
"spryker-feature/category-management": "^202204.0",
"spryker-feature/customer-notes": "202009.0",
"spryker/availability-gui": "^6.6.2",
"spryker/uuid": "dev-some-branch",
"spryker-shop/cart": "dev-master"
Expand Down
38 changes: 38 additions & 0 deletions tests/Acceptance/_data/InvalidProject/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9bb928a

Please sign in to comment.