Skip to content

Commit

Permalink
Alerts about Sylius services with "App" class
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaGallinari committed Jan 15, 2024
1 parent df44711 commit 010848c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Command/ServiceChangesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$rawKernel->boot();

$decoratedServicesAssociation = [];
$syliusServicesWithAppClass = [];
$decoratedDefintions = $decoratorServiceDefinitionsPass::$decoratedServices;

$this->outputVerbose("\n\n### DEBUG: Computing decorated services");
Expand Down Expand Up @@ -150,7 +151,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}

if (!str_starts_with($definitionClass, sprintf('%s\\', $this->namespacePrefix))) {
$isAppClass = str_starts_with($definitionClass, sprintf('%s\\', $this->namespacePrefix));
if (!$isAppClass) {
// it could happen that the definition class of the decorating service is an "App" class,
// but it still be defined with original service class and alias..
// todo: i cannot find a way to test this case
Expand Down Expand Up @@ -227,7 +229,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$this->outputVerbose(sprintf("\tNot found classpath for alias %s", $alias));
if (class_exists($definitionClass)) {
$syliusServicesWithAppClass[$alias] = $definitionClass;
}
}


Expand Down Expand Up @@ -256,6 +260,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->output->writeln('No changes detected');
}

foreach ($syliusServicesWithAppClass as $alias => $class) {
$output->writeln(
sprintf(
'Service with class "%s" must be checked manually because the related alias "%s" referes to a' .
' Sylius service. Actually it\'s impossible to detects if the original class chnaged between versions.',
$class,
$alias,
),
);
}

return 0;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Application/config/services_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ services:
webgriffe_sylius_upgrade.service_changes_command.test_it_detects_with_alias_strategy_those_decorated_services_that_changed.decorate_send_shipment_confirmation_email_handler:
class: Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\test_it_detects_with_alias_strategy_those_decorated_services_that_changed\DecorateSendShipmentConfirmationEmailHandler
decorates: Sylius\Bundle\ApiBundle\CommandHandler\Checkout\SendShipmentConfirmationEmailHandler


## test_it_alerts_about_services_whose_class_has_changed_but_not_their_alias
# this
sylius.calculator.product_variant_price:
public: true
class: Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\DecorateProductVariantPriceCalculator
3 changes: 3 additions & 0 deletions tests/Integration/Command/ServiceChangesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function test_it_detects_with_inner_substitution_strategy_those_decorated
Computing modified services between 1.11.0 and 1.12.0
Service "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\\test_it_detects_with_inner_substitution_strategy_those_decorated_services_that_changed\DecorateOrderEmailManagerInterface" must be checked because the service that it decorates "Sylius\Bundle\AdminBundle\EmailManager\OrderEmailManager" has changed between given versions
Service "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\\test_it_detects_with_inner_substitution_strategy_those_decorated_services_that_changed\DecorateNewShopBased" must be checked because the service that it decorates "Sylius\Component\Core\Cart\Context\ShopBasedCartContext" has changed between given versions
Service with class "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\\DecorateProductVariantPriceCalculator" must be checked manually because the related alias "sylius.calculator.product_variant_price" referes to a Sylius service. Actually it's impossible to detects if the original class chnaged between versions.
TXT;

Expand All @@ -81,6 +82,7 @@ public function test_it_detects_with_decorated_definition_strategy_those_decorat
Computing modified services between 1.11.0 and 1.12.0
Service "webgriffe_sylius_upgrade.service_changes_command.test_it_detects_with_decorated_definition_strategy_those_decorated_services_that_changed.decorate_province_naming_provider" must be checked because the service that it decorates "Sylius\Component\Addressing\Provider\ProvinceNamingProvider" has changed between given versions
Service "webgriffe_sylius_upgrade.service_changes_command.test_it_detects_with_decorated_definition_strategy_those_decorated_services_that_changed.decorate_order_payment_processor" must be checked because the service that it decorates "Sylius\Component\Core\OrderProcessing\OrderPaymentProcessor" has changed between given versions
Service with class "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\\DecorateProductVariantPriceCalculator" must be checked manually because the related alias "sylius.calculator.product_variant_price" referes to a Sylius service. Actually it's impossible to detects if the original class chnaged between versions.
TXT;

Expand All @@ -106,6 +108,7 @@ public function test_it_detects_with_alias_strategy_those_decorated_services_tha
$expectedOutput = <<<TXT
Computing modified services between 1.11.0 and 1.12.0
Service "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\\test_it_detects_with_alias_strategy_those_decorated_services_that_changed\DecorateSendOrderConfirmationHandler" must be checked because the service that it decorates "Sylius\Bundle\ApiBundle\CommandHandler\Checkout\SendOrderConfirmationHandler" has changed between given versions
Service with class "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\\DecorateProductVariantPriceCalculator" must be checked manually because the related alias "sylius.calculator.product_variant_price" referes to a Sylius service. Actually it's impossible to detects if the original class chnaged between versions.
TXT;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand;

final class DecorateProductVariantPriceCalculator
{
}

0 comments on commit 010848c

Please sign in to comment.