From 54a11eb67d5ad3b0f2ca0160dcfa936d50b44d33 Mon Sep 17 00:00:00 2001 From: Quang Do Date: Wed, 25 Mar 2020 11:31:53 +1030 Subject: [PATCH 01/22] Add ACL role ID to category tree cache id --- .../DataProvider/Product/Form/Modifier/Categories.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php index cd1f8e8e3379b..46302185735f9 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php @@ -18,6 +18,7 @@ use Magento\Framework\UrlInterface; use Magento\Framework\Stdlib\ArrayManager; use Magento\Framework\AuthorizationInterface; +use Magento\Backend\Model\Auth\Session; /** * Data provider for categories field of product page @@ -86,12 +87,18 @@ class Categories extends AbstractModifier */ private $authorization; + /** + * @var Session + */ + private $session; + /** * @param LocatorInterface $locator * @param CategoryCollectionFactory $categoryCollectionFactory * @param DbHelper $dbHelper * @param UrlInterface $urlBuilder * @param ArrayManager $arrayManager + * @param Session $session * @param SerializerInterface $serializer * @param AuthorizationInterface $authorization */ @@ -101,6 +108,7 @@ public function __construct( DbHelper $dbHelper, UrlInterface $urlBuilder, ArrayManager $arrayManager, + Session $session, SerializerInterface $serializer = null, AuthorizationInterface $authorization = null ) { @@ -111,6 +119,7 @@ public function __construct( $this->arrayManager = $arrayManager; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); $this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class); + $this->session = $session; } /** @@ -373,6 +382,7 @@ private function getCategoriesTreeCacheId(int $storeId, string $filter = '') : s { return self::CATEGORY_TREE_ID . '_' . (string) $storeId + . '_' . $this->session->getUser()->getAclRole() . '_' . $filter; } From f1c8ad56edcad49fd51288e3a0dbf2df74505df5 Mon Sep 17 00:00:00 2001 From: Quang Do Date: Wed, 25 Mar 2020 15:21:27 +1030 Subject: [PATCH 02/22] Ensure constructor change is backwards compatible --- .../Ui/DataProvider/Product/Form/Modifier/Categories.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php index 46302185735f9..b5b270e17a581 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php @@ -98,9 +98,9 @@ class Categories extends AbstractModifier * @param DbHelper $dbHelper * @param UrlInterface $urlBuilder * @param ArrayManager $arrayManager - * @param Session $session * @param SerializerInterface $serializer * @param AuthorizationInterface $authorization + * @param Session $session */ public function __construct( LocatorInterface $locator, @@ -108,9 +108,9 @@ public function __construct( DbHelper $dbHelper, UrlInterface $urlBuilder, ArrayManager $arrayManager, - Session $session, SerializerInterface $serializer = null, - AuthorizationInterface $authorization = null + AuthorizationInterface $authorization = null, + Session $session = null ) { $this->locator = $locator; $this->categoryCollectionFactory = $categoryCollectionFactory; @@ -119,7 +119,7 @@ public function __construct( $this->arrayManager = $arrayManager; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); $this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class); - $this->session = $session; + $this->session = $session ?: ObjectManager::getInstance()->get(Session::class); } /** From 207a44956715bee23dbd7c0ded5735283299f9cc Mon Sep 17 00:00:00 2001 From: Quang Do Date: Wed, 25 Mar 2020 15:22:09 +1030 Subject: [PATCH 03/22] Suppress CookieAndSessionMisuse --- .../Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php index b5b270e17a581..1c04879ef36da 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php @@ -25,6 +25,7 @@ * * @api * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) * @since 101.0.0 */ class Categories extends AbstractModifier From 61f847ec3edbf7c91ae7158d81778109c0821fbc Mon Sep 17 00:00:00 2001 From: Quang Do Date: Wed, 25 Mar 2020 15:25:35 +1030 Subject: [PATCH 04/22] Add null check for admin session user --- .../DataProvider/Product/Form/Modifier/Categories.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php index 1c04879ef36da..ce5b740fe5fb0 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php @@ -379,11 +379,16 @@ protected function getCategoriesTree($filter = null) * @param string $filter * @return string */ - private function getCategoriesTreeCacheId(int $storeId, string $filter = '') : string + private function getCategoriesTreeCacheId(int $storeId, string $filter = ''): string { + if ($this->session->getUser() !== null) { + return self::CATEGORY_TREE_ID + . '_' . (string)$storeId + . '_' . $this->session->getUser()->getAclRole() + . '_' . $filter; + } return self::CATEGORY_TREE_ID - . '_' . (string) $storeId - . '_' . $this->session->getUser()->getAclRole() + . '_' . (string)$storeId . '_' . $filter; } From d95a65adde03f8a573b0b1dd15d0c5a247d8d99d Mon Sep 17 00:00:00 2001 From: Sathish Date: Fri, 3 Apr 2020 22:38:09 +0530 Subject: [PATCH 05/22] #27091 removed array print while setup upgrade --- setup/src/Magento/Setup/Model/Installer.php | 14 +- .../Setup/Test/Unit/Model/InstallerTest.php | 1413 +++++++++-------- 2 files changed, 754 insertions(+), 673 deletions(-) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 535040f942b89..bfab9b68e4aaf 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -46,6 +46,7 @@ use Magento\Setup\Module\SetupFactory; use Magento\Setup\Validator\DbValidator; use Magento\Store\Model\Store; +use Magento\Framework\App\Cache\Manager; /** * Class Installer contains the logic to install Magento application. @@ -1272,8 +1273,8 @@ public function uninstall() */ private function updateCaches($isEnabled, $types = []) { - /** @var \Magento\Framework\App\Cache\Manager $cacheManager */ - $cacheManager = $this->objectManagerProvider->get()->create(\Magento\Framework\App\Cache\Manager::class); + /** @var Manager $cacheManager */ + $cacheManager = $this->objectManagerProvider->get()->create(Manager::class); $availableTypes = $cacheManager->getAvailableTypes(); $types = empty($types) ? $availableTypes : array_intersect($availableTypes, $types); @@ -1292,8 +1293,9 @@ function (string $key) use ($types) { ); $this->log->log('Current status:'); - // phpcs:ignore Magento2.Functions.DiscouragedFunction - $this->log->log(print_r($cacheStatus, true)); + foreach ($cacheStatus as $cache => $status) { + $this->log->log(sprintf('%s: %d', $cache, $status)); + } } /** @@ -1305,8 +1307,8 @@ function (string $key) use ($types) { */ private function cleanCaches() { - /** @var \Magento\Framework\App\Cache\Manager $cacheManager */ - $cacheManager = $this->objectManagerProvider->get()->get(\Magento\Framework\App\Cache\Manager::class); + /** @var Manager $cacheManager */ + $cacheManager = $this->objectManagerProvider->get()->get(Manager::class); $types = $cacheManager->getAvailableTypes(); $cacheManager->clean($types); $this->log->log('Cache cleared successfully'); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 2b992c30615c2..1f9afb04c07dd 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -3,723 +3,802 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + +namespace Magento\Setup\Test\Unit\Model; + +use Magento\Backend\Setup\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsListConstants; +use Magento\Framework\Setup\SchemaListener; +use Magento\Setup\Model\AdminAccount; +use Magento\Setup\Model\DeclarationInstaller; +use Magento\Setup\Model\Installer; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem\DriverPool; +use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\App\State as MFAState; +use Magento\Framework\App\State\CleanupFiles; +use Magento\Framework\Setup\Patch\PatchApplier; +use Magento\Framework\Setup\Patch\PatchApplierFactory; +use Magento\Setup\Validator\DbValidator; +use Magento\Framework\Setup\FilePermissions; +use Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Module\ModuleListInterface; +use Magento\Framework\Module\ModuleList\Loader; +use Magento\Setup\Model\AdminAccountFactory; +use Magento\Framework\Setup\LoggerInterface; +use Magento\Framework\Math\Random; +use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Setup\Module\ConnectionFactory; +use Magento\Framework\App\MaintenanceMode; +use Magento\Framework\Filesystem; +use Magento\Setup\Model\PhpReadinessCheck; +use Magento\Framework\Model\ResourceModel\Db\Context; +use Magento\Framework\Component\ComponentRegistrar; +use Magento\Framework\Setup\SampleData\State; +use Magento\Setup\Module\DataSetupFactory; +use Magento\Setup\Module\DataSetup; +use Magento\Setup\Module\SetupFactory; +use Magento\Setup\Model\ConfigModel; +use Magento\Setup\Module\Setup; +use Magento\Framework\DB\Ddl\Table; +use Magento\Framework\App\ResourceConnection; +use Magento\Framework\App\Cache\Manager; +use Magento\Framework\Registry; +use Magento\Framework\App\Area; +use Magento\Setup\Controller\ResponseTypeInterface; +use Magento\Framework\Filesystem\Directory\WriteInterface; +use Magento\Setup\Model\ObjectManagerProvider; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; -namespace Magento\Setup\Test\Unit\Model { +/** + * Unit test for Magento\Setup\Model\Installer + * + * @SuppressWarnings(PHPMD.TooManyFields) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class InstallerTest extends TestCase +{ + /** + * @var Installer + */ + private $object; - use Magento\Backend\Setup\ConfigOptionsList; - use Magento\Framework\Config\ConfigOptionsListConstants; - use Magento\Framework\Setup\SchemaListener; - use Magento\Setup\Model\AdminAccount; - use Magento\Setup\Model\DeclarationInstaller; - use Magento\Setup\Model\Installer; - use Magento\Framework\App\Filesystem\DirectoryList; - use Magento\Framework\Filesystem\DriverPool; - use Magento\Framework\Config\File\ConfigFilePool; - use Magento\Framework\App\State\CleanupFiles; - use Magento\Framework\Setup\Patch\PatchApplier; - use Magento\Framework\Setup\Patch\PatchApplierFactory; - use Magento\Setup\Validator\DbValidator; + /** + * @var FilePermissions|MockObject + */ + private $filePermissionsMock; /** - * @SuppressWarnings(PHPMD.TooManyFields) - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @var Writer|MockObject */ - class InstallerTest extends \PHPUnit\Framework\TestCase - { - /** - * @var \Magento\Setup\Model\Installer - */ - private $object; - - /** - * @var \Magento\Framework\Setup\FilePermissions|\PHPUnit_Framework_MockObject_MockObject - */ - private $filePermissions; - - /** - * @var \Magento\Framework\App\DeploymentConfig\Writer|\PHPUnit_Framework_MockObject_MockObject - */ - private $configWriter; - - /** - * @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject - */ - private $configReader; - - /** - * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject - */ - private $config; - - /** - * @var \Magento\Framework\Module\ModuleListInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $moduleList; - - /** - * @var \Magento\Framework\Module\ModuleList\Loader|\PHPUnit_Framework_MockObject_MockObject - */ - private $moduleLoader; - - /** - * @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject - */ - private $directoryList; - - /** - * @var \Magento\Setup\Model\AdminAccountFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $adminFactory; - - /** - * @var \Magento\Framework\Setup\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $logger; - - /** - * @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject - */ - private $random; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $connection; - - /** - * @var \Magento\Framework\App\MaintenanceMode|\PHPUnit_Framework_MockObject_MockObject - */ - private $maintenanceMode; - - /** - * @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject - */ - private $filesystem; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $objectManager; - - /** - * @var \Magento\Setup\Model\ConfigModel|\PHPUnit_Framework_MockObject_MockObject - */ - private $configModel; - - /** - * @var CleanupFiles|\PHPUnit_Framework_MockObject_MockObject - */ - private $cleanupFiles; - - /** - * @var DbValidator|\PHPUnit_Framework_MockObject_MockObject - */ - private $dbValidator; - - /** - * @var \Magento\Setup\Module\SetupFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $setupFactory; - - /** - * @var \Magento\Setup\Module\DataSetupFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $dataSetupFactory; - - /** - * @var \Magento\Framework\Setup\SampleData\State|\PHPUnit_Framework_MockObject_MockObject - */ - private $sampleDataState; - - /** - * @var \Magento\Framework\Component\ComponentRegistrar|\PHPUnit_Framework_MockObject_MockObject - */ - private $componentRegistrar; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\PhpReadinessCheck - */ - private $phpReadinessCheck; - - /** - * @var \Magento\Framework\Setup\DeclarationInstaller|\PHPUnit_Framework_MockObject_MockObject - */ - private $declarationInstallerMock; - - /** - * @var SchemaListener|\PHPUnit_Framework_MockObject_MockObject - */ - private $schemaListenerMock; - - /** - * Sample DB configuration segment - * @var array - */ - private static $dbConfig = [ - 'default' => [ - ConfigOptionsListConstants::KEY_HOST => '127.0.0.1', - ConfigOptionsListConstants::KEY_NAME => 'magento', - ConfigOptionsListConstants::KEY_USER => 'magento', - ConfigOptionsListConstants::KEY_PASSWORD => '', - ] - ]; + private $configWriterMock; + + /** + * @var Reader|MockObject + */ + private $configReaderMock; + + /** + * @var DeploymentConfig|MockObject + */ + private $configMock; + + /** + * @var ModuleListInterface|MockObject + */ + private $moduleListMock; + + /** + * @var Loader|MockObject + */ + private $moduleLoaderMock; - /** - * @var \Magento\Framework\Model\ResourceModel\Db\Context|\PHPUnit_Framework_MockObject_MockObject - */ - private $contextMock; - - /** - * @var PatchApplier|\PHPUnit_Framework_MockObject_MockObject - */ - private $patchApplierMock; - - /** - * @var PatchApplierFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $patchApplierFactoryMock; - - protected function setUp() - { - $this->filePermissions = $this->createMock(\Magento\Framework\Setup\FilePermissions::class); - $this->configWriter = $this->createMock(\Magento\Framework\App\DeploymentConfig\Writer::class); - $this->configReader = $this->createMock(\Magento\Framework\App\DeploymentConfig\Reader::class); - $this->config = $this->createMock(\Magento\Framework\App\DeploymentConfig::class); - - $this->moduleList = $this->getMockForAbstractClass(\Magento\Framework\Module\ModuleListInterface::class); - $this->moduleList->expects($this->any())->method('getOne')->willReturn( + /** + * @var AdminAccountFactory|MockObject + */ + private $adminFactoryMock; + + /** + * @var LoggerInterface|MockObject + */ + private $loggerMock; + + /** + * @var Random|MockObject + */ + private $randomMock; + + /** + * @var AdapterInterface|MockObject + */ + private $connectionMock; + + /** + * @var MaintenanceMode|MockObject + */ + private $maintenanceModeMock; + + /** + * @var Filesystem|MockObject + */ + private $filesystemMock; + + /** + * @var ObjectManager|MockObject + */ + private $objectManager; + + /** + * @var ConfigModel|MockObject + */ + private $configModelMock; + + /** + * @var CleanupFiles|MockObject + */ + private $cleanupFilesMock; + + /** + * @var DbValidator|MockObject + */ + private $dbValidatorMock; + + /** + * @var SetupFactory|MockObject + */ + private $setupFactoryMock; + + /** + * @var DataSetupFactory|MockObject + */ + private $dataSetupFactoryMock; + + /** + * @var State|MockObject + */ + private $sampleDataStateMock; + + /** + * @var ComponentRegistrar|MockObject + */ + private $componentRegistrarMock; + + /** + * @var PhpReadinessCheck|MockObject + */ + private $phpReadinessCheckMock; + + /** + * @var DeclarationInstaller|MockObject + */ + private $declarationInstallerMock; + + /** + * @var SchemaListener|MockObject + */ + private $schemaListenerMock; + + /** + * @var Context|MockObject + */ + private $contextMock; + + /** + * @var PatchApplier|MockObject + */ + private $patchApplierMock; + + /** + * @var PatchApplierFactory|MockObject + */ + private $patchApplierFactoryMock; + + /** + * Sample DB configuration segment + * @var array + */ + private static $dbConfig = [ + 'default' => [ + ConfigOptionsListConstants::KEY_HOST => '127.0.0.1', + ConfigOptionsListConstants::KEY_NAME => 'magento', + ConfigOptionsListConstants::KEY_USER => 'magento', + ConfigOptionsListConstants::KEY_PASSWORD => '', + ] + ]; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + $this->filePermissionsMock = $this->createMock(FilePermissions::class); + $this->configWriterMock = $this->createMock(Writer::class); + $this->configReaderMock = $this->createMock(Reader::class); + $this->configMock = $this->createMock(DeploymentConfig::class); + + $this->moduleListMock = $this->getMockForAbstractClass(ModuleListInterface::class); + $this->moduleListMock->expects($this->any()) + ->method('getOne') + ->willReturn( ['setup_version' => '2.0.0'] ); - $this->moduleList->expects($this->any())->method('getNames')->willReturn( + $this->moduleListMock->expects($this->any()) + ->method('getNames') + ->willReturn( ['Foo_One', 'Bar_Two'] ); - $this->moduleLoader = $this->createMock(\Magento\Framework\Module\ModuleList\Loader::class); - $this->directoryList = - $this->createMock(\Magento\Framework\App\Filesystem\DirectoryList::class); - $this->adminFactory = $this->createMock(\Magento\Setup\Model\AdminAccountFactory::class); - $this->logger = $this->getMockForAbstractClass(\Magento\Framework\Setup\LoggerInterface::class); - $this->random = $this->createMock(\Magento\Framework\Math\Random::class); - $this->connection = $this->getMockForAbstractClass(\Magento\Framework\DB\Adapter\AdapterInterface::class); - $this->maintenanceMode = $this->createMock(\Magento\Framework\App\MaintenanceMode::class); - $this->filesystem = $this->createMock(\Magento\Framework\Filesystem::class); - $this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class); - $this->contextMock = - $this->createMock(\Magento\Framework\Model\ResourceModel\Db\Context::class); - $this->configModel = $this->createMock(\Magento\Setup\Model\ConfigModel::class); - $this->cleanupFiles = $this->createMock(\Magento\Framework\App\State\CleanupFiles::class); - $this->dbValidator = $this->createMock(\Magento\Setup\Validator\DbValidator::class); - $this->setupFactory = $this->createMock(\Magento\Setup\Module\SetupFactory::class); - $this->dataSetupFactory = $this->createMock(\Magento\Setup\Module\DataSetupFactory::class); - $this->sampleDataState = $this->createMock(\Magento\Framework\Setup\SampleData\State::class); - $this->componentRegistrar = - $this->createMock(\Magento\Framework\Component\ComponentRegistrar::class); - $this->phpReadinessCheck = $this->createMock(\Magento\Setup\Model\PhpReadinessCheck::class); - $this->declarationInstallerMock = $this->createMock(DeclarationInstaller::class); - $this->schemaListenerMock = $this->createMock(SchemaListener::class); - $this->patchApplierFactoryMock = $this->createMock(PatchApplierFactory::class); - $this->patchApplierMock = $this->createMock(PatchApplier::class); - $this->patchApplierFactoryMock->expects($this->any())->method('create')->willReturn( + + $this->moduleLoaderMock = $this->createMock(Loader::class); + $this->adminFactoryMock = $this->createMock(AdminAccountFactory::class); + $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); + $this->randomMock = $this->createMock(Random::class); + $this->connectionMock = $this->getMockForAbstractClass(AdapterInterface::class); + $this->maintenanceModeMock = $this->createMock(MaintenanceMode::class); + $this->filesystemMock = $this->createMock(Filesystem::class); + $this->contextMock = $this->createMock(Context::class); + $this->configModelMock = $this->createMock(ConfigModel::class); + $this->cleanupFilesMock = $this->createMock(CleanupFiles::class); + $this->dbValidatorMock = $this->createMock(DbValidator::class); + $this->setupFactoryMock = $this->createMock(SetupFactory::class); + $this->dataSetupFactoryMock = $this->createMock(DataSetupFactory::class); + $this->sampleDataStateMock = $this->createMock(State::class); + $this->componentRegistrarMock = $this->createMock(ComponentRegistrar::class); + $this->phpReadinessCheckMock = $this->createMock(PhpReadinessCheck::class); + $this->declarationInstallerMock = $this->createMock(DeclarationInstaller::class); + $this->schemaListenerMock = $this->createMock(SchemaListener::class); + $this->patchApplierFactoryMock = $this->createMock(PatchApplierFactory::class); + $this->patchApplierMock = $this->createMock(PatchApplier::class); + + $this->patchApplierFactoryMock->expects($this->any()) + ->method('create') + ->willReturn( $this->patchApplierMock ); - $this->object = $this->createObject(); - } - /** - * Instantiates the object with mocks - * @param \PHPUnit_Framework_MockObject_MockObject|bool $connectionFactory - * @param \PHPUnit_Framework_MockObject_MockObject|bool $objectManagerProvider - * @return Installer - */ - private function createObject($connectionFactory = false, $objectManagerProvider = false) - { - if (!$connectionFactory) { - $connectionFactory = $this->createMock(\Magento\Setup\Module\ConnectionFactory::class); - $connectionFactory->expects($this->any())->method('create')->willReturn($this->connection); - } - if (!$objectManagerProvider) { - $objectManagerProvider = - $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class); - $objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager); - } - - return new Installer( - $this->filePermissions, - $this->configWriter, - $this->configReader, - $this->config, - $this->moduleList, - $this->moduleLoader, - $this->adminFactory, - $this->logger, - $connectionFactory, - $this->maintenanceMode, - $this->filesystem, - $objectManagerProvider, - $this->contextMock, - $this->configModel, - $this->cleanupFiles, - $this->dbValidator, - $this->setupFactory, - $this->dataSetupFactory, - $this->sampleDataState, - $this->componentRegistrar, - $this->phpReadinessCheck, - $this->declarationInstallerMock - ); + $this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class); + $this->object = $this->createObject(); + } + + /** + * Instantiates the object with mocks + * + * @param ConnectionFactory|MockObject|bool $connectionFactory + * @param ObjectManagerProvider|MockObject|bool $objectManagerProvider + * @return Installer + */ + private function createObject($connectionFactoryMock = false, $objectManagerProviderMock = false) + { + if (!$connectionFactoryMock) { + $connectionFactoryMock = $this->createMock(ConnectionFactory::class); + $connectionFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->connectionMock); } - /** - * @param array $request - * @param array $logMessages - * @dataProvider installDataProvider - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function testInstall(array $request, array $logMessages) - { - $this->config->expects($this->atLeastOnce()) + if (!$objectManagerProviderMock) { + $objectManagerProviderMock = $this->createMock(ObjectManagerProvider::class); + $objectManagerProviderMock->expects($this->any()) ->method('get') - ->willReturnMap( - [ - [ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true], - [ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true], - ['modules/Magento_User', null, '1'] - ] - ); - $allModules = ['Foo_One' => [], 'Bar_Two' => []]; - - $this->declarationInstallerMock->expects($this->once())->method('installSchema'); - $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules); - $setup = $this->createMock(\Magento\Setup\Module\Setup::class); - $table = $this->createMock(\Magento\Framework\DB\Ddl\Table::class); - $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class) - ->setMethods(['getSchemaListener', 'newTable']) - ->getMockForAbstractClass(); - $connection->expects($this->any())->method('getSchemaListener')->willReturn($this->schemaListenerMock); - $setup->expects($this->any())->method('getConnection')->willReturn($connection); - $table->expects($this->any())->method('addColumn')->willReturn($table); - $table->expects($this->any())->method('setComment')->willReturn($table); - $table->expects($this->any())->method('addIndex')->willReturn($table); - $connection->expects($this->any())->method('newTable')->willReturn($table); - $resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class); - $this->contextMock->expects($this->any())->method('getResources')->willReturn($resource); - $resource->expects($this->any())->method('getConnection')->will($this->returnValue($connection)); - $dataSetup = $this->createMock(\Magento\Setup\Module\DataSetup::class); - $dataSetup->expects($this->any())->method('getConnection')->willReturn($connection); - $cacheManager = $this->createMock(\Magento\Framework\App\Cache\Manager::class); - $cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->exactly(3))->method('clean'); - $cacheManager->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]); - $appState = $this->getMockBuilder(\Magento\Framework\App\State::class) - ->disableOriginalConstructor() - ->disableArgumentCloning() - ->getMock(); - $appState->expects($this->once()) - ->method('setAreaCode') - ->with(\Magento\Framework\App\Area::AREA_GLOBAL); - $registry = $this->createMock(\Magento\Framework\Registry::class); - $this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup); - $this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup); - $this->objectManager->expects($this->any()) - ->method('create') - ->will($this->returnValueMap([ - [\Magento\Framework\App\Cache\Manager::class, [], $cacheManager], - [\Magento\Framework\App\State::class, [], $appState], - [ - PatchApplierFactory::class, - ['objectManager' => $this->objectManager], - $this->patchApplierFactoryMock - ], - ])); - $this->patchApplierMock->expects($this->exactly(2))->method('applySchemaPatch')->willReturnMap( + ->willReturn($this->objectManager); + } + + return (new ObjectManager($this))->getObject( + Installer::class, + [ + 'filePermissions' => $this->filePermissionsMock, + 'deploymentConfigWriter' => $this->configWriterMock, + 'deploymentConfigReader' => $this->configReaderMock, + 'moduleList' => $this->moduleListMock, + 'moduleLoader' => $this->moduleLoaderMock, + 'adminAccountFactory' => $this->adminFactoryMock, + 'log' => $this->loggerMock, + 'connectionFactory' => $connectionFactoryMock, + 'maintenanceMode' => $this->maintenanceModeMock, + 'filesystem' => $this->filesystemMock, + [], + 'deploymentConfig' => $this->configMock, + 'objectManagerProvider' => $objectManagerProviderMock, + 'context' => $this->contextMock, + 'setupConfigModel' => $this->configModelMock, + 'cleanupFiles' => $this->cleanupFilesMock, + 'dbValidator' => $this->dbValidatorMock, + 'setupFactory' => $this->setupFactoryMock, + 'dataSetupFactory' => $this->dataSetupFactoryMock, + 'sampleDataState' => $this->sampleDataStateMock, + 'componentRegistrar' => $this->componentRegistrarMock, + 'phpReadinessCheck' => $this->phpReadinessCheckMock + ] + ); + } + + /** + * Test install() + * + * @param array $request + * @param array $logMessages + * @dataProvider installDataProvider + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testInstall(array $request, array $logMessages): void + { + $this->configMock->expects($this->atLeastOnce()) + ->method('get') + ->willReturnMap( [ - ['Bar_Two'], - ['Foo_One'], + [ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true], + [ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true], + ['modules/Magento_User', null, '1'] ] ); - $this->patchApplierMock->expects($this->exactly(2))->method('applyDataPatch')->willReturnMap( + $allModules = ['Foo_One' => [], 'Bar_Two' => []]; + + $this->declarationInstallerMock->expects($this->once())->method('installSchema'); + $this->moduleLoaderMock->expects($this->any())->method('load')->willReturn($allModules); + + $connectionMock = $this->getMockBuilder(AdapterInterface::class) + ->setMethods(['getSchemaListener', 'newTable']) + ->getMockForAbstractClass(); + $connectionMock->expects($this->any())->method('getSchemaListener')->willReturn($this->schemaListenerMock); + + $setupMock = $this->createMock(Setup::class); + $setupMock->expects($this->any())->method('getConnection')->willReturn($connectionMock); + + $tableMock = $this->createMock(Table::class); + $tableMock->expects($this->any())->method('addColumn')->willReturn($tableMock); + $tableMock->expects($this->any())->method('setComment')->willReturn($tableMock); + $tableMock->expects($this->any())->method('addIndex')->willReturn($tableMock); + + $connectionMock->expects($this->any())->method('newTable')->willReturn($tableMock); + + $resourceMock = $this->createMock(ResourceConnection::class); + $this->contextMock->expects($this->any())->method('getResources')->willReturn($resourceMock); + $resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock)); + + $dataSetupMock = $this->createMock(DataSetup::class); + $dataSetupMock->expects($this->any())->method('getConnection')->willReturn($connectionMock); + + $cacheManagerMock = $this->createMock(Manager::class); + $cacheManagerMock->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->exactly(3))->method('setEnabled') + // ->with(['foo', 'bar'], false) + ->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->exactly(3))->method('clean'); + $cacheManagerMock->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]); + + $appStateMock = $this->getMockBuilder(MFAState::class) + ->disableOriginalConstructor() + ->disableArgumentCloning() + ->getMock(); + $appStateMock->expects($this->once()) + ->method('setAreaCode') + ->with(Area::AREA_GLOBAL); + + $registryMock = $this->createMock(Registry::class); + + $this->setupFactoryMock->expects($this->atLeastOnce())->method('create')->with($resourceMock)->willReturn($setupMock); + $this->dataSetupFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($dataSetupMock); + $this->objectManager->expects($this->any()) + ->method('create') + ->will($this->returnValueMap([ + [Manager::class, [], $cacheManagerMock], + [MFAState::class, [], $appStateMock], + [ + PatchApplierFactory::class, + ['objectManager' => $this->objectManager], + $this->patchApplierFactoryMock + ], + ])); + + $this->patchApplierMock->expects($this->exactly(2))->method('applySchemaPatch') + ->willReturnMap( [ - ['Bar_Two'], - ['Foo_One'], + ['Bar_Two'], ['Foo_One'] ] ); - $this->objectManager->expects($this->any()) - ->method('get') - ->will($this->returnValueMap([ - [\Magento\Framework\App\State::class, $appState], - [\Magento\Framework\App\Cache\Manager::class, $cacheManager], - [\Magento\Setup\Model\DeclarationInstaller::class, $this->declarationInstallerMock], - [\Magento\Framework\Registry::class, $registry] - ])); - $this->adminFactory->expects($this->any())->method('create')->willReturn( - $this->createMock(\Magento\Setup\Model\AdminAccount::class) - ); - $this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true); - $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn( - ['responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] + $this->patchApplierMock->expects($this->exactly(2))->method('applyDataPatch')->willReturnMap( + [ + ['Bar_Two'], ['Foo_One'] + ] + ); + $this->objectManager->expects($this->any()) + ->method('get') + ->will($this->returnValueMap([ + [MFAState::class, $appStateMock], + [Manager::class, $cacheManagerMock], + [DeclarationInstaller::class, $this->declarationInstallerMock], + [Registry::class, $registryMock] + ])); + $this->adminFactoryMock->expects($this->any())->method('create')->willReturn( + $this->createMock(AdminAccount::class) + ); + $this->sampleDataStateMock->expects($this->once())->method('hasError')->willReturn(true); + $this->phpReadinessCheckMock->expects($this->once())->method('checkPhpExtensions') + ->willReturn( + ['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] ); - $this->filePermissions->expects($this->any()) - ->method('getMissingWritablePathsForInstallation') - ->willReturn([]); - $this->filePermissions->expects($this->once()) - ->method('getMissingWritableDirectoriesForDbUpgrade') - ->willReturn([]); - call_user_func_array( - [ - $this->logger->expects($this->exactly(count($logMessages)))->method('log'), - 'withConsecutive' - ], - $logMessages + $this->filePermissionsMock->expects($this->any()) + ->method('getMissingWritablePathsForInstallation') + ->willReturn([]); + $this->filePermissionsMock->expects($this->once()) + ->method('getMissingWritableDirectoriesForDbUpgrade') + ->willReturn([]); + + call_user_func_array( + [ + $this->loggerMock->expects($this->exactly(count($logMessages)))->method('log'), + 'withConsecutive' + ], + $logMessages + ); + + $this->loggerMock->expects($this->exactly(2)) + ->method('logSuccess') + ->withConsecutive( + ['Magento installation complete.'], + ['Magento Admin URI: /'] ); - $this->logger->expects($this->exactly(2)) - ->method('logSuccess') - ->withConsecutive( - ['Magento installation complete.'], - ['Magento Admin URI: /'] - ); - - $this->object->install($request); - } + $this->object->install($request); + } - /** - * @return array - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function installDataProvider() - { - return [ - [ - 'request' => [ - ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1', - ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento', - ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento', - ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', - ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend', - ], - '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 user configuration...'], - ['Enabling caches:'], - ['Current status:'], - [print_r(['foo' => 1, 'bar' => 1], true)], - ['Installing data...'], - ['Data install/update:'], - ['Disabling caches:'], - ['Current status:'], - [print_r([], true)], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Data post-updates:'], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Enabling caches:'], - ['Current status:'], - [print_r([], true)], - ['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'] - ], + /** + * Install DataProvider + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function installDataProvider(): array + { + return [ + [ + 'request' => [ + ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1', + ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento', + ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento', + ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', + ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend', ], - [ - 'request' => [ - ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1', - ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento', - ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento', - ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', - ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend', - AdminAccount::KEY_USER => 'admin', - AdminAccount::KEY_PASSWORD => '123', - AdminAccount::KEY_EMAIL => 'admin@example.com', - AdminAccount::KEY_FIRST_NAME => 'John', - 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 user configuration...'], - ['Enabling caches:'], - ['Current status:'], - [print_r(['foo' => 1, 'bar' => 1], true)], - ['Installing data...'], - ['Data install/update:'], - ['Disabling caches:'], - ['Current status:'], - [print_r([], true)], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Data post-updates:'], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Enabling caches:'], - ['Current status:'], - [print_r([], true)], - ['Installing admin user...'], - ['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'] - ], + '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 user configuration...'], + ['Enabling caches:'], + ['Current status:'], + ['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...'], + ['Sample Data is installed with errors. See log file for details'] ], - ]; - } + ], + [ + 'request' => [ + ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1', + ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento', + ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento', + ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', + ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend', + AdminAccount::KEY_USER => 'admin', + AdminAccount::KEY_PASSWORD => '123', + AdminAccount::KEY_EMAIL => 'admin@example.com', + AdminAccount::KEY_FIRST_NAME => 'John', + 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 user configuration...'], + ['Enabling caches:'], + ['Current status:'], + ['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...'], + ['Sample Data is installed with errors. See log file for details'] + ], + ], + ]; + } - public function testCheckInstallationFilePermissions() - { - $this->filePermissions - ->expects($this->once()) - ->method('getMissingWritablePathsForInstallation') - ->willReturn([]); - $this->object->checkInstallationFilePermissions(); - } + /** + * Test Check installation file permission + */ + public function testCheckInstallationFilePermissions(): void + { + $this->filePermissionsMock->expects($this->once()) + ->method('getMissingWritablePathsForInstallation') + ->willReturn([]); + $this->object->checkInstallationFilePermissions(); + } - /** - * @expectedException \Exception - * @expectedExceptionMessage Missing write permissions to the following paths: - */ - public function testCheckInstallationFilePermissionsError() - { - $this->filePermissions - ->expects($this->once()) - ->method('getMissingWritablePathsForInstallation') - ->willReturn(['foo', 'bar']); - $this->object->checkInstallationFilePermissions(); - } + /** + * Test Check installation file permission error + * + * @expectedException \Exception + * @expectedExceptionMessage Missing write permissions to the following paths: + */ + public function testCheckInstallationFilePermissionsError(): void + { + $this->filePermissionsMock->expects($this->once()) + ->method('getMissingWritablePathsForInstallation') + ->willReturn(['foo', 'bar']); + $this->object->checkInstallationFilePermissions(); + } - public function testCheckExtensions() - { - $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn( - ['responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] - ); - $this->object->checkExtensions(); - } + /** + * Test check extensions + */ + public function testCheckExtensions(): void + { + $this->phpReadinessCheckMock->expects($this->once())->method('checkPhpExtensions')->willReturn( + ['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] + ); + $this->object->checkExtensions(); + } - /** - * @expectedException \Exception - * @expectedExceptionMessage Missing following extensions: 'foo' - */ - public function testCheckExtensionsError() - { - $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn( + /** + * Test check if extensions has error + * + * @expectedException \Exception + * @expectedExceptionMessage Missing following extensions: 'foo' + */ + public function testCheckExtensionsError(): void + { + $this->phpReadinessCheckMock->expects($this->once())->method('checkPhpExtensions')->willReturn( + [ + 'responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, + 'data' => ['required' => ['foo', 'bar'], 'missing' => ['foo']] + ] + ); + $this->object->checkExtensions(); + } + + /** + * Test check application file permissions + */ + public function testCheckApplicationFilePermissions(): void + { + $this->filePermissionsMock + ->expects($this->once()) + ->method('getUnnecessaryWritableDirectoriesForApplication') + ->willReturn(['foo', 'bar']); + $expectedMessage = "For security, remove write permissions from these directories: 'foo' 'bar'"; + $this->loggerMock->expects($this->once())->method('log')->with($expectedMessage); + $this->object->checkApplicationFilePermissions(); + $this->assertSame(['message' => [$expectedMessage]], $this->object->getInstallInfo()); + } + + /** + * Test update modules sequence + */ + public function testUpdateModulesSequence(): void + { + $this->cleanupFilesMock->expects($this->once())->method('clearCodeGeneratedFiles')->will( + $this->returnValue( [ - 'responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_ERROR, - 'data' => ['required' => ['foo', 'bar'], 'missing' => ['foo']] + "The directory '/generation' doesn't exist - skipping cleanup" ] - ); - $this->object->checkExtensions(); - } + ) + ); + $installer = $this->prepareForUpdateModulesTests(); + + $this->loggerMock->expects($this->at(0))->method('log')->with('Cache cleared successfully'); + $this->loggerMock->expects($this->at(1))->method('log')->with('File system cleanup:'); + $this->loggerMock->expects($this->at(2))->method('log') + ->with('The directory \'/generation\' doesn\'t exist - skipping cleanup'); + $this->loggerMock->expects($this->at(3))->method('log')->with('Updating modules:'); + $installer->updateModulesSequence(false); + } - public function testCheckApplicationFilePermissions() - { - $this->filePermissions - ->expects($this->once()) - ->method('getUnnecessaryWritableDirectoriesForApplication') - ->willReturn(['foo', 'bar']); - $expectedMessage = "For security, remove write permissions from these directories: 'foo' 'bar'"; - $this->logger->expects($this->once())->method('log')->with($expectedMessage); - $this->object->checkApplicationFilePermissions(); - $this->assertSame(['message' => [$expectedMessage]], $this->object->getInstallInfo()); - } + /** + * Test update modules sequence with generated + */ + public function testUpdateModulesSequenceKeepGenerated(): void + { + $this->cleanupFilesMock->expects($this->never())->method('clearCodeGeneratedClasses'); - public function testUpdateModulesSequence() - { - $this->cleanupFiles->expects($this->once())->method('clearCodeGeneratedFiles')->will( - $this->returnValue( + $installer = $this->prepareForUpdateModulesTests(); + + $this->loggerMock->expects($this->at(0))->method('log')->with('Cache cleared successfully'); + $this->loggerMock->expects($this->at(1))->method('log')->with('Updating modules:'); + $installer->updateModulesSequence(true); + } + + /** + * Test Uninstall method + */ + public function testUninstall(): void + { + $this->configMock->expects($this->once()) + ->method('get') + ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) + ->willReturn([]); + $this->configReaderMock->expects($this->once())->method('getFiles')->willReturn([ + 'ConfigOne.php', + 'ConfigTwo.php' + ]); + + $configDirMock = $this->getMockForAbstractClass(WriteInterface::class); + $configDirMock->expects($this->exactly(2)) + ->method('getAbsolutePath') + ->will( + $this->returnValueMap( [ - "The directory '/generation' doesn't exist - skipping cleanup", + ['ConfigOne.php', '/config/ConfigOne.php'], + ['ConfigTwo.php', '/config/ConfigTwo.php'] ] ) ); - $installer = $this->prepareForUpdateModulesTests(); - - $this->logger->expects($this->at(0))->method('log')->with('Cache cleared successfully'); - $this->logger->expects($this->at(1))->method('log')->with('File system cleanup:'); - $this->logger->expects($this->at(2))->method('log') - ->with('The directory \'/generation\' doesn\'t exist - skipping cleanup'); - $this->logger->expects($this->at(3))->method('log')->with('Updating modules:'); - $installer->updateModulesSequence(false); - } - public function testUpdateModulesSequenceKeepGenerated() - { - $this->cleanupFiles->expects($this->never())->method('clearCodeGeneratedClasses'); + $this->filesystemMock->expects($this->any()) + ->method('getDirectoryWrite') + ->will($this->returnValueMap([ + [DirectoryList::CONFIG, DriverPool::FILE, $configDirMock], + ])); + $this->loggerMock->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); + $this->loggerMock->expects($this->at(2)) + ->method('log') + ->with('No database connection defined - skipping database cleanup'); + + $cacheManagerMock = $this->createMock(Manager::class); + $cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->once())->method('clean'); + + $this->objectManager->expects($this->any()) + ->method('get') + ->with(Manager::class) + ->willReturn($cacheManagerMock); + $this->loggerMock->expects($this->at(1))->method('log')->with('Cache cleared successfully'); + $this->loggerMock->expects($this->at(3))->method('log')->with('File system cleanup:'); + $this->loggerMock + ->expects($this->at(4)) + ->method('log') + ->with("The directory '/var' doesn't exist - skipping cleanup"); + $this->loggerMock + ->expects($this->at(5)) + ->method('log') + ->with("The directory '/static' doesn't exist - skipping cleanup"); + $this->loggerMock + ->expects($this->at(6)) + ->method('log') + ->with("The file '/config/ConfigOne.php' doesn't exist - skipping cleanup"); + $this->loggerMock + ->expects($this->at(7)) + ->method('log') + ->with("The file '/config/ConfigTwo.php' doesn't exist - skipping cleanup"); + $this->loggerMock->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.'); + $this->cleanupFilesMock->expects($this->once())->method('clearAllFiles')->will( + $this->returnValue( + [ + "The directory '/var' doesn't exist - skipping cleanup", + "The directory '/static' doesn't exist - skipping cleanup" + ] + ) + ); - $installer = $this->prepareForUpdateModulesTests(); + $this->object->uninstall(); + } - $this->logger->expects($this->at(0))->method('log')->with('Cache cleared successfully'); - $this->logger->expects($this->at(1))->method('log')->with('Updating modules:'); - $installer->updateModulesSequence(true); - } + /** + * Test cleanupDb + */ + public function testCleanupDb(): void + { + $this->configMock->expects($this->once()) + ->method('get') + ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) + ->willReturn(self::$dbConfig); + $this->connectionMock->expects($this->at(0))->method('quoteIdentifier') + ->with('magento') + ->willReturn('`magento`'); + $this->connectionMock->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); + $this->connectionMock->expects($this->at(2))->method('query')->with('CREATE DATABASE IF NOT EXISTS `magento`'); + $this->loggerMock->expects($this->once())->method('log')->with('Cleaning up database `magento`'); + $this->object->cleanupDb(); + } - public function testUninstall() - { - $this->config->expects($this->once()) - ->method('get') - ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) - ->willReturn([]); - $this->configReader->expects($this->once())->method('getFiles')->willReturn([ - 'ConfigOne.php', - 'ConfigTwo.php' - ]); - $configDir = $this->getMockForAbstractClass( - \Magento\Framework\Filesystem\Directory\WriteInterface::class - ); - $configDir - ->expects($this->exactly(2)) - ->method('getAbsolutePath') - ->will( - $this->returnValueMap( - [ - ['ConfigOne.php', '/config/ConfigOne.php'], - ['ConfigTwo.php', '/config/ConfigTwo.php'] - ] - ) - ); - $this->filesystem - ->expects($this->any()) - ->method('getDirectoryWrite') - ->will($this->returnValueMap([ - [DirectoryList::CONFIG, DriverPool::FILE, $configDir], - ])); - $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); - $this->logger - ->expects($this->at(2)) - ->method('log') - ->with('No database connection defined - skipping database cleanup'); - $cacheManager = $this->createMock(\Magento\Framework\App\Cache\Manager::class); - $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->once())->method('clean'); - $this->objectManager->expects($this->any()) - ->method('get') - ->with(\Magento\Framework\App\Cache\Manager::class) - ->willReturn($cacheManager); - $this->logger->expects($this->at(1))->method('log')->with('Cache cleared successfully'); - $this->logger->expects($this->at(3))->method('log')->with('File system cleanup:'); - $this->logger - ->expects($this->at(4)) - ->method('log') - ->with("The directory '/var' doesn't exist - skipping cleanup"); - $this->logger - ->expects($this->at(5)) - ->method('log') - ->with("The directory '/static' doesn't exist - skipping cleanup"); - $this->logger - ->expects($this->at(6)) - ->method('log') - ->with("The file '/config/ConfigOne.php' doesn't exist - skipping cleanup"); - $this->logger - ->expects($this->at(7)) - ->method('log') - ->with("The file '/config/ConfigTwo.php' doesn't exist - skipping cleanup"); - $this->logger->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.'); - $this->cleanupFiles->expects($this->once())->method('clearAllFiles')->will( - $this->returnValue( - [ - "The directory '/var' doesn't exist - skipping cleanup", - "The directory '/static' doesn't exist - skipping cleanup" - ] - ) - ); + /** + * Prepare mocks for update modules tests and returns the installer to use + * @return Installer + */ + private function prepareForUpdateModulesTests() + { + $allModules = [ + 'Foo_One' => [], + 'Bar_Two' => [], + 'New_Module' => [], + ]; - $this->object->uninstall(); - } + $cacheManagerMock = $this->createMock(Manager::class); + $cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->once())->method('clean'); - public function testCleanupDb() - { - $this->config->expects($this->once()) - ->method('get') - ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) - ->willReturn(self::$dbConfig); - $this->connection->expects($this->at(0))->method('quoteIdentifier')->with('magento')->willReturn( - '`magento`' - ); - $this->connection->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); - $this->connection->expects($this->at(2))->method('query')->with('CREATE DATABASE IF NOT EXISTS `magento`'); - $this->logger->expects($this->once())->method('log')->with('Cleaning up database `magento`'); - $this->object->cleanupDb(); - } + $this->objectManager->expects($this->any())->method('get') + ->will($this->returnValueMap([ + [Manager::class, $cacheManagerMock] + ])); - /** - * Prepare mocks for update modules tests and returns the installer to use - * @return Installer - */ - private function prepareForUpdateModulesTests() - { - $allModules = [ - 'Foo_One' => [], - 'Bar_Two' => [], - 'New_Module' => [], - ]; - - $cacheManager = $this->createMock(\Magento\Framework\App\Cache\Manager::class); - $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->once())->method('clean'); - $this->objectManager->expects($this->any()) - ->method('get') - ->will($this->returnValueMap([ - [\Magento\Framework\App\Cache\Manager::class, $cacheManager] - ])); - $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules); - - $expectedModules = [ - ConfigFilePool::APP_CONFIG => [ - 'modules' => [ - 'Bar_Two' => 0, - 'Foo_One' => 1, - 'New_Module' => 1 - ] - ] - ]; + $this->moduleLoaderMock->expects($this->once())->method('load') + ->willReturn($allModules); - $this->config->expects($this->atLeastOnce()) - ->method('get') - ->with(ConfigOptionsListConstants::KEY_MODULES) - ->willReturn(true); + $expectedModules = [ + ConfigFilePool::APP_CONFIG => [ + 'modules' => [ + 'Bar_Two' => 0, + 'Foo_One' => 1, + 'New_Module' => 1 + ] + ] + ]; - $newObject = $this->createObject(false, false); - $this->configReader->expects($this->once())->method('load') - ->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0]]); - $this->configWriter->expects($this->once())->method('saveConfig')->with($expectedModules); + $this->configMock->expects($this->atLeastOnce())->method('get') + ->with(ConfigOptionsListConstants::KEY_MODULES) + ->willReturn(true); - return $newObject; - } - } -} + $this->configReaderMock->expects($this->once())->method('load') + ->willReturn( + [ + 'modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0] + ] + ); -namespace Magento\Setup\Model { + $this->configWriterMock->expects($this->once()) + ->method('saveConfig') + ->with($expectedModules); - /** - * Mocking autoload function - * - * @returns array - */ - function spl_autoload_functions() - { - return ['mock_function_one', 'mock_function_two']; + return $this->createObject(); } } From 981df7bdc533a1209253976b2677b8af03f2df08 Mon Sep 17 00:00:00 2001 From: Sathish Date: Sat, 4 Apr 2020 17:41:02 +0530 Subject: [PATCH 06/22] Fixed static test --- .../Magento/Setup/Test/Unit/Model/InstallerTest.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 1f9afb04c07dd..40a47f46765a2 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -366,7 +366,6 @@ public function testInstall(array $request, array $logMessages): void $cacheManagerMock = $this->createMock(Manager::class); $cacheManagerMock->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']); $cacheManagerMock->expects($this->exactly(3))->method('setEnabled') - // ->with(['foo', 'bar'], false) ->willReturn(['foo', 'bar']); $cacheManagerMock->expects($this->exactly(3))->method('clean'); $cacheManagerMock->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]); @@ -381,8 +380,15 @@ public function testInstall(array $request, array $logMessages): void $registryMock = $this->createMock(Registry::class); - $this->setupFactoryMock->expects($this->atLeastOnce())->method('create')->with($resourceMock)->willReturn($setupMock); - $this->dataSetupFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($dataSetupMock); + $this->setupFactoryMock->expects($this->atLeastOnce()) + ->method('create') + ->with($resourceMock) + ->willReturn($setupMock); + + $this->dataSetupFactoryMock->expects($this->atLeastOnce()) + ->method('create') + ->willReturn($dataSetupMock); + $this->objectManager->expects($this->any()) ->method('create') ->will($this->returnValueMap([ From 5a4e93f80eee1d37c63243d4e99d947aa8465a96 Mon Sep 17 00:00:00 2001 From: Quang Do Date: Mon, 6 Apr 2020 16:13:48 +0930 Subject: [PATCH 07/22] Added unit test to assert cache IDs for different ACL roles must not be equal --- .../Product/Form/Modifier/CategoriesTest.php | 91 ++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php index bceafee0f82a4..02fc16c55be07 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php @@ -14,6 +14,9 @@ use Magento\Framework\UrlInterface; use Magento\Store\Model\Store; use Magento\Framework\AuthorizationInterface; +use Magento\Backend\Model\Auth\Session; +use Magento\Authorization\Model\Role; +use Magento\User\Model\User; /** * Class CategoriesTest @@ -52,6 +55,11 @@ class CategoriesTest extends AbstractModifierTest */ private $authorizationMock; + /** + * @var \Magento\Backend\Model\Auth\Session|\PHPUnit_Framework_MockObject_MockObject + */ + private $sessionMock; + protected function setUp() { parent::setUp(); @@ -73,6 +81,10 @@ protected function setUp() $this->authorizationMock = $this->getMockBuilder(AuthorizationInterface::class) ->disableOriginalConstructor() ->getMock(); + $this->sessionMock = $this->getMockBuilder(Session::class) + ->setMethods(['getUser']) + ->disableOriginalConstructor() + ->getMock(); $this->categoryCollectionFactoryMock->expects($this->any()) ->method('create') @@ -89,6 +101,26 @@ protected function setUp() $this->categoryCollectionMock->expects($this->any()) ->method('getIterator') ->willReturn(new \ArrayIterator([])); + + $roleAdmin = $this->getMockBuilder(Role::class) + ->setMethods(['getId']) + ->disableOriginalConstructor() + ->getMock(); + $roleAdmin->expects($this->any()) + ->method('getId') + ->willReturn(0); + + $userAdmin = $this->getMockBuilder(User::class) + ->setMethods(['getRole']) + ->disableOriginalConstructor() + ->getMock(); + $userAdmin->expects($this->any()) + ->method('getRole') + ->willReturn($roleAdmin); + + $this->sessionMock->expects($this->any()) + ->method('getUser') + ->willReturn($userAdmin); } /** @@ -102,11 +134,28 @@ protected function createModel() 'locator' => $this->locatorMock, 'categoryCollectionFactory' => $this->categoryCollectionFactoryMock, 'arrayManager' => $this->arrayManagerMock, - 'authorization' => $this->authorizationMock + 'authorization' => $this->authorizationMock, + 'session' => $this->sessionMock ] ); } + /** + * @param object $object + * @param string $method + * @param array $args + * @return mixed + * @throws \ReflectionException + */ + private function invokeMethod($object, $method, $args = []) + { + $class = new \ReflectionClass(Categories::class); + $method = $class->getMethod($method); + $method->setAccessible(true); + + return $method->invokeArgs($object, $args); + } + public function testModifyData() { $this->assertSame([], $this->getModel()->modifyData([])); @@ -177,4 +226,44 @@ public function modifyMetaLockedDataProvider() { return [[true], [false]]; } + + /** + * Asserts that a user with an ACL role ID of 0 and a user with an ACL role ID of 1 do not have the same cache IDs + * Assumes a store ID of 0 + * + * @throws \ReflectionException + */ + public function testAclCacheIds() + { + $categoriesAdmin = $this->createModel(); + $cacheIdAdmin = $this->invokeMethod($categoriesAdmin, 'getCategoriesTreeCacheId', [0]); + + $roleAclUser = $this->getMockBuilder(Role::class) + ->disableOriginalConstructor() + ->getMock(); + $roleAclUser->expects($this->any()) + ->method('getId') + ->willReturn(1); + + $userAclUser = $this->getMockBuilder(User::class) + ->disableOriginalConstructor() + ->getMock(); + $userAclUser->expects($this->any()) + ->method('getRole') + ->will($this->returnValue($roleAclUser)); + + $this->sessionMock = $this->getMockBuilder(Session::class) + ->setMethods(['getUser']) + ->disableOriginalConstructor() + ->getMock(); + + $this->sessionMock->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($userAclUser)); + + $categoriesAclUser = $this->createModel(); + $cacheIdAclUser = $this->invokeMethod($categoriesAclUser, 'getCategoriesTreeCacheId', [0]); + + $this->assertNotEquals($cacheIdAdmin, $cacheIdAclUser); + } } From e5b64f533b984063d9e735cf6f2b485fca6b721b Mon Sep 17 00:00:00 2001 From: Quang Do Date: Tue, 7 Apr 2020 08:27:27 +0930 Subject: [PATCH 08/22] Update class description to address static test --- .../Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php index 02fc16c55be07..d1df9ae0a5b99 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php @@ -19,7 +19,7 @@ use Magento\User\Model\User; /** - * Class CategoriesTest + * Tests for \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ From 06d3e3aa19f2a51332996416a38725d03d21be05 Mon Sep 17 00:00:00 2001 From: Quang Do Date: Tue, 14 Apr 2020 08:36:18 +0930 Subject: [PATCH 09/22] Update deprecated PHPUnit_Framework_MockObject_MockObject declarations --- .../Product/Form/Modifier/CategoriesTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php index d1df9ae0a5b99..8bd5cfce49638 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php @@ -26,37 +26,37 @@ class CategoriesTest extends AbstractModifierTest { /** - * @var CategoryCollectionFactory|\PHPUnit_Framework_MockObject_MockObject + * @var CategoryCollectionFactory|\PHPUnit\Framework\MockObject\MockObject */ protected $categoryCollectionFactoryMock; /** - * @var DbHelper|\PHPUnit_Framework_MockObject_MockObject + * @var DbHelper|\PHPUnit\Framework\MockObject\MockObject */ protected $dbHelperMock; /** - * @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject + * @var UrlInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $urlBuilderMock; /** - * @var Store|\PHPUnit_Framework_MockObject_MockObject + * @var Store|\PHPUnit\Framework\MockObject\MockObject */ protected $storeMock; /** - * @var CategoryCollection|\PHPUnit_Framework_MockObject_MockObject + * @var CategoryCollection|\PHPUnit\Framework\MockObject\MockObject */ protected $categoryCollectionMock; /** - * @var AuthorizationInterface|\PHPUnit_Framework_MockObject_MockObject + * @var AuthorizationInterface|\PHPUnit\Framework\MockObject\MockObject */ private $authorizationMock; /** - * @var \Magento\Backend\Model\Auth\Session|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Backend\Model\Auth\Session|\PHPUnit\Framework\MockObject\MockObject */ private $sessionMock; From d938e7bcab3f4620d5d0facb23a05ab81304e988 Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Fri, 24 Apr 2020 10:23:40 +0200 Subject: [PATCH 10/22] Migrate Plugin out of Framework (to Theme module) --- app/code/Magento/Store/etc/di.xml | 1 - .../code/Magento/Theme}/Plugin/LoadDesignPlugin.php | 2 +- app/code/Magento/Theme/etc/di.xml | 3 +++ 3 files changed, 4 insertions(+), 2 deletions(-) rename {lib/internal/Magento/Framework/App/Action => app/code/Magento/Theme}/Plugin/LoadDesignPlugin.php (97%) diff --git a/app/code/Magento/Store/etc/di.xml b/app/code/Magento/Store/etc/di.xml index 5bd8f6e2349fc..2da9e91e1fddd 100644 --- a/app/code/Magento/Store/etc/di.xml +++ b/app/code/Magento/Store/etc/di.xml @@ -65,7 +65,6 @@ - diff --git a/lib/internal/Magento/Framework/App/Action/Plugin/LoadDesignPlugin.php b/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php similarity index 97% rename from lib/internal/Magento/Framework/App/Action/Plugin/LoadDesignPlugin.php rename to app/code/Magento/Theme/Plugin/LoadDesignPlugin.php index 2cda49c43c2ce..96258c2184ab8 100644 --- a/lib/internal/Magento/Framework/App/Action/Plugin/LoadDesignPlugin.php +++ b/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\Framework\App\Action\Plugin; +namespace Magento\Theme\Plugin; use Magento\Framework\App\ActionInterface; use Magento\Framework\Config\Dom\ValidationException; diff --git a/app/code/Magento/Theme/etc/di.xml b/app/code/Magento/Theme/etc/di.xml index 921e6bfc6ecf1..3acd910f98151 100644 --- a/app/code/Magento/Theme/etc/di.xml +++ b/app/code/Magento/Theme/etc/di.xml @@ -104,6 +104,9 @@ Magento\Store\Model\ScopeInterface::SCOPE_STORE + + + From ae58f560edad58b8c9b6fd01f9460b7c37fd2895 Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Fri, 24 Apr 2020 11:33:56 +0200 Subject: [PATCH 11/22] Fix automated checks --- app/code/Magento/Theme/Plugin/LoadDesignPlugin.php | 8 ++++---- .../Theme/Test/Unit}/Plugin/LoadDesignPluginTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename {lib/internal/Magento/Framework/App/Test/Unit/Action => app/code/Magento/Theme/Test/Unit}/Plugin/LoadDesignPluginTest.php (94%) diff --git a/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php b/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php index 96258c2184ab8..c4f8d3a905d0f 100644 --- a/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php +++ b/app/code/Magento/Theme/Plugin/LoadDesignPlugin.php @@ -21,12 +21,12 @@ class LoadDesignPlugin /** * @var DesignLoader */ - protected $_designLoader; + private $designLoader; /** * @var MessageManagerInterface */ - protected $messageManager; + private $messageManager; /** * @param DesignLoader $designLoader @@ -36,7 +36,7 @@ public function __construct( DesignLoader $designLoader, MessageManagerInterface $messageManager ) { - $this->_designLoader = $designLoader; + $this->designLoader = $designLoader; $this->messageManager = $messageManager; } @@ -50,7 +50,7 @@ public function __construct( public function beforeExecute(ActionInterface $subject) { try { - $this->_designLoader->load(); + $this->designLoader->load(); } catch (LocalizedException $e) { if ($e->getPrevious() instanceof ValidationException) { /** @var MessageInterface $message */ diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Action/Plugin/LoadDesignPluginTest.php b/app/code/Magento/Theme/Test/Unit/Plugin/LoadDesignPluginTest.php similarity index 94% rename from lib/internal/Magento/Framework/App/Test/Unit/Action/Plugin/LoadDesignPluginTest.php rename to app/code/Magento/Theme/Test/Unit/Plugin/LoadDesignPluginTest.php index 90acfde426931..34d53c5d770bc 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Action/Plugin/LoadDesignPluginTest.php +++ b/app/code/Magento/Theme/Test/Unit/Plugin/LoadDesignPluginTest.php @@ -6,10 +6,10 @@ namespace Magento\Framework\App\Test\Unit\Action\Plugin; use Magento\Framework\App\Action\Action; -use Magento\Framework\App\Action\Plugin\LoadDesignPlugin; use Magento\Framework\App\ActionInterface; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\View\DesignLoader; +use Magento\Theme\Plugin\LoadDesignPlugin; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; From 02aae13792fc648c00f6f8e153e208dc0d00c67d Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Sat, 25 Apr 2020 03:44:03 +0200 Subject: [PATCH 12/22] Fix Unit Tests location --- .../Magento/Theme/Test/Unit/Plugin/LoadDesignPluginTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Theme/Test/Unit/Plugin/LoadDesignPluginTest.php b/app/code/Magento/Theme/Test/Unit/Plugin/LoadDesignPluginTest.php index 34d53c5d770bc..4efcc584986d1 100644 --- a/app/code/Magento/Theme/Test/Unit/Plugin/LoadDesignPluginTest.php +++ b/app/code/Magento/Theme/Test/Unit/Plugin/LoadDesignPluginTest.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Framework\App\Test\Unit\Action\Plugin; +namespace Magento\Theme\Test\Unit\Plugin; use Magento\Framework\App\Action\Action; use Magento\Framework\App\ActionInterface; From a09627037573662071d47fa0d022bd4035e45818 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Wed, 13 May 2020 12:37:24 +0300 Subject: [PATCH 13/22] conflict resolved --- .../Product/Form/Modifier/CategoriesTest.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php index 68c0054a9ed92..17318d4207841 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php @@ -10,20 +10,16 @@ use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories; use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory; use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection; -use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory; -use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories; use Magento\Framework\AuthorizationInterface; use Magento\Framework\DB\Helper as DbHelper; use Magento\Framework\UrlInterface; use Magento\Store\Model\Store; -use Magento\Framework\AuthorizationInterface; use Magento\Backend\Model\Auth\Session; use Magento\Authorization\Model\Role; use Magento\User\Model\User; +use PHPUnit\Framework\MockObject\MockObject; /** - * Class CategoriesTest - * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CategoriesTest extends AbstractModifierTest @@ -59,7 +55,7 @@ class CategoriesTest extends AbstractModifierTest private $authorizationMock; /** - * @var \Magento\Backend\Model\Auth\Session|\PHPUnit\Framework\MockObject\MockObject + * @var Session|MockObject */ private $sessionMock; @@ -88,7 +84,6 @@ protected function setUp(): void ->setMethods(['getUser']) ->disableOriginalConstructor() ->getMock(); - $this->categoryCollectionFactoryMock->expects($this->any()) ->method('create') ->willReturn($this->categoryCollectionMock); From a044c531ed9c9dc54cfc73630bbaf0ae003b7995 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Fri, 15 May 2020 13:33:13 +0300 Subject: [PATCH 14/22] refactor --- .../Setup/Test/Unit/Model/InstallerTest.php | 454 ++++++++++-------- 1 file changed, 242 insertions(+), 212 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 6b9e2c8bb549c..b4f10de71dcd1 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -37,6 +37,7 @@ use Magento\Framework\Setup\Patch\PatchApplierFactory; use Magento\Framework\Setup\SampleData\State; use Magento\Framework\Setup\SchemaListener; + use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Setup\Controller\ResponseTypeInterface; use Magento\Setup\Model\AdminAccount; use Magento\Setup\Model\AdminAccountFactory; @@ -45,6 +46,7 @@ use Magento\Setup\Model\Installer; use Magento\Setup\Model\ObjectManagerProvider; use Magento\Setup\Model\PhpReadinessCheck; + use Magento\Setup\Model\SearchConfig; use Magento\Setup\Module\ConnectionFactory; use Magento\Setup\Module\DataSetup; use Magento\Setup\Module\DataSetupFactory; @@ -53,7 +55,6 @@ use Magento\Setup\Validator\DbValidator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; - use Magento\Setup\Model\SearchConfig; /** * @SuppressWarnings(PHPMD.TooManyFields) @@ -62,74 +63,74 @@ class InstallerTest extends TestCase { /** - * @var \Magento\Setup\Model\Installer + * @var Installer */ private $object; /** * @var FilePermissions|MockObject */ - private $filePermissions; + private $filePermissionsMock; /** * @var Writer|MockObject */ - private $configWriter; + private $configWriterMock; /** * @var Reader|MockObject */ - private $configReader; + private $configReaderMock; /** * @var DeploymentConfig|MockObject */ - private $config; + private $configMock; /** * @var ModuleListInterface|MockObject */ - private $moduleList; + private $moduleListMock; /** * @var Loader|MockObject */ - private $moduleLoader; + private $moduleLoaderMock; /** * @var DirectoryList|MockObject */ - private $directoryList; + private $directoryListMock; /** * @var AdminAccountFactory|MockObject */ - private $adminFactory; + private $adminFactoryMock; /** * @var LoggerInterface|MockObject */ - private $logger; + private $loggerMock; /** * @var Random|MockObject */ - private $random; + private $randomMock; /** - * @var MockObject + * @var AdapterInterface|MockObject */ - private $connection; + private $connectionMock; /** * @var MaintenanceMode|MockObject */ - private $maintenanceMode; + private $maintenanceModeMock; /** * @var Filesystem|MockObject */ - private $filesystem; + private $filesystemMock; /** * @var MockObject @@ -139,45 +140,45 @@ class InstallerTest extends TestCase /** * @var ConfigModel|MockObject */ - private $configModel; + private $configModelMock; /** * @var CleanupFiles|MockObject */ - private $cleanupFiles; + private $cleanupFilesMock; /** * @var DbValidator|MockObject */ - private $dbValidator; + private $dbValidatorMock; /** * @var SetupFactory|MockObject */ - private $setupFactory; + private $setupFactoryMock; /** * @var DataSetupFactory|MockObject */ - private $dataSetupFactory; + private $dataSetupFactoryMock; /** * @var State|MockObject */ - private $sampleDataState; + private $sampleDataStateMock; /** * @var ComponentRegistrar|MockObject */ - private $componentRegistrar; + private $componentRegistrarMock; /** - * @var MockObject|PhpReadinessCheck + * @var PhpReadinessCheck|MockObject */ - private $phpReadinessCheck; + private $phpReadinessCheckMock; /** - * @var \Magento\Framework\Setup\DeclarationInstaller|MockObject + * @var DeclarationInstaller|MockObject */ private $declarationInstallerMock; @@ -186,19 +187,6 @@ class InstallerTest extends TestCase */ private $schemaListenerMock; - /** - * Sample DB configuration segment - * @var array - */ - private static $dbConfig = [ - 'default' => [ - ConfigOptionsListConstants::KEY_HOST => '127.0.0.1', - ConfigOptionsListConstants::KEY_NAME => 'magento', - ConfigOptionsListConstants::KEY_USER => 'magento', - ConfigOptionsListConstants::KEY_PASSWORD => '', - ] - ]; - /** * @var Context|MockObject */ @@ -214,91 +202,113 @@ class InstallerTest extends TestCase */ private $patchApplierFactoryMock; + /** + * Sample DB configuration segment + * @var array + */ + private static $dbConfig = [ + 'default' => [ + ConfigOptionsListConstants::KEY_HOST => '127.0.0.1', + ConfigOptionsListConstants::KEY_NAME => 'magento', + ConfigOptionsListConstants::KEY_USER => 'magento', + ConfigOptionsListConstants::KEY_PASSWORD => '', + ] + ]; + protected function setUp(): void { - $this->filePermissions = $this->createMock(FilePermissions::class); - $this->configWriter = $this->createMock(Writer::class); - $this->configReader = $this->createMock(Reader::class); - $this->config = $this->createMock(DeploymentConfig::class); - - $this->moduleList = $this->getMockForAbstractClass(ModuleListInterface::class); - $this->moduleList->expects($this->any())->method('getOne')->willReturn( - ['setup_version' => '2.0.0'] - ); - $this->moduleList->expects($this->any())->method('getNames')->willReturn( - ['Foo_One', 'Bar_Two'] - ); - $this->moduleLoader = $this->createMock(Loader::class); - $this->directoryList = - $this->createMock(DirectoryList::class); - $this->adminFactory = $this->createMock(AdminAccountFactory::class); - $this->logger = $this->getMockForAbstractClass(LoggerInterface::class); - $this->random = $this->createMock(Random::class); - $this->connection = $this->getMockForAbstractClass(AdapterInterface::class); - $this->maintenanceMode = $this->createMock(MaintenanceMode::class); - $this->filesystem = $this->createMock(Filesystem::class); + $this->filePermissionsMock = $this->createMock(FilePermissions::class); + $this->configWriterMock = $this->createMock(Writer::class); + $this->configReaderMock = $this->createMock(Reader::class); + $this->configMock = $this->createMock(DeploymentConfig::class); + + $this->moduleListMock = $this->getMockForAbstractClass(ModuleListInterface::class); + $this->moduleListMock->expects($this->any()) + ->method('getOne') + ->willReturn( + ['setup_version' => '2.0.0'] + ); + $this->moduleListMock->expects($this->any()) + ->method('getNames') + ->willReturn( + ['Foo_One', 'Bar_Two'] + ); + $this->moduleLoaderMock = $this->createMock(Loader::class); + $this->directoryListMock = $this->createMock(DirectoryList::class); + $this->adminFactoryMock = $this->createMock(AdminAccountFactory::class); + $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); + $this->randomMock = $this->createMock(Random::class); + $this->connectionMock = $this->getMockForAbstractClass(AdapterInterface::class); + $this->maintenanceModeMock = $this->createMock(MaintenanceMode::class); + $this->filesystemMock = $this->createMock(Filesystem::class); $this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class); - $this->contextMock = - $this->createMock(Context::class); - $this->configModel = $this->createMock(ConfigModel::class); - $this->cleanupFiles = $this->createMock(CleanupFiles::class); - $this->dbValidator = $this->createMock(DbValidator::class); - $this->setupFactory = $this->createMock(SetupFactory::class); - $this->dataSetupFactory = $this->createMock(DataSetupFactory::class); - $this->sampleDataState = $this->createMock(State::class); - $this->componentRegistrar = - $this->createMock(ComponentRegistrar::class); - $this->phpReadinessCheck = $this->createMock(PhpReadinessCheck::class); + $this->contextMock = $this->createMock(Context::class); + $this->configModelMock = $this->createMock(ConfigModel::class); + $this->cleanupFilesMock = $this->createMock(CleanupFiles::class); + $this->dbValidatorMock = $this->createMock(DbValidator::class); + $this->setupFactoryMock = $this->createMock(SetupFactory::class); + $this->dataSetupFactoryMock = $this->createMock(DataSetupFactory::class); + $this->sampleDataStateMock = $this->createMock(State::class); + $this->componentRegistrarMock = $this->createMock(ComponentRegistrar::class); + $this->phpReadinessCheckMock = $this->createMock(PhpReadinessCheck::class); $this->declarationInstallerMock = $this->createMock(DeclarationInstaller::class); $this->schemaListenerMock = $this->createMock(SchemaListener::class); $this->patchApplierFactoryMock = $this->createMock(PatchApplierFactory::class); $this->patchApplierMock = $this->createMock(PatchApplier::class); - $this->patchApplierFactoryMock->expects($this->any())->method('create')->willReturn( - $this->patchApplierMock - ); + $this->patchApplierFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->patchApplierMock); + $this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class); $this->object = $this->createObject(); } /** * Instantiates the object with mocks - * @param MockObject|bool $connectionFactory - * @param MockObject|bool $objectManagerProvider + * @param MockObject|bool $connectionFactoryMock + * @param MockObject|bool $objectManagerProviderMock * @return Installer */ - private function createObject($connectionFactory = false, $objectManagerProvider = false) + private function createObject($connectionFactoryMock = false, $objectManagerProviderMock = false) { - if (!$connectionFactory) { - $connectionFactory = $this->createMock(ConnectionFactory::class); - $connectionFactory->expects($this->any())->method('create')->willReturn($this->connection); + if (!$connectionFactoryMock) { + $connectionFactoryMock = $this->createMock(ConnectionFactory::class); + $connectionFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->connectionMock); } - if (!$objectManagerProvider) { - $objectManagerProvider = - $this->createMock(ObjectManagerProvider::class); - $objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager); + if (!$objectManagerProviderMock) { + $objectManagerProviderMock = $this->createMock(ObjectManagerProvider::class); + $objectManagerProviderMock->expects($this->any()) + ->method('get') + ->willReturn($this->objectManager); } - return new Installer( - $this->filePermissions, - $this->configWriter, - $this->configReader, - $this->config, - $this->moduleList, - $this->moduleLoader, - $this->adminFactory, - $this->logger, - $connectionFactory, - $this->maintenanceMode, - $this->filesystem, - $objectManagerProvider, - $this->contextMock, - $this->configModel, - $this->cleanupFiles, - $this->dbValidator, - $this->setupFactory, - $this->dataSetupFactory, - $this->sampleDataState, - $this->componentRegistrar, - $this->phpReadinessCheck + return (new ObjectManager($this))->getObject( + Installer::class, + [ + 'filePermissions' => $this->filePermissionsMock, + 'deploymentConfigWriter' => $this->configWriterMock, + 'deploymentConfigReader' => $this->configReaderMock, + 'moduleList' => $this->moduleListMock, + 'moduleLoader' => $this->moduleLoaderMock, + 'adminAccountFactory' => $this->adminFactoryMock, + 'log' => $this->loggerMock, + 'connectionFactory' => $connectionFactoryMock, + 'maintenanceMode' => $this->maintenanceModeMock, + 'filesystem' => $this->filesystemMock, + [], + 'deploymentConfig' => $this->configMock, + 'objectManagerProvider' => $objectManagerProviderMock, + 'context' => $this->contextMock, + 'setupConfigModel' => $this->configModelMock, + 'cleanupFiles' => $this->cleanupFilesMock, + 'dbValidator' => $this->dbValidatorMock, + 'setupFactory' => $this->setupFactoryMock, + 'dataSetupFactory' => $this->dataSetupFactoryMock, + 'sampleDataState' => $this->sampleDataStateMock, + 'componentRegistrar' => $this->componentRegistrarMock, + 'phpReadinessCheck' => $this->phpReadinessCheckMock + ] ); } @@ -308,9 +318,9 @@ private function createObject($connectionFactory = false, $objectManagerProvider * @dataProvider installDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function testInstall(array $request, array $logMessages) + public function testInstall(array $request, array $logMessages): void { - $this->config->expects($this->atLeastOnce()) + $this->configMock->expects($this->atLeastOnce()) ->method('get') ->willReturnMap( [ @@ -322,92 +332,107 @@ public function testInstall(array $request, array $logMessages) $allModules = ['Foo_One' => [], 'Bar_Two' => []]; $this->declarationInstallerMock->expects($this->once())->method('installSchema'); - $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules); - $setup = $this->createMock(Setup::class); - $table = $this->createMock(Table::class); - $connection = $this->getMockBuilder(AdapterInterface::class) + $this->moduleLoaderMock->expects($this->any())->method('load')->willReturn($allModules); + $connectionMock = $this->getMockBuilder(AdapterInterface::class) ->setMethods(['getSchemaListener', 'newTable']) ->getMockForAbstractClass(); - $connection->expects($this->any())->method('getSchemaListener')->willReturn($this->schemaListenerMock); - $setup->expects($this->any())->method('getConnection')->willReturn($connection); - $table->expects($this->any())->method('addColumn')->willReturn($table); - $table->expects($this->any())->method('setComment')->willReturn($table); - $table->expects($this->any())->method('addIndex')->willReturn($table); - $connection->expects($this->any())->method('newTable')->willReturn($table); - $resource = $this->createMock(ResourceConnection::class); - $this->contextMock->expects($this->any())->method('getResources')->willReturn($resource); - $resource->expects($this->any())->method('getConnection')->willReturn($connection); - $dataSetup = $this->createMock(DataSetup::class); - $dataSetup->expects($this->any())->method('getConnection')->willReturn($connection); - $cacheManager = $this->createMock(Manager::class); - $cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->exactly(3))->method('clean'); - $cacheManager->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]); - $appState = $this->getMockBuilder(\Magento\Framework\App\State::class) + $connectionMock->expects($this->any())->method('getSchemaListener')->willReturn($this->schemaListenerMock); + + $setupMock = $this->createMock(Setup::class); + $setupMock->expects($this->any())->method('getConnection')->willReturn($connectionMock); + + $tableMock = $this->createMock(Table::class); + $tableMock->expects($this->any())->method('addColumn')->willReturn($tableMock); + $tableMock->expects($this->any())->method('setComment')->willReturn($tableMock); + $tableMock->expects($this->any())->method('addIndex')->willReturn($tableMock); + + $connectionMock->expects($this->any())->method('newTable')->willReturn($tableMock); + + $resourceMock = $this->createMock(ResourceConnection::class); + $this->contextMock->expects($this->any())->method('getResources')->willReturn($resourceMock); + $resourceMock->expects($this->any())->method('getConnection')->willReturn($connectionMock); + + $dataSetupMock = $this->createMock(DataSetup::class); + $dataSetupMock->expects($this->any())->method('getConnection')->willReturn($connectionMock); + + $cacheManagerMock = $this->createMock(Manager::class); + $cacheManagerMock->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->exactly(3))->method('clean'); + $cacheManagerMock->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]); + + $appStateMock = $this->getMockBuilder(\Magento\Framework\App\State::class) ->disableOriginalConstructor() ->disableArgumentCloning() ->getMock(); - $appState->expects($this->once()) + $appStateMock->expects($this->once()) ->method('setAreaCode') ->with(Area::AREA_GLOBAL); - $registry = $this->createMock(Registry::class); + + $registryMock = $this->createMock(Registry::class); $searchConfigMock = $this->getMockBuilder(SearchConfig::class)->disableOriginalConstructor()->getMock(); - $this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup); - $this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup); + $this->setupFactoryMock->expects($this->atLeastOnce()) + ->method('create') + ->with($resourceMock) + ->willReturn($setupMock); + $this->dataSetupFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($dataSetupMock); $this->objectManager->expects($this->any()) ->method('create') ->willReturnMap([ - [Manager::class, [], $cacheManager], - [\Magento\Framework\App\State::class, [], $appState], + [Manager::class, [], $cacheManagerMock], + [\Magento\Framework\App\State::class, [], $appStateMock], [ PatchApplierFactory::class, ['objectManager' => $this->objectManager], $this->patchApplierFactoryMock ], ]); - $this->patchApplierMock->expects($this->exactly(2))->method('applySchemaPatch')->willReturnMap( - [ - ['Bar_Two'], - ['Foo_One'], - ] - ); - $this->patchApplierMock->expects($this->exactly(2))->method('applyDataPatch')->willReturnMap( - [ - ['Bar_Two'], - ['Foo_One'], - ] - ); + $this->patchApplierMock->expects($this->exactly(2)) + ->method('applySchemaPatch') + ->willReturnMap( + [ + ['Bar_Two'], + ['Foo_One'], + ] + ); + $this->patchApplierMock->expects($this->exactly(2)) + ->method('applyDataPatch') + ->willReturnMap( + [ + ['Bar_Two'], + ['Foo_One'], + ] + ); $this->objectManager->expects($this->any()) ->method('get') ->willReturnMap([ - [\Magento\Framework\App\State::class, $appState], - [Manager::class, $cacheManager], + [\Magento\Framework\App\State::class, $appStateMock], + [Manager::class, $cacheManagerMock], [DeclarationInstaller::class, $this->declarationInstallerMock], - [Registry::class, $registry], + [Registry::class, $registryMock], [SearchConfig::class, $searchConfigMock] ]); - $this->adminFactory->expects($this->any())->method('create')->willReturn( + $this->adminFactoryMock->expects($this->any())->method('create')->willReturn( $this->createMock(AdminAccount::class) ); - $this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true); - $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn( + $this->sampleDataStateMock->expects($this->once())->method('hasError')->willReturn(true); + $this->phpReadinessCheckMock->expects($this->once())->method('checkPhpExtensions')->willReturn( ['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] ); - $this->filePermissions->expects($this->any()) + $this->filePermissionsMock->expects($this->any()) ->method('getMissingWritablePathsForInstallation') ->willReturn([]); - $this->filePermissions->expects($this->once()) + $this->filePermissionsMock->expects($this->once()) ->method('getMissingWritableDirectoriesForDbUpgrade') ->willReturn([]); call_user_func_array( [ - $this->logger->expects($this->exactly(count($logMessages)))->method('log'), + $this->loggerMock->expects($this->exactly(count($logMessages)))->method('log'), 'withConsecutive' ], $logMessages ); - $this->logger->expects($this->exactly(2)) + $this->loggerMock->expects($this->exactly(2)) ->method('logSuccess') ->withConsecutive( ['Magento installation complete.'], @@ -418,10 +443,9 @@ public function testInstall(array $request, array $logMessages) } /** - * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function installDataProvider() + public function installDataProvider(): array { return [ [ @@ -449,12 +473,12 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [print_r(['foo' => 1, 'bar' => 1], true)], + ['foo: 1'], + ['bar: 1'], ['Installing data...'], ['Data install/update:'], ['Disabling caches:'], ['Current status:'], - [print_r([], true)], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Data post-updates:'], @@ -462,7 +486,6 @@ public function installDataProvider() ['Module \'Bar_Two\':'], ['Enabling caches:'], ['Current status:'], - [print_r([], true)], ['Caches clearing:'], ['Cache cleared successfully'], ['Disabling Maintenance Mode:'], @@ -501,12 +524,12 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [print_r(['foo' => 1, 'bar' => 1], true)], + ['foo: 1'], + ['bar: 1'], ['Installing data...'], ['Data install/update:'], ['Disabling caches:'], ['Current status:'], - [print_r([], true)], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Data post-updates:'], @@ -514,7 +537,6 @@ public function installDataProvider() ['Module \'Bar_Two\':'], ['Enabling caches:'], ['Current status:'], - [print_r([], true)], ['Installing admin user...'], ['Caches clearing:'], ['Cache cleared successfully'], @@ -527,39 +549,39 @@ public function installDataProvider() ]; } - public function testCheckInstallationFilePermissions() + public function testCheckInstallationFilePermissions(): void { - $this->filePermissions + $this->filePermissionsMock ->expects($this->once()) ->method('getMissingWritablePathsForInstallation') ->willReturn([]); $this->object->checkInstallationFilePermissions(); } - public function testCheckInstallationFilePermissionsError() + public function testCheckInstallationFilePermissionsError(): void { $this->expectException('Exception'); $this->expectExceptionMessage('Missing write permissions to the following paths:'); - $this->filePermissions + $this->filePermissionsMock ->expects($this->once()) ->method('getMissingWritablePathsForInstallation') ->willReturn(['foo', 'bar']); $this->object->checkInstallationFilePermissions(); } - public function testCheckExtensions() + public function testCheckExtensions(): void { - $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn( + $this->phpReadinessCheckMock->expects($this->once())->method('checkPhpExtensions')->willReturn( ['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] ); $this->object->checkExtensions(); } - public function testCheckExtensionsError() + public function testCheckExtensionsError(): void { $this->expectException('Exception'); $this->expectExceptionMessage('Missing following extensions: \'foo\''); - $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn( + $this->phpReadinessCheckMock->expects($this->once())->method('checkPhpExtensions')->willReturn( [ 'responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, 'data' => ['required' => ['foo', 'bar'], 'missing' => ['foo']] @@ -568,53 +590,53 @@ public function testCheckExtensionsError() $this->object->checkExtensions(); } - public function testCheckApplicationFilePermissions() + public function testCheckApplicationFilePermissions(): void { - $this->filePermissions + $this->filePermissionsMock ->expects($this->once()) ->method('getUnnecessaryWritableDirectoriesForApplication') ->willReturn(['foo', 'bar']); $expectedMessage = "For security, remove write permissions from these directories: 'foo' 'bar'"; - $this->logger->expects($this->once())->method('log')->with($expectedMessage); + $this->loggerMock->expects($this->once())->method('log')->with($expectedMessage); $this->object->checkApplicationFilePermissions(); $this->assertSame(['message' => [$expectedMessage]], $this->object->getInstallInfo()); } - public function testUpdateModulesSequence() + public function testUpdateModulesSequence(): void { - $this->cleanupFiles->expects($this->once())->method('clearCodeGeneratedFiles')->willReturn( + $this->cleanupFilesMock->expects($this->once())->method('clearCodeGeneratedFiles')->willReturn( [ "The directory '/generation' doesn't exist - skipping cleanup", ] ); $installer = $this->prepareForUpdateModulesTests(); - $this->logger->expects($this->at(0))->method('log')->with('Cache cleared successfully'); - $this->logger->expects($this->at(1))->method('log')->with('File system cleanup:'); - $this->logger->expects($this->at(2))->method('log') + $this->loggerMock->expects($this->at(0))->method('log')->with('Cache cleared successfully'); + $this->loggerMock->expects($this->at(1))->method('log')->with('File system cleanup:'); + $this->loggerMock->expects($this->at(2))->method('log') ->with('The directory \'/generation\' doesn\'t exist - skipping cleanup'); - $this->logger->expects($this->at(3))->method('log')->with('Updating modules:'); + $this->loggerMock->expects($this->at(3))->method('log')->with('Updating modules:'); $installer->updateModulesSequence(false); } - public function testUpdateModulesSequenceKeepGenerated() + public function testUpdateModulesSequenceKeepGenerated(): void { - $this->cleanupFiles->expects($this->never())->method('clearCodeGeneratedClasses'); + $this->cleanupFilesMock->expects($this->never())->method('clearCodeGeneratedClasses'); $installer = $this->prepareForUpdateModulesTests(); - $this->logger->expects($this->at(0))->method('log')->with('Cache cleared successfully'); - $this->logger->expects($this->at(1))->method('log')->with('Updating modules:'); + $this->loggerMock->expects($this->at(0))->method('log')->with('Cache cleared successfully'); + $this->loggerMock->expects($this->at(1))->method('log')->with('Updating modules:'); $installer->updateModulesSequence(true); } - public function testUninstall() + public function testUninstall(): void { - $this->config->expects($this->once()) + $this->configMock->expects($this->once()) ->method('get') ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) ->willReturn([]); - $this->configReader->expects($this->once())->method('getFiles')->willReturn([ + $this->configReaderMock->expects($this->once())->method('getFiles')->willReturn([ 'ConfigOne.php', 'ConfigTwo.php' ]); @@ -630,14 +652,14 @@ public function testUninstall() ['ConfigTwo.php', '/config/ConfigTwo.php'] ] ); - $this->filesystem + $this->filesystemMock ->expects($this->any()) ->method('getDirectoryWrite') ->willReturnMap([ [DirectoryList::CONFIG, DriverPool::FILE, $configDir], ]); - $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); - $this->logger + $this->loggerMock->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); + $this->loggerMock ->expects($this->at(2)) ->method('log') ->with('No database connection defined - skipping database cleanup'); @@ -648,26 +670,26 @@ public function testUninstall() ->method('get') ->with(Manager::class) ->willReturn($cacheManager); - $this->logger->expects($this->at(1))->method('log')->with('Cache cleared successfully'); - $this->logger->expects($this->at(3))->method('log')->with('File system cleanup:'); - $this->logger + $this->loggerMock->expects($this->at(1))->method('log')->with('Cache cleared successfully'); + $this->loggerMock->expects($this->at(3))->method('log')->with('File system cleanup:'); + $this->loggerMock ->expects($this->at(4)) ->method('log') ->with("The directory '/var' doesn't exist - skipping cleanup"); - $this->logger + $this->loggerMock ->expects($this->at(5)) ->method('log') ->with("The directory '/static' doesn't exist - skipping cleanup"); - $this->logger + $this->loggerMock ->expects($this->at(6)) ->method('log') ->with("The file '/config/ConfigOne.php' doesn't exist - skipping cleanup"); - $this->logger + $this->loggerMock ->expects($this->at(7)) ->method('log') ->with("The file '/config/ConfigTwo.php' doesn't exist - skipping cleanup"); - $this->logger->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.'); - $this->cleanupFiles->expects($this->once())->method('clearAllFiles')->willReturn( + $this->loggerMock->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.'); + $this->cleanupFilesMock->expects($this->once())->method('clearAllFiles')->willReturn( [ "The directory '/var' doesn't exist - skipping cleanup", "The directory '/static' doesn't exist - skipping cleanup" @@ -677,18 +699,26 @@ public function testUninstall() $this->object->uninstall(); } - public function testCleanupDb() + public function testCleanupDb(): void { - $this->config->expects($this->once()) + $this->configMock->expects($this->once()) ->method('get') ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) ->willReturn(self::$dbConfig); - $this->connection->expects($this->at(0))->method('quoteIdentifier')->with('magento')->willReturn( - '`magento`' - ); - $this->connection->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); - $this->connection->expects($this->at(2))->method('query')->with('CREATE DATABASE IF NOT EXISTS `magento`'); - $this->logger->expects($this->once())->method('log')->with('Cleaning up database `magento`'); + $this->connectionMock->expects($this->at(0)) + ->method('quoteIdentifier') + ->with('magento')->willReturn( + '`magento`' + ); + $this->connectionMock->expects($this->at(1)) + ->method('query') + ->with('DROP DATABASE IF EXISTS `magento`'); + $this->connectionMock->expects($this->at(2)) + ->method('query') + ->with('CREATE DATABASE IF NOT EXISTS `magento`'); + $this->loggerMock->expects($this->once()) + ->method('log') + ->with('Cleaning up database `magento`'); $this->object->cleanupDb(); } @@ -712,7 +742,7 @@ private function prepareForUpdateModulesTests() ->willReturnMap([ [Manager::class, $cacheManager] ]); - $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules); + $this->moduleLoaderMock->expects($this->once())->method('load')->willReturn($allModules); $expectedModules = [ ConfigFilePool::APP_CONFIG => [ @@ -724,15 +754,15 @@ private function prepareForUpdateModulesTests() ] ]; - $this->config->expects($this->atLeastOnce()) + $this->configMock->expects($this->atLeastOnce()) ->method('get') ->with(ConfigOptionsListConstants::KEY_MODULES) ->willReturn(true); $newObject = $this->createObject(false, false); - $this->configReader->expects($this->once())->method('load') + $this->configReaderMock->expects($this->once())->method('load') ->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0]]); - $this->configWriter->expects($this->once())->method('saveConfig')->with($expectedModules); + $this->configWriterMock->expects($this->once())->method('saveConfig')->with($expectedModules); return $newObject; } From fcc3e27f5c55d2eaa5b896bb73488c0e3a0139d8 Mon Sep 17 00:00:00 2001 From: Lukasz Bajsarowicz Date: Sun, 24 May 2020 18:24:09 +0200 Subject: [PATCH 15/22] Generated code is not consistent with Magento requirements and Coding Standard --- .../Developer/Console/Command/patch_template.php.dist | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Developer/Console/Command/patch_template.php.dist b/app/code/Magento/Developer/Console/Command/patch_template.php.dist index f4fc25abcb29a..8e14b24bdc933 100644 --- a/app/code/Magento/Developer/Console/Command/patch_template.php.dist +++ b/app/code/Magento/Developer/Console/Command/patch_template.php.dist @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace %moduleName%\Setup\Patch\%patchType%; @@ -36,7 +37,7 @@ class %class% implements %implementsInterfaces% } %revertFunction% /** - * {@inheritdoc} + * @inheritdoc */ public function getAliases() { @@ -44,12 +45,10 @@ class %class% implements %implementsInterfaces% } /** - * {@inheritdoc} + * @inheritdoc */ public static function getDependencies() { - return [ - - ]; + return []; } } From 035aaf08f8a5e5253a09bf5a7e618acf9d3e32f7 Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Fri, 29 May 2020 13:05:35 +0300 Subject: [PATCH 16/22] fix issue --- .../Plugin/Cms/Model/Store/View.php | 22 ++++++++++++++--- .../Plugin/Cms/Model/Store/ViewTest.php | 24 ++++++++++++------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/View.php b/app/code/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/View.php index e56225cbe2548..31c04d92ac85b 100644 --- a/app/code/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/View.php +++ b/app/code/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/View.php @@ -7,6 +7,7 @@ namespace Magento\CmsUrlRewrite\Plugin\Cms\Model\Store; +use Magento\Cms\Api\Data\PageInterface; use Magento\Cms\Api\PageRepositoryInterface; use Magento\CmsUrlRewrite\Model\CmsPageUrlRewriteGenerator; use Magento\Framework\Api\SearchCriteriaBuilder; @@ -21,6 +22,8 @@ */ class View { + private const ALL_STORE_VIEWS = '0'; + /** * @var UrlPersistInterface */ @@ -89,9 +92,8 @@ private function generateCmsPagesUrls(int $storeId): array { $rewrites = []; $urls = []; - $searchCriteria = $this->searchCriteriaBuilder->create(); - $cmsPagesCollection = $this->pageRepository->getList($searchCriteria)->getItems(); - foreach ($cmsPagesCollection as $page) { + + foreach ($this->getCmsPageItems() as $page) { $page->setStoreId($storeId); $rewrites[] = $this->cmsPageUrlRewriteGenerator->generate($page); } @@ -99,4 +101,18 @@ private function generateCmsPagesUrls(int $storeId): array return $urls; } + + /** + * Return cms page items for all store view + * + * @return PageInterface[] + */ + private function getCmsPageItems(): array + { + $searchCriteria = $this->searchCriteriaBuilder->addFilter('store_id', self::ALL_STORE_VIEWS) + ->create(); + $list = $this->pageRepository->getList($searchCriteria); + + return $list->getItems(); + } } diff --git a/dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php b/dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php index 422cc2958e988..1bcb23d89f425 100644 --- a/dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php +++ b/dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + declare(strict_types=1); namespace Magento\CmsUrlRewrite\Plugin\Cms\Model\Store; @@ -13,13 +14,14 @@ use Magento\TestFramework\Helper\Bootstrap; use Magento\UrlRewrite\Model\UrlFinderInterface; use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; +use PHPUnit\Framework\TestCase; /** - * Test for plugin which is listening store resource model and on save replace cms page url rewrites + * Test for plugin which is listening store resource model and on save replace cms page url rewrites. * * @magentoAppArea adminhtml */ -class ViewTest extends \PHPUnit\Framework\TestCase +class ViewTest extends TestCase { /** * @var UrlFinderInterface @@ -49,26 +51,32 @@ protected function setUp() /** * Test of replacing cms page url rewrites on create and delete store * + * @magentoDataFixture Magento/Cms/_files/two_cms_page_with_same_url_for_different_stores.php * @magentoDataFixture Magento/Cms/_files/pages.php + * + * @return void */ - public function testUrlRewritesChangesAfterStoreSave() + public function testUrlRewritesChangesAfterStoreSave(): void { $storeId = $this->createStore(); - $this->assertUrlRewritesCount($storeId, 1); + $this->assertUrlRewritesCount($storeId, 'page100', 1); + $this->assertUrlRewritesCount($storeId, 'page1', 0); $this->deleteStore($storeId); - $this->assertUrlRewritesCount($storeId, 0); + $this->assertUrlRewritesCount($storeId, 'page100', 0); } /** - * Assert url rewrites count by store id + * Assert url rewrites count by store id and request path * * @param int $storeId + * @param string $requestPath * @param int $expectedCount + * @return void */ - private function assertUrlRewritesCount(int $storeId, int $expectedCount): void + private function assertUrlRewritesCount(int $storeId, string $requestPath, int $expectedCount): void { $data = [ - UrlRewrite::REQUEST_PATH => 'page100', + UrlRewrite::REQUEST_PATH => $requestPath, UrlRewrite::STORE_ID => $storeId ]; $urlRewrites = $this->urlFinder->findAllByData($data); From d4d8ef48391fdff05c9fce5d1cf013dff40d724d Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Mon, 1 Jun 2020 15:13:16 +0300 Subject: [PATCH 17/22] fix --- .../ImportExport/Model/Export/Adapter/Csv.php | 12 +++++ .../Model/Export/Adapter/CsvTest.php | 49 ++++++++++++------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php b/app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php index 09b17371ae4e8..bc4fcd9218e45 100644 --- a/app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php +++ b/app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php @@ -54,6 +54,18 @@ public function destruct() { if (is_object($this->_fileHandler)) { $this->_fileHandler->close(); + $this->resolveDestination(); + } + } + + /** + * Remove temporary destination + * + * @return void + */ + private function resolveDestination(): void + { + if (strpos($this->_destination, '/') === false) { $this->_directoryHandle->delete($this->_destination); } } diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/Adapter/CsvTest.php b/dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/Adapter/CsvTest.php index 9d83b3d2ece98..1bd41b047163a 100644 --- a/dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/Adapter/CsvTest.php +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/Adapter/CsvTest.php @@ -9,6 +9,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem; +use Magento\ImportExport\Model\Import; use Magento\Framework\ObjectManagerInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; @@ -28,43 +29,53 @@ class CsvTest extends TestCase */ private $objectManager; - /** - * @var Csv - */ - private $csv; - /** * @inheritdoc */ protected function setUp(): void { - parent::setUp(); - $this->objectManager = Bootstrap::getObjectManager(); - $this->csv = $this->objectManager->create( - Csv::class, - ['destination' => $this->destination] - ); } /** * Test to destruct export adapter + * + * @dataProvider destructDataProvider + * + * @param string $destination + * @param bool $shouldBeDeleted + * @return void */ - public function testDestruct(): void + public function testDestruct(string $destination, bool $shouldBeDeleted): void { + $csv = $this->objectManager->create(Csv::class, ['destination' => $destination]); /** @var Filesystem $fileSystem */ $fileSystem = $this->objectManager->get(Filesystem::class); $directoryHandle = $fileSystem->getDirectoryRead(DirectoryList::VAR_DIR); /** Assert that the destination file is present after construct */ $this->assertFileExists( - $directoryHandle->getAbsolutePath($this->destination), + $directoryHandle->getAbsolutePath($destination), 'The destination file was\'t created after construct' ); - /** Assert that the destination file was removed after destruct */ - $this->csv = null; - $this->assertFileNotExists( - $directoryHandle->getAbsolutePath($this->destination), - 'The destination file was\'t removed after destruct' - ); + unset($csv); + + if ($shouldBeDeleted) { + $this->assertFileDoesNotExist($directoryHandle->getAbsolutePath($destination)); + } else { + $this->assertFileExists($directoryHandle->getAbsolutePath($destination)); + } + } + + /** + * DataProvider for testDestruct + * + * @return array + */ + public function destructDataProvider(): array + { + return [ + 'temporary file' => [$this->destination, true], + 'import history file' => [Import::IMPORT_HISTORY_DIR . $this->destination, false], + ]; } } From 597d65f0721e3de11d2e3f2c2a39e6490f90eb8b Mon Sep 17 00:00:00 2001 From: Vadim Malesh <51680850+engcom-Charlie@users.noreply.github.com> Date: Mon, 1 Jun 2020 16:16:22 +0300 Subject: [PATCH 18/22] added comment --- app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php b/app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php index bc4fcd9218e45..f5b62df9aea2c 100644 --- a/app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php +++ b/app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php @@ -65,6 +65,7 @@ public function destruct() */ private function resolveDestination(): void { + // only temporary file located directly in var folder if (strpos($this->_destination, '/') === false) { $this->_directoryHandle->delete($this->_destination); } From 8901baa21943a9caf7fe9ea2de1f4fb5e2c82daa Mon Sep 17 00:00:00 2001 From: Nathan de Graaf Date: Thu, 4 Jun 2020 17:24:24 +0200 Subject: [PATCH 19/22] Changed array creation Make the array creation consistent throughout the class --- .../Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php b/app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php index 253dbd43fa580..6ddbce49829eb 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/Items/Invoice/DefaultInvoice.php @@ -80,11 +80,9 @@ public function draw() $lines = []; // draw Product name - $lines[0] = [ - [ + $lines[0][] = [ 'text' => $this->string->split($this->prepareText((string)$item->getName()), 35, true, true), 'feed' => 35 - ] ]; // draw SKU From 9d417ec96f061e700316760c887679caab275e97 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Fri, 5 Jun 2020 13:18:26 +0300 Subject: [PATCH 20/22] resolved conflict --- .../Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php b/dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php index 62922984f69f7..660d59f3264ec 100644 --- a/dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php +++ b/dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php @@ -117,8 +117,6 @@ private function assertUrlRewritesCount(int $storeId, string $requestPath, int $ /** * Create test store - * - * @return int */ private function createStore(): int { @@ -135,7 +133,6 @@ private function createStore(): int * Delete test store * * @param int $storeId - * @return void */ private function deleteStore(int $storeId): void { From 2ac53f86438231d800aff5e2a2fa4f586063d0fb Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Tue, 16 Jun 2020 12:16:20 +0300 Subject: [PATCH 21/22] Close prompt immediately after click ok instead of wait ajax request --- lib/web/mage/adminhtml/browser.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/web/mage/adminhtml/browser.js b/lib/web/mage/adminhtml/browser.js index 604680e0bf8d5..74984024b74a0 100644 --- a/lib/web/mage/adminhtml/browser.js +++ b/lib/web/mage/adminhtml/browser.js @@ -376,7 +376,7 @@ define([ * @param {*} folderName */ confirm: function (folderName) { - return $.ajax({ + $.ajax({ url: self.options.newFolderUrl, dataType: 'json', data: { @@ -399,6 +399,8 @@ define([ ); } }, this)); + + return true; } } }); From 479166ef9ae0ba50c813c3f502372b05299a0c84 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Wed, 17 Jun 2020 12:33:04 +0300 Subject: [PATCH 22/22] resolved conflict --- .../Magento/Setup/Test/Unit/Model/InstallerTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 0d12a73434355..8446486c2f104 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -450,12 +450,12 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [print_r(['foo' => 1, 'bar' => 1], true)], + ['foo: 1'], + ['bar: 1'], ['Installing data...'], ['Data install/update:'], ['Disabling caches:'], ['Current status:'], - [print_r([], true)], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Data post-updates:'], @@ -463,7 +463,6 @@ public function installDataProvider() ['Module \'Bar_Two\':'], ['Enabling caches:'], ['Current status:'], - [print_r([], true)], ['Caches clearing:'], ['Cache cleared successfully'], ['Disabling Maintenance Mode:'], @@ -502,12 +501,12 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [print_r(['foo' => 1, 'bar' => 1], true)], + ['foo: 1'], + ['bar: 1'], ['Installing data...'], ['Data install/update:'], ['Disabling caches:'], ['Current status:'], - [print_r([], true)], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Data post-updates:'], @@ -515,7 +514,6 @@ public function installDataProvider() ['Module \'Bar_Two\':'], ['Enabling caches:'], ['Current status:'], - [print_r([], true)], ['Installing admin user...'], ['Caches clearing:'], ['Cache cleared successfully'],