Skip to content

Commit

Permalink
Better output
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaGallinari committed Jan 22, 2024
1 parent 5c641e3 commit a2fb05c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 29 deletions.
62 changes: 41 additions & 21 deletions src/Command/ServiceChangesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,48 +150,60 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if (!($this->computeServicesThatChanged($decoratedServicesAssociation))) {
$this->output->writeln('No changes detected');
$this->writeLine('No changes detected');
}

foreach ($syliusServicesWithAppClass as $alias => $class) {
$output->writeln(
if (count($syliusServicesWithAppClass) > 0) {
$this->writeLine('');
$this->writeLine(
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,
),
'Found %s services that must be checked manually because the related alias referes to a Sylius' .
' service. Actually it\'s impossible to detects if the original class chnaged between versions.' .
' Here is the list ([decorated service] -> [decorating service]):',
count($syliusServicesWithAppClass)
)
);
foreach ($syliusServicesWithAppClass as $alias => $class) {
$this->writeLine(sprintf('"%s" -> "%s"', $alias, $class));
}
}

return 0;
}

private function computeServicesThatChanged(array $decoratedServicesAssociation): bool
{
$this->outputVerbose("\n\n### Computing changed services");
$this->output->writeln(
$this->writeLine(
sprintf('Computing modified services between %s and %s', $this->fromVersion, $this->toVersion)
);
$this->writeLine('');

$decoratedServices = [];
$filesChanged = $this->getFilesChangedBetweenTwoVersions();
$atLeastOneChanged = false;
foreach ($filesChanged as $fileChanged) {
foreach ($decoratedServicesAssociation as $newService => $oldService) {
$pathFromNamespace = str_replace('\\', \DIRECTORY_SEPARATOR, $oldService);
if (!str_contains($fileChanged, $pathFromNamespace)) {
continue;
}
$atLeastOneChanged = true;
$this->output->writeln(
sprintf(
'Service "%s" must be checked because the service that it decorates "%s" has changed between given versions',
$newService,
$oldService,
),
);
$decoratedServices[$newService] = $oldService;
}
}
return $atLeastOneChanged;
if (count($decoratedServices) === 0) {
$this->writeLine('Found 0 services that changed and was decorated.');

return false;
}

$this->writeLine(sprintf(
'Found %s services that changed and were decorated ([decorated service] -> [decorating service]):',
count($decoratedServices)
));
foreach ($decoratedServices as $newService => $oldService) {
$this->writeLine(sprintf('"%s" -> "%s"', $oldService, $newService));
}

return true;
}

/**
Expand Down Expand Up @@ -239,8 +251,16 @@ private function compile(
private function outputVerbose(string $message): void
{
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->output->writeln($message);
$this->writeLine($message);
}
}

private function writeLine(string $message): void
{
if ($this->output === null) {
return;
}
$this->output->writeln($message);
}

private function loadInputs(InputInterface $input): void
Expand Down
30 changes: 22 additions & 8 deletions tests/Integration/Command/ServiceChangesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ public function test_it_detects_with_inner_substitution_strategy_those_decorated
$output = $this->commandTester->getDisplay();
$expectedOutput = <<<TXT
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.
Found 2 services that changed and were decorated ([decorated service] -> [decorating service]):
"Sylius\Bundle\AdminBundle\EmailManager\OrderEmailManager" -> "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\\test_it_detects_with_inner_substitution_strategy_those_decorated_services_that_changed\DecorateOrderEmailManagerInterface"
"Sylius\Component\Core\Cart\Context\ShopBasedCartContext" -> "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\\test_it_detects_with_inner_substitution_strategy_those_decorated_services_that_changed\DecorateNewShopBased"
Found 1 services that must be checked manually because the related alias referes to a Sylius service. Actually it's impossible to detects if the original class chnaged between versions. Here is the list ([decorated service] -> [decorating service]):
"sylius.calculator.product_variant_price" -> "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\DecorateProductVariantPriceCalculator"
TXT;

Expand All @@ -80,9 +84,13 @@ public function test_it_detects_with_decorated_definition_strategy_those_decorat
$output = $this->commandTester->getDisplay();
$expectedOutput = <<<TXT
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.
Found 2 services that changed and were decorated ([decorated service] -> [decorating service]):
"Sylius\Component\Addressing\Provider\ProvinceNamingProvider" -> "webgriffe_sylius_upgrade.service_changes_command.test_it_detects_with_decorated_definition_strategy_those_decorated_services_that_changed.decorate_province_naming_provider"
"Sylius\Component\Core\OrderProcessing\OrderPaymentProcessor" -> "webgriffe_sylius_upgrade.service_changes_command.test_it_detects_with_decorated_definition_strategy_those_decorated_services_that_changed.decorate_order_payment_processor"
Found 1 services that must be checked manually because the related alias referes to a Sylius service. Actually it's impossible to detects if the original class chnaged between versions. Here is the list ([decorated service] -> [decorating service]):
"sylius.calculator.product_variant_price" -> "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\DecorateProductVariantPriceCalculator"
TXT;

Expand All @@ -107,8 +115,12 @@ public function test_it_detects_with_alias_strategy_those_decorated_services_tha
$output = $this->commandTester->getDisplay();
$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.
Found 1 services that changed and were decorated ([decorated service] -> [decorating service]):
"Sylius\Bundle\ApiBundle\CommandHandler\Checkout\SendOrderConfirmationHandler" -> "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\\test_it_detects_with_alias_strategy_those_decorated_services_that_changed\DecorateSendOrderConfirmationHandler"
Found 1 services that must be checked manually because the related alias referes to a Sylius service. Actually it's impossible to detects if the original class chnaged between versions. Here is the list ([decorated service] -> [decorating service]):
"sylius.calculator.product_variant_price" -> "Tests\Webgriffe\SyliusUpgradePlugin\Stub\ServiceChangesCommand\DecorateProductVariantPriceCalculator"
TXT;

Expand All @@ -133,6 +145,8 @@ public function test_it_ignores_those_decorated_services_that_changed_but_the_de
$output = $this->commandTester->getDisplay();
$expectedOutput = <<<TXT
Computing modified services between 1.11.0 and 1.12.0
Found 0 services that changed and was decorated.
No changes detected
TXT;
Expand Down

0 comments on commit a2fb05c

Please sign in to comment.