diff --git a/src/Magento/ComposerRootUpdatePlugin/ComposerReimplementation/ExtendableRequireCommand.php b/src/Magento/ComposerRootUpdatePlugin/ComposerReimplementation/ExtendableRequireCommand.php
index e51b40b..b9d68c8 100644
--- a/src/Magento/ComposerRootUpdatePlugin/ComposerReimplementation/ExtendableRequireCommand.php
+++ b/src/Magento/ComposerRootUpdatePlugin/ComposerReimplementation/ExtendableRequireCommand.php
@@ -35,7 +35,7 @@ abstract class ExtendableRequireCommand extends RequireCommand
protected $jsonFile;
/**
- * @var boolean $mageNewlyCreated
+ * @var bool $mageNewlyCreated
*/
protected $mageNewlyCreated;
diff --git a/src/Magento/ComposerRootUpdatePlugin/Plugin/CommandProvider.php b/src/Magento/ComposerRootUpdatePlugin/Plugin/CommandProvider.php
index 20b68b0..a2213f8 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Plugin/CommandProvider.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Plugin/CommandProvider.php
@@ -10,9 +10,6 @@
use Magento\ComposerRootUpdatePlugin\Plugin\Commands\MageRootRequireCommand;
use Magento\ComposerRootUpdatePlugin\Plugin\Commands\UpdatePluginNamespaceCommands;
-/**
- * Class CommandProvider
- */
class CommandProvider implements CommandProviderCapability
{
/**
diff --git a/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommand.php b/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommand.php
index 74a4e09..cb6981f 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommand.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommand.php
@@ -19,9 +19,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-/**
- * Class RootUpdateCommand
- */
class MageRootRequireCommand extends ExtendableRequireCommand
{
/**
@@ -42,7 +39,12 @@ class MageRootRequireCommand extends ExtendableRequireCommand
/**
* @var RootPackageRetriever $retriever
*/
- private $retriever;
+ protected $retriever;
+
+ /**
+ * @var Console $console
+ */
+ protected $console;
/**
* Call the parent setApplication method but also change the command's name to update
@@ -57,7 +59,6 @@ public function setApplication(Application $application = null)
// added to the command registry
$this->setName($this->commandName);
parent::setApplication($application);
- Console::setIO($this->getIO());
}
/**
@@ -132,7 +133,7 @@ public function configure()
public function execute(InputInterface $input, OutputInterface $output)
{
$updater = null;
- Console::setIO($this->getIO());
+ $this->console = new Console($this->getIO(), $input->getOption(static::INTERACTIVE_OPT));
$fileParsed = $this->parseComposerJsonFile($input);
if ($fileParsed !== 0) {
return $fileParsed;
@@ -162,12 +163,12 @@ public function execute(InputInterface $input, OutputInterface $output)
// Found a Magento product in the command arguments; try to run the updater
try {
- $updater = new MagentoRootUpdater($this->getComposer());
+ $updater = new MagentoRootUpdater($this->console, $this->getComposer());
$didUpdate = $this->runUpdate($updater, $input, $edition, $constraint);
} catch (\Exception $e) {
$label = 'Magento ' . ucfirst($edition) . " Edition $constraint";
$this->revertMageComposerFile("Update of composer.json with $label changes failed");
- Console::log($e->getMessage());
+ $this->console->log($e->getMessage());
$didUpdate = false;
}
@@ -178,12 +179,12 @@ public function execute(InputInterface $input, OutputInterface $output)
if ($didUpdate) {
// Update composer.json before the native execute(), as it reads the file instead of an in-memory object
$label = $this->retriever->getTargetLabel();
- Console::info("Updating composer.json for $label ...");
+ $this->console->info("Updating composer.json for $label ...");
try {
$updater->writeUpdatedComposerJson();
} catch (\Exception $e) {
$this->revertMageComposerFile("Update of composer.json with $label changes failed");
- Console::log($e->getMessage());
+ $this->console->log($e->getMessage());
$didUpdate = false;
}
}
@@ -202,7 +203,7 @@ public function execute(InputInterface $input, OutputInterface $output)
// If the native execute() didn't succeed, revert the Magento changes to the composer.json file
$this->revertMageComposerFile('The native \'composer ' . $this->commandName . '\' command failed');
if ($constraint && !PackageUtils::isConstraintStrict($constraint)) {
- Console::comment(
+ $this->console->comment(
"Recommended: Use a specific Magento version constraint instead of \"$package: $constraint\""
);
}
@@ -224,7 +225,7 @@ public function execute(InputInterface $input, OutputInterface $output)
* @param InputInterface $input
* @param string $targetEdition
* @param string $targetConstraint
- * @return boolean Returns true if updates were necessary and prepared successfully
+ * @return bool Returns true if updates were necessary and prepared successfully
*/
protected function runUpdate($updater, $input, $targetEdition, $targetConstraint)
{
@@ -252,8 +253,8 @@ protected function runUpdate($updater, $input, $targetEdition, $targetConstraint
}
}
- Console::setInteractive($input->getOption(static::INTERACTIVE_OPT));
$this->retriever = new RootPackageRetriever(
+ $this->console,
$this->getComposer(),
$targetEdition,
$targetConstraint,
diff --git a/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/UpdatePluginNamespaceCommands.php b/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/UpdatePluginNamespaceCommands.php
index 6f2f3e3..6f48f56 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/UpdatePluginNamespaceCommands.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/UpdatePluginNamespaceCommands.php
@@ -24,12 +24,17 @@ class UpdatePluginNamespaceCommands extends BaseCommand
{
const NAME = 'magento-update-plugin';
+ /**
+ * @var Console $console
+ */
+ protected $console;
+
/**
* Map of operation command to description
*
* @var array $operations
*/
- private static $operations = [
+ protected static $operations = [
'list' =>
"List all operations available in the %command.name% namespace. This is equivalent\n".
'to running %command.full_name% without an operation.',
@@ -63,16 +68,17 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
+ $this->console = new Console($this->getIO());
$operation = $input->getArgument('operation');
- Console::setIO($this->getIO());
if (empty($operation) || $operation == 'list') {
- Console::log(static::describeOperations() . "\n");
+ $this->console->log(static::describeOperations() . "\n");
return 0;
}
if ($operation == 'install') {
- return WebSetupWizardPluginInstaller::doVarInstall();
+ $setupWizardInstaller = new WebSetupWizardPluginInstaller($this->console);
+ return $setupWizardInstaller->doVarInstall();
} else {
- Console::error("'$operation' is not a supported operation for ".static::NAME);
+ $this->console->error("'$operation' is not a supported operation for ".static::NAME);
return 1;
}
}
diff --git a/src/Magento/ComposerRootUpdatePlugin/Plugin/PluginDefinition.php b/src/Magento/ComposerRootUpdatePlugin/Plugin/PluginDefinition.php
index a8538a6..f4ce770 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Plugin/PluginDefinition.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Plugin/PluginDefinition.php
@@ -13,8 +13,9 @@
use Composer\IO\IOInterface;
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
use Composer\Plugin\Capable;
-use Composer\Plugin\PluginInterface;;
+use Composer\Plugin\PluginInterface;
use Magento\ComposerRootUpdatePlugin\Setup\WebSetupWizardPluginInstaller;
+use Magento\ComposerRootUpdatePlugin\Utils\Console;
/**
* Class PluginDefinition
@@ -62,7 +63,8 @@ public function packageUpdate(PackageEvent $event)
{
// Safeguard against the source file being removed before the event is triggered
if (class_exists('\Magento\ComposerRootUpdatePlugin\Setup\WebSetupWizardPluginInstaller')) {
- WebSetupWizardPluginInstaller::packageEvent($event);
+ $setupWizardInstaller = new WebSetupWizardPluginInstaller(new Console($event->getIO()));
+ $setupWizardInstaller->packageEvent($event);
}
}
}
diff --git a/src/Magento/ComposerRootUpdatePlugin/Setup/AbstractModuleOperation.php b/src/Magento/ComposerRootUpdatePlugin/Setup/AbstractModuleOperation.php
new file mode 100644
index 0000000..71213a7
--- /dev/null
+++ b/src/Magento/ComposerRootUpdatePlugin/Setup/AbstractModuleOperation.php
@@ -0,0 +1,38 @@
+doVarInstall();
+ }
+}
diff --git a/src/Magento/ComposerRootUpdatePlugin/Setup/InstallData.php b/src/Magento/ComposerRootUpdatePlugin/Setup/InstallData.php
index b1abfd1..baf4e77 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Setup/InstallData.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Setup/InstallData.php
@@ -10,10 +10,7 @@
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
-/**
- * Class InstallData
- */
-class InstallData implements InstallDataInterface
+class InstallData extends AbstractModuleOperation implements InstallDataInterface
{
/**
* Passthrough Magento setup command to check the plugin installation in the var directory
@@ -24,6 +21,6 @@ class InstallData implements InstallDataInterface
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
- WebSetupWizardPluginInstaller::doVarInstall();
+ $this->doWizardInstall($setup, $context);
}
}
diff --git a/src/Magento/ComposerRootUpdatePlugin/Setup/RecurringData.php b/src/Magento/ComposerRootUpdatePlugin/Setup/RecurringData.php
index ea31a63..51d1ec1 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Setup/RecurringData.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Setup/RecurringData.php
@@ -10,10 +10,7 @@
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
-/**
- * Class RecurringData
- */
-class RecurringData implements InstallDataInterface
+class RecurringData extends AbstractModuleOperation implements InstallDataInterface
{
/**
* Passthrough Magento setup command to check the plugin installation in the var directory
@@ -24,6 +21,6 @@ class RecurringData implements InstallDataInterface
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
- WebSetupWizardPluginInstaller::doVarInstall();
+ $this->doWizardInstall($setup, $context);
}
}
diff --git a/src/Magento/ComposerRootUpdatePlugin/Setup/UpgradeData.php b/src/Magento/ComposerRootUpdatePlugin/Setup/UpgradeData.php
index 5703caf..14020c2 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Setup/UpgradeData.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Setup/UpgradeData.php
@@ -10,10 +10,7 @@
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
-/**
- * Class UpgradeData
- */
-class UpgradeData implements UpgradeDataInterface
+class UpgradeData extends AbstractModuleOperation implements UpgradeDataInterface
{
/**
* Passthrough Magento setup command to check the plugin installation in the var directory
@@ -24,6 +21,6 @@ class UpgradeData implements UpgradeDataInterface
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
- WebSetupWizardPluginInstaller::doVarInstall();
+ $this->doWizardInstall($setup, $context);
}
}
diff --git a/src/Magento/ComposerRootUpdatePlugin/Setup/WebSetupWizardPluginInstaller.php b/src/Magento/ComposerRootUpdatePlugin/Setup/WebSetupWizardPluginInstaller.php
index acd727f..0e9ca65 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Setup/WebSetupWizardPluginInstaller.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Setup/WebSetupWizardPluginInstaller.php
@@ -17,20 +17,32 @@
use Magento\ComposerRootUpdatePlugin\Utils\PackageUtils;
use Magento\ComposerRootUpdatePlugin\Plugin\PluginDefinition;
-/**
- * Class WebSetupWizardPluginInstaller
- */
-abstract class WebSetupWizardPluginInstaller
+class WebSetupWizardPluginInstaller
{
+ /**
+ * @var Console $console
+ */
+ protected $console;
+
+ /**
+ * WebSetupWizardPluginInstaller constructor.
+ *
+ * @param Console $console
+ * @return void
+ */
+ public function __construct($console)
+ {
+ $this->console = $console;
+ }
+
/**
* Process a package event and look for changes in the plugin package version
*
* @param PackageEvent $event
* @return void
*/
- public static function packageEvent($event)
+ public function packageEvent($event)
{
- Console::setIO($event->getIO());
$jobs = $event->getRequest()->getJobs();
$packageName = PluginDefinition::PACKAGE_NAME;
foreach ($jobs as $job) {
@@ -40,13 +52,13 @@ public static function packageEvent($event)
$version = $pkg->getPrettyVersion();
try {
$composer = $event->getComposer();
- static::updateSetupWizardPlugin(
+ $this->updateSetupWizardPlugin(
$composer,
$composer->getConfig()->getConfigSource()->getName(),
$version
);
} catch (Exception $e) {
- Console::error("Web Setup Wizard installation of \"$packageName: $version\" failed.", $e);
+ $this->console->error("Web Setup Wizard installation of \"$packageName: $version\" failed", $e);
}
break;
}
@@ -62,37 +74,40 @@ public static function packageEvent($event)
*
* @return int 0 if successful, 1 if failed
*/
- public static function doVarInstall()
+ public function doVarInstall()
{
$packageName = PluginDefinition::PACKAGE_NAME;
$rootDir = getcwd();
$path = "$rootDir/composer.json";
if (!file_exists($path)) {
- Console::error("Web Setup Wizard installation of \"$packageName\" failed; unable to load $path.");
+ $this->console->error("Web Setup Wizard installation of \"$packageName\" failed; unable to load $path.");
return 1;
}
$factory = new Factory();
- $composer = $factory->createComposer(Console::getIO(), $path, true, null, true);
+ $composer = $factory->createComposer($this->console->getIO(), $path, true, null, true);
$locker = $composer->getLocker();
if ($locker->isLocked()) {
$pkg = $locker->getLockedRepository()->findPackage(PluginDefinition::PACKAGE_NAME, '*');
if ($pkg !== null) {
$version = $pkg->getPrettyVersion();
try {
- Console::log("Checking for \"$packageName: $version\" for the Web Setup Wizard...", Console::VERBOSE);
- static::updateSetupWizardPlugin($composer, $path, $version);
+ $this->console->log(
+ "Checking for \"$packageName: $version\" for the Web Setup Wizard...",
+ Console::VERBOSE
+ );
+ $this->updateSetupWizardPlugin($composer, $path, $version);
} catch (Exception $e) {
- Console::error("Web Setup Wizard installation of \"$packageName: $version\" failed.", $e);
+ $this->console->error("Web Setup Wizard installation of \"$packageName: $version\" failed.", $e);
return 1;
}
} else {
- Console::error("Web Setup Wizard installation of \"$packageName\" failed; " .
+ $this->console->error("Web Setup Wizard installation of \"$packageName\" failed; " .
"package not found in $rootDir/composer.lock.");
return 1;
}
} else {
- Console::error("Web Setup Wizard installation of \"$packageName\" failed; " .
+ $this->console->error("Web Setup Wizard installation of \"$packageName\" failed; " .
"unable to load $rootDir/composer.lock.");
return 1;
}
@@ -105,10 +120,10 @@ public static function doVarInstall()
* @param Composer $composer
* @param string $filePath
* @param string $pluginVersion
- * @return boolean
+ * @return bool
* @throws Exception
*/
- public static function updateSetupWizardPlugin($composer, $filePath, $pluginVersion)
+ public function updateSetupWizardPlugin($composer, $filePath, $pluginVersion)
{
$packageName = PluginDefinition::PACKAGE_NAME;
@@ -124,7 +139,7 @@ public static function updateSetupWizardPlugin($composer, $filePath, $pluginVers
$var = "$rootDir/var";
if (file_exists("$var/vendor/$packageName/composer.json")) {
$varPluginComposer = (new Factory())->createComposer(
- Console::getIO(),
+ $this->console->getIO(),
"$var/vendor/$packageName/composer.json",
true,
"$var/vendor/$packageName",
@@ -133,7 +148,7 @@ public static function updateSetupWizardPlugin($composer, $filePath, $pluginVers
// If the current version of the plugin is already the version in this update, noop
if ($varPluginComposer->getPackage()->getPrettyVersion() == $pluginVersion) {
- Console::log(
+ $this->console->log(
"No Web Setup Wizard update needed for $packageName; version $pluginVersion is already in $var.",
Console::VERBOSE
);
@@ -141,7 +156,7 @@ public static function updateSetupWizardPlugin($composer, $filePath, $pluginVers
}
}
- Console::info("Installing \"$packageName: $pluginVersion\" for the Web Setup Wizard");
+ $this->console->info("Installing \"$packageName: $pluginVersion\" for the Web Setup Wizard");
if (!file_exists($var)) {
mkdir($var);
@@ -158,8 +173,8 @@ public static function updateSetupWizardPlugin($composer, $filePath, $pluginVers
unlink($tmpDir);
mkdir($tmpDir);
- $tmpComposer = static::createPluginComposer($tmpDir, $pluginVersion, $composer);
- $install = Installer::create(Console::getIO(), $tmpComposer);
+ $tmpComposer = $this->createPluginComposer($tmpDir, $pluginVersion, $composer);
+ $install = Installer::create($this->console->getIO(), $tmpComposer);
$install
->setDumpAutoloader(true)
->setRunScripts(false)
@@ -167,12 +182,12 @@ public static function updateSetupWizardPlugin($composer, $filePath, $pluginVers
->disablePlugins();
$install->run();
- static::copyAndReplace("$tmpDir/vendor", "$var/vendor");
+ $this->copyAndReplace("$tmpDir/vendor", "$var/vendor");
} catch (Exception $e) {
$exception = $e;
}
- static::deletePath($tmpDir);
+ $this->deletePath($tmpDir);
if ($exception !== null) {
throw $exception;
@@ -188,7 +203,7 @@ public static function updateSetupWizardPlugin($composer, $filePath, $pluginVers
* @return void
* @throws FilesystemException
*/
- private static function deletePath($path)
+ private function deletePath($path)
{
if (!file_exists($path)) {
return;
@@ -196,7 +211,7 @@ private static function deletePath($path)
if (!is_link($path) && is_dir($path)) {
$files = array_diff(scandir($path), ['..', '.']);
foreach ($files as $file) {
- static::deletePath("$path/$file");
+ $this->deletePath("$path/$file");
}
rmdir($path);
} else {
@@ -215,14 +230,14 @@ private static function deletePath($path)
* @return void
* @throws FilesystemException
*/
- private static function copyAndReplace($source, $target)
+ private function copyAndReplace($source, $target)
{
- static::deletePath($target);
+ $this->deletePath($target);
if (is_dir($source)) {
mkdir($target);
$files = array_diff(scandir($source), ['..', '.']);
foreach ($files as $file) {
- static::copyAndReplace("$source/$file", "$target/$file");
+ $this->copyAndReplace("$source/$file", "$target/$file");
}
} else {
copy($source, $target);
@@ -238,7 +253,7 @@ private static function copyAndReplace($source, $target)
* @return Composer
* @throws Exception
*/
- private static function createPluginComposer($tmpDir, $pluginVersion, $rootComposer)
+ private function createPluginComposer($tmpDir, $pluginVersion, $rootComposer)
{
$factory = new Factory();
$tmpConfig = [
@@ -251,7 +266,7 @@ private static function createPluginComposer($tmpDir, $pluginVersion, $rootCompo
}
$tmpJson = new JsonFile("$tmpDir/composer.json");
$tmpJson->write($tmpConfig);
- $tmpComposer = $factory->createComposer(Console::getIO(), "$tmpDir/composer.json", true, $tmpDir);
+ $tmpComposer = $factory->createComposer($this->console->getIO(), "$tmpDir/composer.json", true, $tmpDir);
$tmpConfig = $tmpComposer->getConfig();
$tmpConfig->setAuthConfigSource($rootComposer->getConfig()->getAuthConfigSource());
$tmpComposer->setConfig($tmpConfig);
diff --git a/src/Magento/ComposerRootUpdatePlugin/Updater/ConflictResolver.php b/src/Magento/ComposerRootUpdatePlugin/Updater/ConflictResolver.php
index e81d0a2..7a28fe2 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Updater/ConflictResolver.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Updater/ConflictResolver.php
@@ -12,9 +12,6 @@
use Magento\ComposerRootUpdatePlugin\Plugin\Commands\MageRootRequireCommand;
use Magento\ComposerRootUpdatePlugin\Utils\Console;
-/**
- * Class ConflictResolver
- */
class ConflictResolver
{
/**
@@ -24,6 +21,11 @@ class ConflictResolver
const REMOVE_VAL = 'remove_value';
const CHANGE_VAL = 'change_value';
+ /**
+ * @var Console $console
+ */
+ protected $console;
+
/**
* @var bool $overrideUserValues
*/
@@ -57,12 +59,14 @@ class ConflictResolver
/**
* ConflictResolver constructor.
*
- * @param boolean $overrideUserValues
+ * @param Console $console
+ * @param bool $overrideUserValues
* @param RootPackageRetriever $retriever
* @return void
*/
- public function __construct($overrideUserValues, $retriever)
+ public function __construct($console, $overrideUserValues, $retriever)
{
+ $this->console = $console;
$this->overrideUserValues = $overrideUserValues;
$this->retriever = $retriever;
$this->originalMageRootPackage = $retriever->getOriginalRootPackage($overrideUserValues);
@@ -169,14 +173,14 @@ public function findResolution(
$shouldOverride = $this->overrideUserValues;
if ($this->overrideUserValues) {
- Console::log($conflictDesc);
- Console::log("Overriding local changes due to --" . MageRootRequireCommand::OVERRIDE_OPT . '.');
+ $this->console->log($conflictDesc);
+ $this->console->log("Overriding local changes due to --" . MageRootRequireCommand::OVERRIDE_OPT . '.');
} else {
- $shouldOverride = Console::ask("$conflictDesc.\nWould you like to override the local changes?");
+ $shouldOverride = $this->console->ask("$conflictDesc.\nWould you like to override the local changes?");
}
if (!$shouldOverride) {
- Console::comment("$conflictDesc and will not be changed. Re-run using " .
+ $this->console->comment("$conflictDesc and will not be changed. Re-run using " .
'--' . MageRootRequireCommand::OVERRIDE_OPT . ' or --' . MageRootRequireCommand::INTERACTIVE_OPT .
' to override with Magento values.');
$action = null;
@@ -250,11 +254,11 @@ public function resolveLinkSection($section, $originalMageLinks, $targetMageLink
$newVal = $adds[$package]->getConstraint()->getPrettyString();
return "$package=$newVal";
}, array_keys($adds));
- Console::labeledVerbose("Adding $section constraints: " . implode(', ', $prettyAdds));
+ $this->console->labeledVerbose("Adding $section constraints: " . implode(', ', $prettyAdds));
}
if ($removes !== []) {
$changed = true;
- Console::labeledVerbose("Removing $section entries: " . implode(', ', $removes));
+ $this->console->labeledVerbose("Removing $section entries: " . implode(', ', $removes));
}
if ($changes !== []) {
$changed = true;
@@ -262,7 +266,7 @@ public function resolveLinkSection($section, $originalMageLinks, $targetMageLink
$newVal = $changes[$package]->getConstraint()->getPrettyString();
return "$package=$newVal";
}, array_keys($changes));
- Console::labeledVerbose("Updating $section constraints: " . implode(', ', $prettyChanges));
+ $this->console->labeledVerbose("Updating $section constraints: " . implode(', ', $prettyChanges));
}
if ($changed) {
@@ -399,14 +403,14 @@ public function resolveNestedArray($field, $originalMageVal, $targetMageVal, $us
$flatAdds = array_diff(array_diff($targetMageFlatPart, $originalMageFlatPart), $flatResult);
if ($flatAdds !== []) {
$valChanged = true;
- Console::labeledVerbose("Adding $field entries: " . implode(', ', $flatAdds));
+ $this->console->labeledVerbose("Adding $field entries: " . implode(', ', $flatAdds));
$flatResult = array_unique(array_merge($flatResult, $flatAdds));
}
$flatRemoves = array_intersect(array_diff($originalMageFlatPart, $targetMageFlatPart), $flatResult);
if ($flatRemoves !== []) {
$valChanged = true;
- Console::labeledVerbose("Removing $field entries: " . implode(', ', $flatRemoves));
+ $this->console->labeledVerbose("Removing $field entries: " . implode(', ', $flatRemoves));
$flatResult = array_diff($flatResult, $flatRemoves);
}
@@ -417,15 +421,15 @@ public function resolveNestedArray($field, $originalMageVal, $targetMageVal, $us
$prettyTargetMageVal = json_encode($targetMageVal, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
if ($action == static::ADD_VAL) {
$valChanged = true;
- Console::labeledVerbose("Adding $field entry: $prettyTargetMageVal");
+ $this->console->labeledVerbose("Adding $field entry: $prettyTargetMageVal");
$result = $targetMageVal;
} elseif ($action == static::CHANGE_VAL) {
$valChanged = true;
- Console::labeledVerbose("Updating $field entry: $prettyTargetMageVal");
+ $this->console->labeledVerbose("Updating $field entry: $prettyTargetMageVal");
$result = $targetMageVal;
} elseif ($action == static::REMOVE_VAL) {
$valChanged = true;
- Console::labeledVerbose("Removing $field entry");
+ $this->console->labeledVerbose("Removing $field entry");
$result = null;
}
}
diff --git a/src/Magento/ComposerRootUpdatePlugin/Updater/MagentoRootUpdater.php b/src/Magento/ComposerRootUpdatePlugin/Updater/MagentoRootUpdater.php
index f6b681f..4f251cf 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Updater/MagentoRootUpdater.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Updater/MagentoRootUpdater.php
@@ -12,13 +12,13 @@
use Magento\ComposerRootUpdatePlugin\Utils\Console;
use Magento\ComposerRootUpdatePlugin\Plugin\PluginDefinition;
-/**
- * Class MagentoRootUpdater
- *
- *
- */
class MagentoRootUpdater
{
+ /**
+ * @var Console $console
+ */
+ protected $console;
+
/**
* @var Composer $composer
*/
@@ -32,11 +32,13 @@ class MagentoRootUpdater
/**
* MagentoRootUpdater constructor.
*
+ * @param Console $console
* @param Composer $composer
* @return void
*/
- public function __construct($composer)
+ public function __construct($console, $composer)
{
+ $this->console = $console;
$this->composer = $composer;
$this->jsonChanges = [];
}
@@ -45,11 +47,11 @@ public function __construct($composer)
* Look ahead to the target Magento version and execute any changes to the root composer.json file in-memory
*
* @param RootPackageRetriever $retriever
- * @param boolean $overrideOption
- * @param boolean $ignorePlatformReqs
+ * @param bool $overrideOption
+ * @param bool $ignorePlatformReqs
* @param string $phpVersion
* @param string $stability
- * @return boolean Returns true if updates were necessary and prepared successfully
+ * @return bool Returns true if updates were necessary and prepared successfully
*/
public function runUpdate(
$retriever,
@@ -75,23 +77,23 @@ public function runUpdate(
}
if ($originalEdition == $retriever->getTargetEdition() && $originalVersion == $retriever->getTargetVersion()) {
- Console::labeledVerbose(
+ $this->console->labeledVerbose(
'The Magento product requirement matched the current installation; no root updates are required'
);
return false;
}
if (!$retriever->getOriginalRootPackage($overrideOption)) {
- Console::log('Skipping Magento composer.json update.');
+ $this->console->log('Skipping Magento composer.json update.');
return false;
}
- Console::setVerboseLabel($retriever->getTargetLabel());
- Console::labeledVerbose(
+ $this->console->setVerboseLabel($retriever->getTargetLabel());
+ $this->console->labeledVerbose(
"Base Magento project package version: magento/project-$originalEdition-edition $prettyOriginalVersion"
);
- $resolver = new ConflictResolver($overrideOption, $retriever);
+ $resolver = new ConflictResolver($this->console, $overrideOption, $retriever);
$jsonChanges = $resolver->resolveConflicts();
@@ -130,7 +132,7 @@ public function writeUpdatedComposerJson()
}
}
- Console::labeledVerbose('Writing changes to the root composer.json...');
+ $this->console->labeledVerbose('Writing changes to the root composer.json...');
$retVal = file_put_contents(
$filePath,
@@ -140,7 +142,7 @@ public function writeUpdatedComposerJson()
if ($retVal === false) {
throw new FilesystemException('Failed to write updated Magento root values to ' . $filePath);
}
- Console::labeledVerbose("$filePath has been updated");
+ $this->console->labeledVerbose("$filePath has been updated");
}
/**
diff --git a/src/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetriever.php b/src/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetriever.php
index 5efa975..28b6cd2 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetriever.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetriever.php
@@ -27,6 +27,11 @@ class RootPackageRetriever
*/
const MISSING_ROOT_LABEL = '(unknown Magento root)';
+ /**
+ * @var Console $console
+ */
+ protected $console;
+
/**
* @var Composer $composer
*/
@@ -90,6 +95,7 @@ class RootPackageRetriever
/**
* RootPackageRetriever constructor.
*
+ * @param Console $console
* @param Composer $composer
* @param string $targetEdition
* @param string $targetConstraint
@@ -97,12 +103,14 @@ class RootPackageRetriever
* @param string $overrideOriginalVersion
*/
public function __construct(
+ $console,
$composer,
$targetEdition,
$targetConstraint,
$overrideOriginalEdition = null,
$overrideOriginalVersion = null
) {
+ $this->console = $console;
$this->composer = $composer;
$this->originalRootPackage = null;
@@ -124,7 +132,7 @@ public function __construct(
* Get the project package that should be used as the basis for Magento root comparisons
*
* @param bool $overrideOption
- * @return PackageInterface|boolean
+ * @return PackageInterface|bool
*/
public function getOriginalRootPackage($overrideOption)
{
@@ -142,9 +150,9 @@ public function getOriginalRootPackage($overrideOption)
if (!$originalRootPackage) {
if (!$originalEdition || !$originalVersion) {
- Console::warning('No Magento product package was found in the current installation.');
+ $this->console->warning('No Magento product package was found in the current installation.');
} else {
- Console::warning('The Magento project package corresponding to the currently installed ' .
+ $this->console->warning('The Magento project package corresponding to the currently installed ' .
"\"magento/product-$originalEdition-edition: $prettyOriginalVersion\" package is unavailable.");
}
@@ -152,7 +160,7 @@ public function getOriginalRootPackage($overrideOption)
if (!$overrideRoot) {
$question = 'Would you like to update the root composer.json file anyway? ' .
'This will override any changes you have made to the default composer.json file.';
- $overrideRoot = Console::ask($question);
+ $overrideRoot = $this->console->ask($question);
}
if ($overrideRoot) {
@@ -206,7 +214,7 @@ public function getUserRootPackage()
*
* @param string $edition
* @param string $constraint
- * @param boolean $ignorePlatformReqs
+ * @param bool $ignorePlatformReqs
* @param string $phpVersion
* @param string $preferredStability
* @return PackageInterface|bool Best root package candidate or false if no valid packages found
@@ -231,7 +239,7 @@ protected function fetchMageRootFromRepo(
$stability = key_exists($packageName, $stabilityFlags)
? array_search($stabilityFlags[$packageName], BasePackage::$stabilities)
: $minStability;
- Console::comment("Minimum stability for \"$packageName: $constraint\": $stability", IOInterface::DEBUG);
+ $this->console->comment("Minimum stability for \"$packageName: $constraint\": $stability", IOInterface::DEBUG);
$pool = new Pool(
$stability,
$stabilityFlags,
@@ -241,7 +249,7 @@ protected function fetchMageRootFromRepo(
$pool->addRepository($repos);
if (!PackageUtils::isConstraintStrict($constraint)) {
- Console::warning(
+ $this->console->warning(
"The version constraint \"magento/product-$edition-edition: $constraint\" is not exact; " .
'the Magento root updater might not accurately determine the version to use according to other ' .
'requirements in this installation. It is recommended to use an exact version number.'
@@ -258,7 +266,7 @@ protected function fetchMageRootFromRepo(
if ($phpVersion) {
$err = "$err for PHP version $phpVersion";
}
- Console::error($err);
+ $this->console->error($err);
}
return $result;
@@ -273,7 +281,7 @@ protected function parseOriginalVersionAndEditionFromLock()
{
$locker = $this->getRootLocker();
if (!$locker || !$locker->isLocked()) {
- Console::labeledVerbose(
+ $this->console->labeledVerbose(
'No composer.lock file was found in the root project to check for the installed Magento version'
);
return;
@@ -318,7 +326,7 @@ protected function getRootLocker()
$parentDir = preg_replace('/\/var\/composer\.json$/', '', $composerPath);
if (file_exists("$parentDir/composer.json") && file_exists("$parentDir/composer.lock")) {
$locker = new Locker(
- Console::getIO(),
+ $this->console->getIO(),
new JsonFile("$parentDir/composer.lock"),
$composer->getRepositoryManager(),
$composer->getInstallationManager(),
diff --git a/src/Magento/ComposerRootUpdatePlugin/Utils/Console.php b/src/Magento/ComposerRootUpdatePlugin/Utils/Console.php
index b80d3ec..b39d05f 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Utils/Console.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Utils/Console.php
@@ -6,22 +6,9 @@
namespace Magento\ComposerRootUpdatePlugin\Utils;
-use Composer\IO\ConsoleIO;
use Composer\IO\IOInterface;
-use Symfony\Component\Console\Helper\DebugFormatterHelper;
-use Symfony\Component\Console\Helper\FormatterHelper;
-use Symfony\Component\Console\Helper\HelperSet;
-use Symfony\Component\Console\Helper\ProcessHelper;
-use Symfony\Component\Console\Helper\QuestionHelper;
-use Symfony\Component\Console\Input\ArrayInput;
-use Symfony\Component\Console\Output\ConsoleOutput;
-use Symfony\Component\Console\Output\OutputInterface;
+use Composer\IO\NullIO;
-/**
- * Class Console
- *
- * Shared static logger and interaction methods
- */
class Console
{
/**
@@ -44,48 +31,45 @@ class Console
/**
* @var IOInterface $io
*/
- static protected $io = null;
+ protected $io;
/**
* @var string $verboseLabel
*/
- static protected $verboseLabel = null;
+ protected $verboseLabel;
/**
* @var bool $interactive
*/
- static protected $interactive = false;
+ protected $interactive;
/**
- * Get the shared IOInterface instance or a default ConsoleIO if one hasn't been set via setIO()
+ * Console constructor.
*
- * @return IOInterface
+ * @param IOInterface $io
+ * @param bool $interactive
+ * @param string $verboseLabel
+ * @return void
*/
- static public function getIO()
+ public function __construct($io, $interactive = false, $verboseLabel = null)
{
- if (static::$io == null) {
- static::$io = new ConsoleIO(new ArrayInput([]),
- new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG),
- new HelperSet([
- new FormatterHelper(),
- new DebugFormatterHelper(),
- new ProcessHelper(),
- new QuestionHelper()
- ])
- );
+ if ($io === null) {
+ $this->io = new NullIO();
+ } else {
+ $this->io = $io;
}
- return static::$io;
+ $this->verboseLabel = $verboseLabel;
+ $this->interactive = $interactive;
}
/**
- * Set the shared IOInterface instance
+ * Get the Composer IOInterface instance
*
- * @param IOInterface $io
- * @return void
+ * @return IOInterface
*/
- static public function setIO($io)
+ public function getIO()
{
- static::$io = $io;
+ return $this->io;
}
/**
@@ -94,31 +78,31 @@ static public function setIO($io)
* @param bool $interactive
* @return void
*/
- public static function setInteractive($interactive)
+ public function setInteractive($interactive)
{
- self::$interactive = $interactive;
+ $this->interactive = $interactive;
}
/**
* Ask the user a yes or no question and return the result
*
- * If setInteractive(false) has been called, instead do not ask and just return the default
+ * If the console is not interactive, instead do not ask and just return the default
*
* @param string $question
- * @param boolean $default
- * @return boolean
+ * @param bool $default
+ * @return bool
*/
- static public function ask($question, $default = false)
+ public function ask($question, $default = false)
{
$result = $default;
- if (static::$interactive) {
- if (!static::getIO()->isInteractive()) {
+ if ($this->interactive) {
+ if (!$this->getIO()->isInteractive()) {
throw new \InvalidArgumentException(
'Interactive options cannot be used in non-interactive terminals.'
);
}
$opts = $default ? 'Y,n' : 'y,N';
- $result = static::getIO()->askConfirmation("$question [$opts]? ", $default);
+ $result = $this->getIO()->askConfirmation("$question [$opts]? ", $default);
}
return $result;
}
@@ -131,13 +115,13 @@ static public function ask($question, $default = false)
* @param string $format
* @return void
*/
- static public function log($message, $verbosity = Console::NORMAL, $format = null)
+ public function log($message, $verbosity = Console::NORMAL, $format = null)
{
if ($format) {
$formatClose = str_replace('<', '', $format);
$message = "${format}${message}${formatClose}";
}
- static::getIO()->writeError($message, true, $verbosity);
+ $this->getIO()->writeError($message, true, $verbosity);
}
/**
@@ -147,9 +131,9 @@ static public function log($message, $verbosity = Console::NORMAL, $format = nul
* @param int $verbosity
* @return void
*/
- static public function info($message, $verbosity = Console::NORMAL)
+ public function info($message, $verbosity = Console::NORMAL)
{
- static::log($message, $verbosity, static::FORMAT_INFO);
+ $this->log($message, $verbosity, static::FORMAT_INFO);
}
/**
@@ -159,9 +143,9 @@ static public function info($message, $verbosity = Console::NORMAL)
* @param int $verbosity
* @return void
*/
- static public function comment($message, $verbosity = Console::NORMAL)
+ public function comment($message, $verbosity = Console::NORMAL)
{
- static::log($message, $verbosity, static::FORMAT_COMMENT);
+ $this->log($message, $verbosity, static::FORMAT_COMMENT);
}
/**
@@ -171,9 +155,9 @@ static public function comment($message, $verbosity = Console::NORMAL)
* @param int $verbosity
* @return void
*/
- static public function warning($message, $verbosity = Console::NORMAL)
+ public function warning($message, $verbosity = Console::NORMAL)
{
- static::log($message, $verbosity, static::FORMAT_WARN);
+ $this->log($message, $verbosity, static::FORMAT_WARN);
}
/**
@@ -187,7 +171,7 @@ static public function warning($message, $verbosity = Console::NORMAL)
* @param string $format
* @return void
*/
- static public function labeledVerbose(
+ public function labeledVerbose(
$message,
$label = null,
$verbosity = Console::VERBOSE,
@@ -198,12 +182,12 @@ static public function labeledVerbose(
$message = "${format}${message}${formatClose}";
}
if ($label === null) {
- $label = static::$verboseLabel;
+ $label = $this->verboseLabel;
}
if ($label) {
$message = " [$label] $message";
}
- static::log($message, $verbosity);
+ $this->log($message, $verbosity);
}
/**
@@ -213,22 +197,22 @@ static public function labeledVerbose(
* @param \Exception $exception
* @return void
*/
- static public function error($message, $exception = null)
+ public function error($message, $exception = null)
{
- static::log($message, static::QUIET, static::FORMAT_ERROR);
+ $this->log($message, static::QUIET, static::FORMAT_ERROR);
if ($exception) {
- static::log($exception->getMessage());
+ $this->log($exception->getMessage());
}
}
/**
- * Sets the label to apply to logVerbose() messages if not overridden
+ * Sets the label to apply to labeledVerbose() messages if not overridden
*
* @param string $verboseLabel
* @return void
*/
- static public function setVerboseLabel($verboseLabel)
+ public function setVerboseLabel($verboseLabel)
{
- static::$verboseLabel = $verboseLabel;
+ $this->verboseLabel = $verboseLabel;
}
}
diff --git a/src/Magento/ComposerRootUpdatePlugin/Utils/PackageUtils.php b/src/Magento/ComposerRootUpdatePlugin/Utils/PackageUtils.php
index 17e917a..8583944 100644
--- a/src/Magento/ComposerRootUpdatePlugin/Utils/PackageUtils.php
+++ b/src/Magento/ComposerRootUpdatePlugin/Utils/PackageUtils.php
@@ -10,9 +10,6 @@
use Composer\Package\Link;
use Composer\Package\Version\VersionParser;
-/**
- * Class PackageUtils
- */
class PackageUtils
{
/**
@@ -52,7 +49,7 @@ static public function getMagentoProductEdition($packageName)
*
* @param Composer $composer
* @param string $packageMatcher
- * @return Link|boolean
+ * @return Link|bool
*/
static public function findRequire($composer, $packageMatcher)
{
diff --git a/tests/Unit/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommandTest.php b/tests/Unit/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommandTest.php
index 586b3c9..6a705c0 100644
--- a/tests/Unit/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommandTest.php
+++ b/tests/Unit/Magento/ComposerRootUpdatePlugin/Plugin/Commands/MageRootRequireCommandTest.php
@@ -15,18 +15,21 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-/**
- * Class RootUpdateCommandTest
- */
class MageRootRequireCommandTest extends UpdatePluginTestCase
{
- /** @var TestApplication */
+ /**
+ * @var TestApplication
+ */
public $application;
- /** @var MageRootRequireCommand */
+ /**
+ * @var MageRootRequireCommand
+ */
public $command;
- /** @var MockObject|InputInterface */
+ /**
+ * @var MockObject|InputInterface
+ */
public $input;
public function testOverwriteRequireCommand()
diff --git a/tests/Unit/Magento/ComposerRootUpdatePlugin/TestHelpers/TestApplication.php b/tests/Unit/Magento/ComposerRootUpdatePlugin/TestHelpers/TestApplication.php
index 1555adc..e0081d7 100644
--- a/tests/Unit/Magento/ComposerRootUpdatePlugin/TestHelpers/TestApplication.php
+++ b/tests/Unit/Magento/ComposerRootUpdatePlugin/TestHelpers/TestApplication.php
@@ -12,15 +12,16 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-/**
- * Class TestApplication
- */
class TestApplication extends \Composer\Console\Application
{
- /** @var bool */
+ /**
+ * @var bool
+ */
private $shouldRun = false;
- /** @var Command */
+ /**
+ * @var Command
+ */
private $command = null;
/**
diff --git a/tests/Unit/Magento/ComposerRootUpdatePlugin/UpdatePluginTestCase.php b/tests/Unit/Magento/ComposerRootUpdatePlugin/UpdatePluginTestCase.php
index a9638a7..06610f4 100644
--- a/tests/Unit/Magento/ComposerRootUpdatePlugin/UpdatePluginTestCase.php
+++ b/tests/Unit/Magento/ComposerRootUpdatePlugin/UpdatePluginTestCase.php
@@ -10,9 +10,6 @@
use Composer\Semver\Constraint\Constraint;
use ReflectionClass;
-/**
- * Class UpdatePluginTestCase
- */
abstract class UpdatePluginTestCase extends \PHPUnit\Framework\TestCase
{
/**
diff --git a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/ConflictResolverTest.php b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/ConflictResolverTest.php
index b015409..4239a42 100644
--- a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/ConflictResolverTest.php
+++ b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/ConflictResolverTest.php
@@ -12,20 +12,26 @@
use Magento\ComposerRootUpdatePlugin\UpdatePluginTestCase;
use PHPUnit\Framework\MockObject\MockObject;
-/**
- * Class ConflictResolverTest
- */
class ConflictResolverTest extends UpdatePluginTestCase
{
- /** @var MockObject|BaseIO */
+ /**
+ * @var MockObject|BaseIO
+ */
public $io;
- /** @var MockObject|RootPackageRetriever */
+ /**
+ * @var MockObject|RootPackageRetriever
+ */
public $retriever;
+ /**
+ * @var Console
+ */
+ public $console;
+
public function testFindResolutionAddElement()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$resolution = $resolver->findResolution('field', null, 'newVal', null);
$this->assertEquals(ConflictResolver::ADD_VAL, $resolution);
@@ -33,7 +39,7 @@ public function testFindResolutionAddElement()
public function testFindResolutionRemoveElement()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$resolution = $resolver->findResolution('field', 'oldVal', null, 'oldVal');
$this->assertEquals(ConflictResolver::REMOVE_VAL, $resolution);
@@ -41,7 +47,7 @@ public function testFindResolutionRemoveElement()
public function testFindResolutionChangeElement()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$resolution = $resolver->findResolution('field', 'oldVal', 'newVal', 'oldVal');
$this->assertEquals(ConflictResolver::CHANGE_VAL, $resolution);
@@ -49,7 +55,7 @@ public function testFindResolutionChangeElement()
public function testFindResolutionNoUpdate()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$resolution = $resolver->findResolution('field', 'oldVal', 'newVal', 'newVal');
$this->assertNull($resolution);
@@ -60,7 +66,7 @@ public function testFindResolutionConflictNoOverride()
$this->io->expects($this->at(0))->method('writeError')
->with($this->stringContains('will not be changed'));
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$resolution = $resolver->findResolution('field', 'oldVal', 'newVal', 'conflictVal');
$this->assertNull($resolution);
@@ -68,7 +74,7 @@ public function testFindResolutionConflictNoOverride()
public function testFindResolutionConflictOverride()
{
- $resolver = new ConflictResolver(true, $this->retriever);
+ $resolver = new ConflictResolver($this->console, true, $this->retriever);
$this->io->expects($this->at(1))->method('writeError')
->with($this->stringContains('overriding local changes'));
@@ -80,7 +86,7 @@ public function testFindResolutionConflictOverride()
public function testFindResolutionConflictOverrideRestoreRemoved()
{
- $resolver = new ConflictResolver(true, $this->retriever);
+ $resolver = new ConflictResolver($this->console, true, $this->retriever);
$this->io->expects($this->at(1))->method('writeError')
->with($this->stringContains('overriding local changes'));
@@ -92,8 +98,8 @@ public function testFindResolutionConflictOverrideRestoreRemoved()
public function testFindResolutionInteractiveConfirm()
{
- $resolver = new ConflictResolver(false, $this->retriever);
- Console::setInteractive(true);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
+ $this->console->setInteractive(true);
$this->io->method('isInteractive')->willReturn(true);
$this->io->expects($this->once())->method('askConfirmation')->willReturn(true);
@@ -104,8 +110,8 @@ public function testFindResolutionInteractiveConfirm()
public function testFindResolutionInteractiveNoConfirm()
{
- $resolver = new ConflictResolver(false, $this->retriever);
- Console::setInteractive(true);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
+ $this->console->setInteractive(true);
$this->io->method('isInteractive')->willReturn(true);
$this->io->expects($this->once())->method('askConfirmation')->willReturn(false);
@@ -116,8 +122,8 @@ public function testFindResolutionInteractiveNoConfirm()
public function testFindResolutionNonInteractiveEnvironmentError()
{
- $resolver = new ConflictResolver(false, $this->retriever);
- Console::setInteractive(true);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
+ $this->console->setInteractive(true);
$this->io->method('isInteractive')->willReturn(false);
$this->expectException(\InvalidArgumentException::class);
@@ -129,7 +135,7 @@ public function testFindResolutionNonInteractiveEnvironmentError()
public function testResolveNestedArrayNonArrayAdd()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveNestedArray('field', null, 'newVal', null);
$this->assertEquals([true, 'newVal'], $result);
@@ -137,7 +143,7 @@ public function testResolveNestedArrayNonArrayAdd()
public function testResolveNestedArrayNonArrayRemove()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveNestedArray('field', 'oldVal', null, 'oldVal');
$this->assertEquals([true, null], $result);
@@ -145,7 +151,7 @@ public function testResolveNestedArrayNonArrayRemove()
public function testResolveNestedArrayNonArrayChange()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveNestedArray('field', 'oldVal', 'newVal', 'oldVal');
$this->assertEquals([true, 'newVal'], $result);
@@ -153,7 +159,7 @@ public function testResolveNestedArrayNonArrayChange()
public function testResolveArrayMismatchedArray()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
'oldVal',
@@ -166,7 +172,7 @@ public function testResolveArrayMismatchedArray()
public function testResolveArrayMismatchedMap()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
['oldVal'],
@@ -181,7 +187,7 @@ public function testResolveArrayFlatArrayAddElement()
{
$expected = ['val1', 'val2', 'val3'];
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
['val1'],
@@ -194,7 +200,7 @@ public function testResolveArrayFlatArrayAddElement()
public function testResolveArrayFlatArrayRemoveElement()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
['val1', 'val2', 'val3'],
@@ -207,7 +213,7 @@ public function testResolveArrayFlatArrayRemoveElement()
public function testResolveArrayFlatArrayAddAndRemoveElement()
{
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
['val1', 'val2', 'val3'],
@@ -222,7 +228,7 @@ public function testResolveArrayAssociativeAddElement()
{
$expected = ['key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'];
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
['key1' => 'val1'],
@@ -237,7 +243,7 @@ public function testResolveArrayAssociativeRemoveElement()
{
$expected = ['key2' => 'val2', 'key3' => 'val3'];
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
['key1' => 'val1', 'key2' => 'val2'],
@@ -252,7 +258,7 @@ public function testResolveArrayAssociativeAddAndRemoveElement()
{
$expected = ['key3' => 'val3', 'key4' => 'val4'];
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
['key1' => 'val1', 'key2' => 'val2'],
@@ -267,7 +273,7 @@ public function testResolveArrayNestedAdd()
{
$expected = ['key1' => ['k1v1', 'k1v2', 'k1v3'], 'key2' => ['k2v1', 'k2v2'], 'key3' => ['k3v1']];
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
['key1' => ['k1v1'], 'key2' => ['k2v1', 'k2v2']],
@@ -288,7 +294,7 @@ public function testResolveArrayNestedRemove()
{
$expected = ['key1' => ['k1v1', 'k1v3'], 'key2' => ['k2v2'], 'key3' => ['k3v1']];
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveArraySection(
'extra',
['key1' => ['k1v1', 'k1v2'], 'key2' => ['k2v1', 'k2v2']],
@@ -313,7 +319,7 @@ public function testResolveLinksAddLink()
$targetMageLinks = array_merge($originalMageLinks, $this->createLinks(1, 'targetMage/link'));
$expected = array_merge($targetMageLinks, $userLink);
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveLinkSection(
'require',
$originalMageLinks,
@@ -332,7 +338,7 @@ public function testResolveLinksRemoveLink()
$targetMageLinks = array_slice($originalMageLinks, 1);
$expected = array_merge($targetMageLinks, $userLink);
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveLinkSection(
'require',
$originalMageLinks,
@@ -351,7 +357,7 @@ public function testResolveLinksChangeLink()
$targetMageLinks = $this->changeLink($originalMageLinks, 1);
$expected = array_merge($targetMageLinks, $userLink);
- $resolver = new ConflictResolver(false, $this->retriever);
+ $resolver = new ConflictResolver($this->console, false, $this->retriever);
$result = $resolver->resolveLinkSection(
'require',
$originalMageLinks,
@@ -365,8 +371,7 @@ public function testResolveLinksChangeLink()
public function setUp()
{
$this->io = $this->getMockForAbstractClass(IOInterface::class);
- Console::setIO($this->io);
- Console::setInteractive(false);
+ $this->console = new Console($this->io);
$this->retriever = $this->createPartialMock(
RootPackageRetriever::class,
['getOriginalRootPackage', 'getTargetRootPackage', 'getUserRootPackage']
diff --git a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/MagentoRootUpdaterTest.php b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/MagentoRootUpdaterTest.php
index 2cd1b23..23f46b6 100644
--- a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/MagentoRootUpdaterTest.php
+++ b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/MagentoRootUpdaterTest.php
@@ -25,38 +25,56 @@
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Input\InputInterface;
-/**
- * Class MagentoRootUpdaterTest
- */
class MagentoRootUpdaterTest extends UpdatePluginTestCase
{
- /** @var MockObject|Composer */
+ /**
+ * @var MockObject|Composer
+ */
public $composer;
- /** @var RootPackage */
+ /**
+ * @var RootPackage
+ */
public $installRoot;
- /** @var RootPackage */
+ /**
+ * @var RootPackage
+ */
public $expectedNoOverride;
- /** @var RootPackage */
+ /**
+ * @var RootPackage
+ */
public $expectedWithOverride;
- /** @var MockObject|EventDispatcher */
+ /**
+ * @var MockObject|EventDispatcher
+ */
public $eventDispatcher;
- /** @var MockObject|InputInterface */
+ /**
+ * @var MockObject|InputInterface
+ */
public $input;
- /** @var MockObject|BaseIO */
+ /**
+ * @var MockObject|BaseIO
+ */
public $io;
- /** @var MockObject|RootPackageRetriever */
+ /**
+ * @var Console
+ */
+ public $console;
+
+ /**
+ * @var MockObject|RootPackageRetriever
+ */
public $retriever;
public function testMagentoUpdateSetsFieldsNoOverride()
{
- $updater = new MagentoRootUpdater($this->composer);
+ $updater = new MagentoRootUpdater($this->console, $this->composer);
$updater->runUpdate($this->retriever, false, true, '7.0', 'stable');
$result = $updater->getJsonChanges();
@@ -73,7 +91,7 @@ public function testMagentoUpdateSetsFieldsNoOverride()
public function testMagentoUpdateSetsFieldsWithOverride()
{
- $updater = new MagentoRootUpdater($this->composer);
+ $updater = new MagentoRootUpdater($this->console, $this->composer);
$updater->runUpdate($this->retriever, true, true, '7.0', 'stable');
$result = $updater->getJsonChanges();
@@ -198,7 +216,7 @@ public function setUp()
* Mock IOInterface for interaction
*/
$this->io = $this->getMockForAbstractClass(IOInterface::class);
- Console::setIO($this->io);
+ $this->console = new Console($this->io);
/**
* Mock package repositories
diff --git a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetrieverTest.php b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetrieverTest.php
index db8692c..1ca9360 100644
--- a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetrieverTest.php
+++ b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetrieverTest.php
@@ -33,6 +33,11 @@ class RootPackageRetrieverTest extends UpdatePluginTestCase
*/
public $io;
+ /**
+ * @var Console $console
+ */
+ public $console;
+
/**
* @var MockObject|PackageInterface $originalRoot
*/
@@ -57,7 +62,14 @@ public function testOverrideOriginalRoot()
{
$this->composer->expects($this->never())->method('getLocker');
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0', 'community', '1.0.0');
+ $retriever = new RootPackageRetriever(
+ $this->console,
+ $this->composer,
+ 'enterprise',
+ '2.0.0',
+ 'community',
+ '1.0.0'
+ );
$this->assertEquals('community', $retriever->getOriginalEdition());
$this->assertEquals('1.0.0', $retriever->getOriginalVersion());
@@ -68,7 +80,7 @@ public function testOriginalRootFromLocker()
{
$this->composer->expects($this->once())->method('getLocker');
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0');
+ $retriever = new RootPackageRetriever($this->console, $this->composer, 'enterprise', '2.0.0');
$this->assertEquals('enterprise', $retriever->getOriginalEdition());
$this->assertEquals('1.1.0.0', $retriever->getOriginalVersion());
@@ -79,7 +91,7 @@ public function testGetOriginalRootFromRepo()
{
$this->repo->method('whatProvides')->willReturn(['1.1.0.0' => $this->originalRoot, '2.0.0.0' => $this->targetRoot]);
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0');
+ $retriever = new RootPackageRetriever($this->console, $this->composer, 'enterprise', '2.0.0');
$retrievedOriginal = $retriever->getOriginalRootPackage(false);
$this->assertEquals($this->originalRoot, $retrievedOriginal);
@@ -89,7 +101,7 @@ public function testGetOriginalRootNotOnRepo_Override()
{
$this->repo->method('whatProvides')->willReturn(['2.0.0.0' => $this->targetRoot]);
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0');
+ $retriever = new RootPackageRetriever($this->console, $this->composer, 'enterprise', '2.0.0');
$retrievedOriginal = $retriever->getOriginalRootPackage(true);
$this->assertEquals($this->userRoot, $retrievedOriginal);
@@ -99,7 +111,7 @@ public function testGetOriginalRootNotOnRepo_NoOverride()
{
$this->repo->method('whatProvides')->willReturn(['2.0.0.0' => $this->targetRoot]);
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0');
+ $retriever = new RootPackageRetriever($this->console, $this->composer, 'enterprise', '2.0.0');
$retrievedOriginal = $retriever->getOriginalRootPackage(false);
$this->assertEquals(null, $retrievedOriginal);
@@ -108,11 +120,11 @@ public function testGetOriginalRootNotOnRepo_NoOverride()
public function testGetOriginalRootNotOnRepo_Confirm()
{
$this->repo->method('whatProvides')->willReturn(['2.0.0.0' => $this->targetRoot]);
- Console::setInteractive('true');
+ $this->console->setInteractive(true);
$this->io->method('isInteractive')->willReturn(true);
$this->io->method('askConfirmation')->willReturn(true);
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0');
+ $retriever = new RootPackageRetriever($this->console, $this->composer, 'enterprise', '2.0.0');
$retrievedOriginal = $retriever->getOriginalRootPackage(false);
$this->assertEquals($this->userRoot, $retrievedOriginal);
@@ -121,11 +133,11 @@ public function testGetOriginalRootNotOnRepo_Confirm()
public function testGetOriginalRootNotOnRepo_NoConfirm()
{
$this->repo->method('whatProvides')->willReturn(['2.0.0.0' => $this->targetRoot]);
- Console::setInteractive('true');
+ $this->console->setInteractive(true);
$this->io->method('isInteractive')->willReturn(true);
$this->io->method('askConfirmation')->willReturn(false);
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0');
+ $retriever = new RootPackageRetriever($this->console, $this->composer, 'enterprise', '2.0.0');
$retrievedOriginal = $retriever->getOriginalRootPackage(false);
$this->assertEquals(null, $retrievedOriginal);
@@ -133,9 +145,11 @@ public function testGetOriginalRootNotOnRepo_NoConfirm()
public function testGetTargetRootFromRepo()
{
- $this->repo->method('whatProvides')->willReturn(['1.1.0.0' => $this->originalRoot, '2.0.0.0' => $this->targetRoot]);
+ $this->repo->method('whatProvides')->willReturn(
+ ['1.1.0.0' => $this->originalRoot, '2.0.0.0' => $this->targetRoot]
+ );
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0');
+ $retriever = new RootPackageRetriever($this->console, $this->composer, 'enterprise', '2.0.0');
$retrievedTarget = $retriever->getTargetRootPackage();
$this->assertEquals($this->targetRoot, $retrievedTarget);
@@ -145,7 +159,7 @@ public function testGetTargetRootNotOnRepo()
{
$this->repo->method('whatProvides')->willReturn(['1.1.0.0' => $this->originalRoot]);
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0');
+ $retriever = new RootPackageRetriever($this->console, $this->composer, 'enterprise', '2.0.0');
$retrievedTarget = $retriever->getTargetRootPackage();
$this->assertEquals(null, $retrievedTarget);
@@ -153,7 +167,7 @@ public function testGetTargetRootNotOnRepo()
public function testGetUserRoot()
{
- $retriever = new RootPackageRetriever($this->composer, 'enterprise', '2.0.0');
+ $retriever = new RootPackageRetriever($this->console, $this->composer, 'enterprise', '2.0.0');
$retrievedTarget = $retriever->getUserRootPackage();
$this->assertEquals($this->userRoot, $retrievedTarget);
@@ -162,8 +176,7 @@ public function testGetUserRoot()
protected function setUp()
{
$this->io = $this->getMockForAbstractClass(IOInterface::class);
- Console::setIO($this->io);
- Console::setInteractive(false);
+ $this->console = new Console($this->io);
$this->composer = $this->createPartialMock(Composer::class, [
'getConfig',