From 520b295820a098b214419d184a78b99466f39f17 Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Mon, 27 Jul 2020 22:23:36 +0200 Subject: [PATCH 1/8] Adds some more colors to the output of certain setup cli commands. --- .../Magento/Framework/Setup/ConsoleLogger.php | 9 ++++++ .../Framework/Setup/LoggerInterface.php | 8 +++++ setup/src/Magento/Setup/Model/Installer.php | 32 +++++++++---------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/ConsoleLogger.php b/lib/internal/Magento/Framework/Setup/ConsoleLogger.php index 01342ebb59b3a..b44e73728e893 100644 --- a/lib/internal/Magento/Framework/Setup/ConsoleLogger.php +++ b/lib/internal/Magento/Framework/Setup/ConsoleLogger.php @@ -88,6 +88,15 @@ public function logMeta($message) $this->console->writeln('' . $message . ''); } + /** + * {@inheritdoc} + */ + public function logMetaInline($message) + { + $this->isInline = true; + $this->console->write('' . $message . ''); + } + /** * Terminates line if the inline logging is started * diff --git a/lib/internal/Magento/Framework/Setup/LoggerInterface.php b/lib/internal/Magento/Framework/Setup/LoggerInterface.php index 169c2acfe9bf5..114325c5420f5 100644 --- a/lib/internal/Magento/Framework/Setup/LoggerInterface.php +++ b/lib/internal/Magento/Framework/Setup/LoggerInterface.php @@ -53,4 +53,12 @@ public function logInline($message); * @return void */ public function logMeta($message); + + /** + * Logs meta information in the current line + * + * @param string $message + * @return void + */ + public function logMetaInline($message); } diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index edcebe4c85f73..1ec5ffa183041 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -378,7 +378,7 @@ public function install($request) $total = count($script) + 4 * count(array_filter($estimatedModules)); $this->progress = new Installer\Progress($total, 0); - $this->log->log('Starting Magento installation:'); + $this->log->logMeta('Starting Magento installation:'); foreach ($script as $item) { list($message, $method, $params) = $item; @@ -893,7 +893,7 @@ public function installSchema(array $request) $this->setupModuleRegistry($setup); $this->setupCoreTables($setup); $this->cleanMemoryTables($setup); - $this->log->log('Schema creation/updates:'); + $this->log->logMeta('Schema creation/updates:'); $this->declarativeInstallSchema($request); $this->handleDBSchemaData($setup, 'schema', $request); /** @var Mysql $adapter */ @@ -952,10 +952,10 @@ public function installDataFixtures(array $request = [], $keepCacheStatuses = fa $this->assertDbAccessible(); $setup = $this->dataSetupFactory->create(); $this->checkFilePermissionsForDbUpgrade(); - $this->log->log('Data install/update:'); + $this->log->logMeta('Data install/update:'); if ($frontendCaches) { - $this->log->log('Disabling caches:'); + $this->log->logMeta('Disabling caches:'); $this->updateCaches(false, $frontendCaches); } @@ -963,7 +963,7 @@ public function installDataFixtures(array $request = [], $keepCacheStatuses = fa $this->handleDBSchemaData($setup, 'data', $request); } finally { if ($frontendCaches) { - $this->log->log('Enabling caches:'); + $this->log->logMeta('Enabling caches:'); $this->updateCaches(true, $frontendCaches); } } @@ -1058,7 +1058,7 @@ private function handleDBSchemaData($setup, $type, array $request) if ($status == \Magento\Framework\Setup\ModuleDataSetupInterface::VERSION_COMPARE_GREATER) { $upgrader = $this->getSchemaDataHandler($moduleName, $upgradeType); if ($upgrader) { - $this->log->logInline("Upgrading $type.. "); + $this->log->logMetaInline("Upgrading $type.. "); $upgrader->upgrade($setup, $moduleContextList[$moduleName]); if ($type === 'schema') { $resource->setDbVersion($moduleName, $configVer); @@ -1070,12 +1070,12 @@ private function handleDBSchemaData($setup, $type, array $request) } elseif ($configVer) { $installer = $this->getSchemaDataHandler($moduleName, $installType); if ($installer) { - $this->log->logInline("Installing $type... "); + $this->log->logMetaInline("Installing $type... "); $installer->install($setup, $moduleContextList[$moduleName]); } $upgrader = $this->getSchemaDataHandler($moduleName, $upgradeType); if ($upgrader) { - $this->log->logInline("Upgrading $type... "); + $this->log->logMetaInline("Upgrading $type... "); $upgrader->upgrade($setup, $moduleContextList[$moduleName]); } } @@ -1101,9 +1101,9 @@ private function handleDBSchemaData($setup, $type, array $request) } if ($type === 'schema') { - $this->log->log('Schema post-updates:'); + $this->log->logMeta('Schema post-updates:'); } elseif ($type === 'data') { - $this->log->log('Data post-updates:'); + $this->log->logMeta('Data post-updates:'); } $handlerType = $type === 'schema' ? 'schema-recurring' : 'data-recurring'; @@ -1116,7 +1116,7 @@ private function handleDBSchemaData($setup, $type, array $request) $this->log->log("Module '{$moduleName}':"); $modulePostUpdater = $this->getSchemaDataHandler($moduleName, $handlerType); if ($modulePostUpdater) { - $this->log->logInline('Running ' . str_replace('-', ' ', $handlerType) . '...'); + $this->log->logMetaInline('Running ' . str_replace('-', ' ', $handlerType) . '...'); $modulePostUpdater->install($setup, $moduleContextList[$moduleName]); } $this->logProgress(); @@ -1371,7 +1371,7 @@ public function updateModulesSequence($keepGeneratedFiles = false) if (!$keepGeneratedFiles) { $this->cleanupGeneratedFiles(); } - $this->log->log('Updating modules:'); + $this->log->logMeta('Updating modules:'); $this->createModulesConfig([]); } @@ -1393,7 +1393,7 @@ public function getModulesConfig() */ public function uninstall() { - $this->log->log('Starting Magento uninstallation:'); + $this->log->logMeta('Starting Magento uninstallation:'); try { $this->cleanCaches(); @@ -1407,7 +1407,7 @@ public function uninstall() $this->cleanupDb(); - $this->log->log('File system cleanup:'); + $this->log->logMeta('File system cleanup:'); $messages = $this->cleanupFiles->clearAllFiles(); foreach ($messages as $message) { $this->log->log($message); @@ -1470,7 +1470,7 @@ private function cleanCaches() $cacheManager = $this->objectManagerProvider->get()->get(Manager::class); $types = $cacheManager->getAvailableTypes(); $cacheManager->clean($types); - $this->log->log('Cache cleared successfully'); + $this->log->logSuccess('Cache cleared successfully'); } /** @@ -1719,7 +1719,7 @@ private function generateListOfModuleContext($resource, $type) */ private function cleanupGeneratedFiles() { - $this->log->log('File system cleanup:'); + $this->log->logMeta('File system cleanup:'); $messages = $this->cleanupFiles->clearCodeGeneratedFiles(); // unload Magento autoloader because it may be using compiled definition From 1a5f10e71a3cf30df6196c730c2703ad5c5e460b Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Tue, 28 Jul 2020 17:10:42 +0200 Subject: [PATCH 2/8] Satisfy static tests. --- .../Magento/Framework/Setup/ConsoleLogger.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/ConsoleLogger.php b/lib/internal/Magento/Framework/Setup/ConsoleLogger.php index b44e73728e893..0421ae6121551 100644 --- a/lib/internal/Magento/Framework/Setup/ConsoleLogger.php +++ b/lib/internal/Magento/Framework/Setup/ConsoleLogger.php @@ -9,11 +9,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Formatter\OutputFormatterStyle; -/** - * Console Logger - * - * @package Magento\Setup\Model - */ class ConsoleLogger implements LoggerInterface { /** @@ -44,7 +39,7 @@ public function __construct(OutputInterface $output) } /** - * {@inheritdoc} + * @inheritdoc */ public function logSuccess($message) { @@ -53,7 +48,7 @@ public function logSuccess($message) } /** - * {@inheritdoc} + * @inheritdoc */ public function logError(\Exception $e) { @@ -62,7 +57,7 @@ public function logError(\Exception $e) } /** - * {@inheritdoc} + * @inheritdoc */ public function log($message) { @@ -71,7 +66,7 @@ public function log($message) } /** - * {@inheritdoc} + * @inheritdoc */ public function logInline($message) { @@ -80,7 +75,7 @@ public function logInline($message) } /** - * {@inheritdoc} + * @inheritdoc */ public function logMeta($message) { @@ -89,7 +84,7 @@ public function logMeta($message) } /** - * {@inheritdoc} + * @inheritdoc */ public function logMetaInline($message) { From 6614b51a0fc8d553709a585ee5350c223ff3f95b Mon Sep 17 00:00:00 2001 From: Viktor Kopin Date: Thu, 1 Oct 2020 16:37:32 +0300 Subject: [PATCH 3/8] magento/magento2#29298: refactoring, unit test fix --- .../Magento/Framework/Setup/ConsoleLogger.php | 2 +- .../Setup/ConsoleLoggerInterface.php | 63 +++++++++++++++ .../Framework/Setup/LoggerInterface.php | 10 +-- setup/src/Magento/Setup/Model/Installer.php | 7 +- .../Magento/Setup/Model/InstallerFactory.php | 6 +- .../Setup/Test/Unit/Model/InstallerTest.php | 79 ++++++++++++------- 6 files changed, 125 insertions(+), 42 deletions(-) create mode 100644 lib/internal/Magento/Framework/Setup/ConsoleLoggerInterface.php diff --git a/lib/internal/Magento/Framework/Setup/ConsoleLogger.php b/lib/internal/Magento/Framework/Setup/ConsoleLogger.php index 0421ae6121551..ba7bb7b4b15bb 100644 --- a/lib/internal/Magento/Framework/Setup/ConsoleLogger.php +++ b/lib/internal/Magento/Framework/Setup/ConsoleLogger.php @@ -9,7 +9,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Formatter\OutputFormatterStyle; -class ConsoleLogger implements LoggerInterface +class ConsoleLogger implements ConsoleLoggerInterface { /** * Indicator of whether inline output is started diff --git a/lib/internal/Magento/Framework/Setup/ConsoleLoggerInterface.php b/lib/internal/Magento/Framework/Setup/ConsoleLoggerInterface.php new file mode 100644 index 0000000000000..c6e0ff1bb37dd --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/ConsoleLoggerInterface.php @@ -0,0 +1,63 @@ +objectManagerProvider->get()->get(Manager::class); $types = empty($types) ? $cacheManager->getAvailableTypes() : $types; $cacheManager->flush($types); - $this->log->log('Cache types ' . implode(',', $types) . ' flushed successfully'); + $this->log->logSuccess('Cache types ' . implode(',', $types) . ' flushed successfully'); } /** diff --git a/setup/src/Magento/Setup/Model/InstallerFactory.php b/setup/src/Magento/Setup/Model/InstallerFactory.php index aeb5be93614fb..d65e15d1f87c6 100644 --- a/setup/src/Magento/Setup/Model/InstallerFactory.php +++ b/setup/src/Magento/Setup/Model/InstallerFactory.php @@ -8,7 +8,7 @@ use Laminas\ServiceManager\ServiceLocatorInterface; use Magento\Framework\App\ErrorHandler; -use Magento\Framework\Setup\LoggerInterface; +use Magento\Framework\Setup\ConsoleLoggerInterface; use Magento\Setup\Module\ResourceFactory; /** @@ -48,11 +48,11 @@ public function __construct( /** * Factory method for installer object * - * @param LoggerInterface $log + * @param ConsoleLoggerInterface $log * @return Installer * @throws \Magento\Setup\Exception */ - public function create(LoggerInterface $log) + public function create(ConsoleLoggerInterface $log) { return new Installer( $this->serviceLocator->get(\Magento\Framework\Setup\FilePermissions::class), diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 8bb9a8da952a6..dda25ff8717cb 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -35,8 +35,8 @@ use Magento\Framework\Module\ModuleResource; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Registry; + use Magento\Framework\Setup\ConsoleLoggerInterface; use Magento\Framework\Setup\FilePermissions; - use Magento\Framework\Setup\LoggerInterface; use Magento\Framework\Setup\Patch\PatchApplier; use Magento\Framework\Setup\Patch\PatchApplierFactory; use Magento\Framework\Setup\SampleData\State; @@ -122,7 +122,7 @@ class InstallerTest extends TestCase private $adminFactory; /** - * @var LoggerInterface|MockObject + * @var ConsoleLoggerInterface|MockObject */ private $logger; @@ -240,7 +240,7 @@ protected function setUp(): void ); $this->moduleLoader = $this->createMock(Loader::class); $this->adminFactory = $this->createMock(AdminAccountFactory::class); - $this->logger = $this->getMockForAbstractClass(LoggerInterface::class); + $this->logger = $this->getMockForAbstractClass(ConsoleLoggerInterface::class); $this->connection = $this->getMockForAbstractClass(AdapterInterface::class); $this->maintenanceMode = $this->createMock(MaintenanceMode::class); $this->filesystem = $this->createMock(Filesystem::class); @@ -452,9 +452,10 @@ public function testInstall(array $request, array $logMessages) ], $logMessages ); - $this->logger->expects($this->exactly(2)) + $this->logger->expects($this->exactly(3)) ->method('logSuccess') ->withConsecutive( + ['Cache cleared successfully'], ['Magento installation complete.'], ['Magento Admin URI: /'] ); @@ -472,16 +473,13 @@ public function installDataProvider() [ 'request' => $this->request, 'logMessages' => [ - ['Starting Magento installation:'], ['File permissions check...'], ['Required extensions check...'], ['Enabling Maintenance Mode...'], ['Installing deployment configuration...'], ['Installing database schema:'], - ['Schema creation/updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Schema post-updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Installing search configuration...'], @@ -492,18 +490,13 @@ public function installDataProvider() ['foo: 1'], ['bar: 1'], ['Installing data...'], - ['Data install/update:'], - ['Disabling caches:'], ['Current status:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Data post-updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Enabling caches:'], ['Current status:'], ['Caches clearing:'], - ['Cache cleared successfully'], ['Disabling Maintenance Mode:'], ['Post installation file permissions check...'], ['Write installation date...'], @@ -524,16 +517,13 @@ public function installDataProvider() AdminAccount::KEY_LAST_NAME => 'Doe' ], 'logMessages' => [ - ['Starting Magento installation:'], ['File permissions check...'], ['Required extensions check...'], ['Enabling Maintenance Mode...'], ['Installing deployment configuration...'], ['Installing database schema:'], - ['Schema creation/updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Schema post-updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Installing search configuration...'], @@ -544,19 +534,14 @@ public function installDataProvider() ['foo: 1'], ['bar: 1'], ['Installing data...'], - ['Data install/update:'], - ['Disabling caches:'], ['Current status:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Data post-updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Enabling caches:'], ['Current status:'], ['Installing admin user...'], ['Caches clearing:'], - ['Cache cleared successfully'], ['Disabling Maintenance Mode:'], ['Post installation file permissions check...'], ['Write installation date...'], @@ -806,13 +791,11 @@ public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploym $request = $this->request; $logMessages = [ - ['Starting Magento installation:'], ['File permissions check...'], ['Required extensions check...'], ['Enabling Maintenance Mode...'], ['Installing deployment configuration...'], ['Installing database schema:'], - ['Schema creation/updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Schema post-updates:'], @@ -822,6 +805,11 @@ public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploym ['Validating remote storage configuration...'], ]; + $logMetaMessages = [ + ['Starting Magento installation:'], + ['Schema creation/updates:'], + ]; + $this->config->expects(static::atLeastOnce()) ->method('get') ->willReturnMap( @@ -961,6 +949,13 @@ public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploym ], $logMessages ); + call_user_func_array( + [ + $this->logger->expects(static::exactly(count($logMetaMessages)))->method('logMeta'), + 'withConsecutive' + ], + $logMetaMessages + ); $this->logger->expects(static::never())->method('logSuccess'); @@ -1175,12 +1170,15 @@ public function testInstallWithInvalidRemoteStorageConfigurationWithEarlyExcepti $request = $this->request; $logMessages = [ - ['Starting Magento installation:'], ['File permissions check...'], ['Required extensions check...'], ['Enabling Maintenance Mode...'], ['Installing deployment configuration...'], ['Installing database schema:'], + ]; + + $logMetaMessages = [ + ['Starting Magento installation:'], ['Schema creation/updates:'] ]; @@ -1285,6 +1283,13 @@ public function testInstallWithInvalidRemoteStorageConfigurationWithEarlyExcepti ], $logMessages ); + call_user_func_array( + [ + $this->logger->expects(static::exactly(count($logMetaMessages)))->method('logMeta'), + 'withConsecutive' + ], + $logMetaMessages + ); $this->logger->expects(static::never())->method('logSuccess'); @@ -1465,8 +1470,13 @@ public function testUpdateModulesSequence() ->withConsecutive( ['Cache types config flushed successfully'], ['Cache cleared successfully'], - ['File system cleanup:'], ['The directory \'/generation\' doesn\'t exist - skipping cleanup'], + ); + + $this->logger + ->method('logMeta') + ->withConsecutive( + ['File system cleanup:'], ['Updating modules:'] ); @@ -1483,6 +1493,11 @@ public function testUpdateModulesSequenceKeepGenerated() ->withConsecutive( ['Cache types config flushed successfully'], ['Cache cleared successfully'], + ); + + $this->logger + ->method('logMeta') + ->withConsecutive( ['Updating modules:'] ); @@ -1542,16 +1557,26 @@ public function testUninstall(): void $this->logger ->method('log') ->withConsecutive( - ['Starting Magento uninstallation:'], - ['Cache cleared successfully'], ['No database connection defined - skipping database cleanup'], - ['File system cleanup:'], ["The directory '/var' doesn't exist - skipping cleanup"], ["The directory '/static' doesn't exist - skipping cleanup"], ["The file '/config/ConfigOne.php' doesn't exist - skipping cleanup"], ["The file '/config/ConfigTwo.php' doesn't exist - skipping cleanup"] ); + $this->logger + ->method('logMeta') + ->withConsecutive( + ['Starting Magento uninstallation:'], + ['File system cleanup:'], + ); + + $this->logger + ->method('logSuccess') + ->withConsecutive( + ['Cache cleared successfully'], + ); + $this->object->uninstall(); } From 5d20ea52e62ccf007c0a631ad646c9b7e18bfa9a Mon Sep 17 00:00:00 2001 From: "taras.gamanov" Date: Mon, 5 Oct 2020 10:53:19 +0300 Subject: [PATCH 4/8] Code refactoring --- .../Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php index adc451e6c473b..16b54411f00c1 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php @@ -20,8 +20,8 @@ use Magento\Framework\Model\ResourceModel\Db\TransactionManager; use Magento\Framework\Module\ModuleList; use Magento\Framework\Module\ModuleList\Loader; +use Magento\Framework\Setup\ConsoleLoggerInterface; use Magento\Framework\Setup\FilePermissions; -use Magento\Framework\Setup\LoggerInterface; use Magento\Framework\Setup\SampleData\State; use Magento\Framework\Setup\SchemaPersistor; use Magento\Setup\Model\AdminAccountFactory; @@ -80,8 +80,8 @@ public function testCreate() $serviceLocatorMock->expects($this->any())->method('get') ->willReturnMap($this->getReturnValueMap()); - /** @var LoggerInterface|MockObject $log */ - $log = $this->getMockForAbstractClass(LoggerInterface::class); + /** @var ConsoleLoggerInterface|MockObject $log */ + $log = $this->getMockForAbstractClass(ConsoleLoggerInterface::class); /** @var ResourceFactory|MockObject $resourceFactoryMock */ $resourceFactoryMock = $this->createMock(ResourceFactory::class); $resourceFactoryMock From 5d03c0dc8b94f4717dad09f93011b7f177f1dbdd Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Sat, 23 Oct 2021 15:54:20 +0200 Subject: [PATCH 5/8] Fixed 'deprecated' typo. --- lib/internal/Magento/Framework/Setup/LoggerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Setup/LoggerInterface.php b/lib/internal/Magento/Framework/Setup/LoggerInterface.php index 8a52afb3787e3..1e2d73b1aee4b 100644 --- a/lib/internal/Magento/Framework/Setup/LoggerInterface.php +++ b/lib/internal/Magento/Framework/Setup/LoggerInterface.php @@ -10,7 +10,7 @@ * Interface to Log Message in Setup * * @api - * @deprecared + * @deprecated * * @since 100.0.2 */ From 7a5e0f6b72c55716a1fb740205b9392bc593cea2 Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Sat, 23 Oct 2021 16:13:21 +0200 Subject: [PATCH 6/8] Removes usages of the now deprecated Setup\LoggerInterface class in the codebase. --- lib/internal/Magento/Framework/Setup/BackupRollback.php | 6 +++--- .../Framework/Setup/Test/Unit/BackupRollbackTest.php | 6 +++--- setup/src/Magento/Setup/Model/Installer.php | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/BackupRollback.php b/lib/internal/Magento/Framework/Setup/BackupRollback.php index 201220c71ffc1..1a1a185cf9d6c 100644 --- a/lib/internal/Magento/Framework/Setup/BackupRollback.php +++ b/lib/internal/Magento/Framework/Setup/BackupRollback.php @@ -42,7 +42,7 @@ class BackupRollback /** * Logger * - * @var LoggerInterface + * @var ConsoleLoggerInterface */ private $log; @@ -69,14 +69,14 @@ class BackupRollback * Constructor * * @param ObjectManagerInterface $objectManager - * @param LoggerInterface $log + * @param ConsoleLoggerInterface $log * @param DirectoryList $directoryList * @param File $file * @param Helper $fsHelper */ public function __construct( ObjectManagerInterface $objectManager, - LoggerInterface $log, + ConsoleLoggerInterface $log, DirectoryList $directoryList, File $file, Helper $fsHelper diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php index 548d6c0970c14..a4e4c80781b8d 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php @@ -18,7 +18,7 @@ use Magento\Framework\ObjectManager\ConfigLoaderInterface; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Setup\BackupRollback; -use Magento\Framework\Setup\LoggerInterface; +use Magento\Framework\Setup\ConsoleLoggerInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -33,7 +33,7 @@ class BackupRollbackTest extends TestCase private $objectManager; /** - * @var LoggerInterface|MockObject + * @var ConsoleLoggerInterface|MockObject */ private $log; @@ -75,7 +75,7 @@ class BackupRollbackTest extends TestCase protected function setUp(): void { $this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class); - $this->log = $this->getMockForAbstractClass(LoggerInterface::class); + $this->log = $this->getMockForAbstractClass(ConsoleLoggerInterface::class); $this->directoryList = $this->createMock(DirectoryList::class); $this->path = realpath(__DIR__); $this->directoryList->expects($this->any()) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 2a61c75dd44f9..fa0dd07ffef08 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -37,7 +37,6 @@ use Magento\Framework\Setup\FilePermissions; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\InstallSchemaInterface; -use Magento\Framework\Setup\LoggerInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\PatchApplier; use Magento\Framework\Setup\Patch\PatchApplierFactory; @@ -136,7 +135,7 @@ class Installer /** * Logger * - * @var LoggerInterface + * @var ConsoleLoggerInterface */ private $log; From 2d59cb8e60d41910a0b739a960b5199354d8208b Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Mon, 25 Oct 2021 19:53:57 +0200 Subject: [PATCH 7/8] More static test fixes. --- lib/internal/Magento/Framework/Setup/BackupRollback.php | 3 --- lib/internal/Magento/Framework/Setup/ConsoleLogger.php | 2 -- .../Magento/Framework/Setup/ConsoleLoggerInterface.php | 1 + lib/internal/Magento/Framework/Setup/LoggerInterface.php | 3 ++- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/internal/Magento/Framework/Setup/BackupRollback.php b/lib/internal/Magento/Framework/Setup/BackupRollback.php index 1a1a185cf9d6c..cc55fc3e04747 100644 --- a/lib/internal/Magento/Framework/Setup/BackupRollback.php +++ b/lib/internal/Magento/Framework/Setup/BackupRollback.php @@ -22,9 +22,6 @@ */ class BackupRollback { - /** - * Default backup directory - */ public const DEFAULT_BACKUP_DIRECTORY = 'backups'; /** diff --git a/lib/internal/Magento/Framework/Setup/ConsoleLogger.php b/lib/internal/Magento/Framework/Setup/ConsoleLogger.php index ba7bb7b4b15bb..47c8475c0f8d8 100644 --- a/lib/internal/Magento/Framework/Setup/ConsoleLogger.php +++ b/lib/internal/Magento/Framework/Setup/ConsoleLogger.php @@ -19,8 +19,6 @@ class ConsoleLogger implements ConsoleLoggerInterface private $isInline = false; /** - * Console - * * @var OutputInterface */ protected $console; diff --git a/lib/internal/Magento/Framework/Setup/ConsoleLoggerInterface.php b/lib/internal/Magento/Framework/Setup/ConsoleLoggerInterface.php index c6e0ff1bb37dd..e727a1dedb3e7 100644 --- a/lib/internal/Magento/Framework/Setup/ConsoleLoggerInterface.php +++ b/lib/internal/Magento/Framework/Setup/ConsoleLoggerInterface.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Framework\Setup; diff --git a/lib/internal/Magento/Framework/Setup/LoggerInterface.php b/lib/internal/Magento/Framework/Setup/LoggerInterface.php index 1e2d73b1aee4b..3ee8bdd277ea2 100644 --- a/lib/internal/Magento/Framework/Setup/LoggerInterface.php +++ b/lib/internal/Magento/Framework/Setup/LoggerInterface.php @@ -10,7 +10,8 @@ * Interface to Log Message in Setup * * @api - * @deprecated + * @deprecated Replaced with ConsoleLogger + * @see Magento\Framework\Setup\ConsoleLogger * * @since 100.0.2 */ From b99ac917615a1444dd3c5623ab59ef5760b3a27b Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Wed, 5 Apr 2023 23:35:25 +0200 Subject: [PATCH 8/8] Fixed unit tests (I think) --- .../Setup/Test/Unit/Model/InstallerTest.php | 171 +++++++++++++++--- 1 file changed, 149 insertions(+), 22 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index dda25ff8717cb..43b0c6689f43f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -318,10 +318,11 @@ private function createObject($connectionFactory = false, $objectManagerProvider /** * @param array $request * @param array $logMessages + * @param array $logMetaMessages * @dataProvider installDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testInstall(array $request, array $logMessages) + public function testInstall(array $request, array $logMessages, array $logMetaMessages) { $this->moduleList->method('getOne') ->willReturnMap( @@ -452,6 +453,13 @@ public function testInstall(array $request, array $logMessages) ], $logMessages ); + call_user_func_array( + [ + $this->logger->expects($this->exactly(count($logMetaMessages)))->method('logMeta'), + 'withConsecutive' + ], + $logMetaMessages + ); $this->logger->expects($this->exactly(3)) ->method('logSuccess') ->withConsecutive( @@ -502,6 +510,37 @@ public function installDataProvider() ['Write installation date...'], ['Sample Data is installed with errors. See log file for details'] ], + 'logMetaMessages' => [ + ['Starting Magento installation:'], + ['[Progress: 1 / 22]'], + ['[Progress: 2 / 22]'], + ['[Progress: 3 / 22]'], + ['[Progress: 4 / 22]'], + ['Schema creation/updates:'], + ['[Progress: 5 / 22]'], + ['[Progress: 6 / 22]'], + ['Schema post-updates:'], + ['[Progress: 7 / 22]'], + ['[Progress: 8 / 22]'], + ['[Progress: 9 / 22]'], + ['[Progress: 10 / 22]'], + ['[Progress: 11 / 22]'], + ['[Progress: 12 / 22]'], + ['[Progress: 13 / 22]'], + ['Data install/update:'], + ['Disabling caches:'], + ['[Progress: 14 / 22]'], + ['[Progress: 15 / 22]'], + ['Data post-updates:'], + ['[Progress: 16 / 22]'], + ['[Progress: 17 / 22]'], + ['Enabling caches:'], + ['[Progress: 18 / 22]'], + ['[Progress: 19 / 22]'], + ['[Progress: 20 / 22]'], + ['[Progress: 21 / 22]'], + ['[Progress: 22 / 22]'], + ], ], [ 'request' => [ @@ -547,6 +586,38 @@ public function installDataProvider() ['Write installation date...'], ['Sample Data is installed with errors. See log file for details'] ], + 'logMetaMessages' => [ + ['Starting Magento installation:'], + ['[Progress: 1 / 23]'], + ['[Progress: 2 / 23]'], + ['[Progress: 3 / 23]'], + ['[Progress: 4 / 23]'], + ['Schema creation/updates:'], + ['[Progress: 5 / 23]'], + ['[Progress: 6 / 23]'], + ['Schema post-updates:'], + ['[Progress: 7 / 23]'], + ['[Progress: 8 / 23]'], + ['[Progress: 9 / 23]'], + ['[Progress: 10 / 23]'], + ['[Progress: 11 / 23]'], + ['[Progress: 12 / 23]'], + ['[Progress: 13 / 23]'], + ['Data install/update:'], + ['Disabling caches:'], + ['[Progress: 14 / 23]'], + ['[Progress: 15 / 23]'], + ['Data post-updates:'], + ['[Progress: 16 / 23]'], + ['[Progress: 17 / 23]'], + ['Enabling caches:'], + ['[Progress: 18 / 23]'], + ['[Progress: 19 / 23]'], + ['[Progress: 20 / 23]'], + ['[Progress: 21 / 23]'], + ['[Progress: 22 / 23]'], + ['[Progress: 23 / 23]'], + ], ], ]; } @@ -556,13 +627,14 @@ public function installDataProvider() * * @param array $request * @param array $logMessages + * @param array $logMetaMessages * @throws RuntimeException * @throws FileSystemException * @throws LocalizedException * @dataProvider installWithOrderIncrementPrefixDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testInstallWithOrderIncrementPrefix(array $request, array $logMessages) + public function testInstallWithOrderIncrementPrefix(array $request, array $logMessages, array $logMetaMessages) { $this->moduleList->method('getOne') ->willReturnMap( @@ -706,9 +778,17 @@ public function testInstallWithOrderIncrementPrefix(array $request, array $logMe ], $logMessages ); - $this->logger->expects($this->exactly(2)) + call_user_func_array( + [ + $this->logger->expects($this->exactly(count($logMetaMessages)))->method('logMeta'), + 'withConsecutive' + ], + $logMetaMessages + ); + $this->logger->expects($this->exactly(3)) ->method('logSuccess') ->withConsecutive( + ['Cache cleared successfully'], ['Magento installation complete.'], ['Magento Admin URI: /'] ); @@ -733,16 +813,13 @@ public function installWithOrderIncrementPrefixDataProvider(): array InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX => 'ORD' ], 'logMessages' => [ - ['Starting Magento installation:'], ['File permissions check...'], ['Required extensions check...'], ['Enabling Maintenance Mode...'], ['Installing deployment configuration...'], ['Installing database schema:'], - ['Schema creation/updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Schema post-updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Installing search configuration...'], @@ -753,24 +830,51 @@ public function installWithOrderIncrementPrefixDataProvider(): array ['foo: 1'], ['bar: 1'], ['Installing data...'], - ['Data install/update:'], - ['Disabling caches:'], ['Current status:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Data post-updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Enabling caches:'], ['Current status:'], ['Creating sales order increment prefix...'], // << added ['Caches clearing:'], - ['Cache cleared successfully'], ['Disabling Maintenance Mode:'], ['Post installation file permissions check...'], ['Write installation date...'], ['Sample Data is installed with errors. See log file for details'] ], + 'logMetaMessages' => [ + ['Starting Magento installation:'], + ['[Progress: 1 / 23]'], + ['[Progress: 2 / 23]'], + ['[Progress: 3 / 23]'], + ['[Progress: 4 / 23]'], + ['Schema creation/updates:'], + ['[Progress: 5 / 23]'], + ['[Progress: 6 / 23]'], + ['Schema post-updates:'], + ['[Progress: 7 / 23]'], + ['[Progress: 8 / 23]'], + ['[Progress: 9 / 23]'], + ['[Progress: 10 / 23]'], + ['[Progress: 11 / 23]'], + ['[Progress: 12 / 23]'], + ['[Progress: 13 / 23]'], + ['Data install/update:'], + ['Disabling caches:'], + ['[Progress: 14 / 23]'], + ['[Progress: 15 / 23]'], + ['Data post-updates:'], + ['[Progress: 16 / 23]'], + ['[Progress: 17 / 23]'], + ['Enabling caches:'], + ['[Progress: 18 / 23]'], + ['[Progress: 19 / 23]'], + ['[Progress: 20 / 23]'], + ['[Progress: 21 / 23]'], + ['[Progress: 22 / 23]'], + ['[Progress: 23 / 23]'], + ], ], ]; } @@ -798,7 +902,6 @@ public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploym ['Installing database schema:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - ['Schema post-updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Installing search configuration...'], @@ -807,7 +910,18 @@ public function testInstallWithInvalidRemoteStorageConfiguration(bool $isDeploym $logMetaMessages = [ ['Starting Magento installation:'], + ['[Progress: 1 / 22]'], + ['[Progress: 2 / 22]'], + ['[Progress: 3 / 22]'], + ['[Progress: 4 / 22]'], ['Schema creation/updates:'], + ['[Progress: 5 / 22]'], + ['[Progress: 6 / 22]'], + ['Schema post-updates:'], + ['[Progress: 7 / 22]'], + ['[Progress: 8 / 22]'], + ['[Progress: 9 / 22]'], + ['[Progress: 10 / 22]'], ]; $this->config->expects(static::atLeastOnce()) @@ -988,6 +1102,7 @@ public function testInstallWithUnresolvableRemoteStorageValidator() // every log message call is expected $logMessages = $this->installDataProvider()[0]['logMessages']; + $logMetaMessages = $this->installDataProvider()[0]['logMetaMessages']; $this->config->expects(static::atLeastOnce()) ->method('get') @@ -1145,9 +1260,17 @@ public function testInstallWithUnresolvableRemoteStorageValidator() ], $logMessages ); - $this->logger->expects(static::exactly(2)) + call_user_func_array( + [ + $this->logger->expects(static::exactly(count($logMetaMessages)))->method('logMeta'), + 'withConsecutive' + ], + $logMetaMessages + ); + $this->logger->expects(static::exactly(3)) ->method('logSuccess') ->withConsecutive( + ['Cache cleared successfully'], ['Magento installation complete.'], ['Magento Admin URI: /'] ); @@ -1179,7 +1302,11 @@ public function testInstallWithInvalidRemoteStorageConfigurationWithEarlyExcepti $logMetaMessages = [ ['Starting Magento installation:'], - ['Schema creation/updates:'] + ['[Progress: 1 / 22]'], + ['[Progress: 2 / 22]'], + ['[Progress: 3 / 22]'], + ['[Progress: 4 / 22]'], + ['Schema creation/updates:'], ]; $this->config->expects(static::atLeastOnce()) @@ -1468,17 +1595,20 @@ public function testUpdateModulesSequence() $this->logger ->method('log') ->withConsecutive( - ['Cache types config flushed successfully'], - ['Cache cleared successfully'], ['The directory \'/generation\' doesn\'t exist - skipping cleanup'], ); - $this->logger ->method('logMeta') ->withConsecutive( ['File system cleanup:'], ['Updating modules:'] ); + $this->logger + ->method('logSuccess') + ->withConsecutive( + ['Cache types config flushed successfully'], + ['Cache cleared successfully'], + ); $installer->updateModulesSequence(false); } @@ -1489,12 +1619,11 @@ public function testUpdateModulesSequenceKeepGenerated() $installer = $this->prepareForUpdateModulesTests(); $this->logger - ->method('log') + ->method('logSuccess') ->withConsecutive( ['Cache types config flushed successfully'], ['Cache cleared successfully'], ); - $this->logger ->method('logMeta') ->withConsecutive( @@ -1546,7 +1675,6 @@ public function testUninstall(): void ->method('get') ->with(Manager::class) ->willReturn($cacheManager); - $this->logger->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.'); $this->cleanupFiles->expects($this->once())->method('clearAllFiles')->willReturn( [ "The directory '/var' doesn't exist - skipping cleanup", @@ -1563,18 +1691,17 @@ public function testUninstall(): void ["The file '/config/ConfigOne.php' doesn't exist - skipping cleanup"], ["The file '/config/ConfigTwo.php' doesn't exist - skipping cleanup"] ); - $this->logger ->method('logMeta') ->withConsecutive( ['Starting Magento uninstallation:'], ['File system cleanup:'], ); - $this->logger ->method('logSuccess') ->withConsecutive( ['Cache cleared successfully'], + ['Magento uninstallation complete.'], ); $this->object->uninstall();