From f1fe15394bf74c170f7f2489de7cce9c3c81a1c7 Mon Sep 17 00:00:00 2001 From: Viktor Petryk Date: Fri, 17 Jan 2020 18:04:27 +0200 Subject: [PATCH 01/11] MC-30397: Doesn't work: "Files" as fallback when Magento fails to connect to "Redis" --- .../Framework/Session/SaveHandlerTest.php | 148 ++++++++---------- .../Magento/Framework/Session/SaveHandler.php | 87 ++++++---- 2 files changed, 125 insertions(+), 110 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Framework/Session/SaveHandlerTest.php b/dev/tests/integration/testsuite/Magento/Framework/Session/SaveHandlerTest.php index c420f6fa9dd75..dd493a499e855 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Session/SaveHandlerTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Session/SaveHandlerTest.php @@ -3,18 +3,25 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework\Session; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Exception\SessionException; use Magento\Framework\Phrase; use Magento\Framework\Session\Config\ConfigInterface; -use Magento\Framework\App\ObjectManager; +use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\ObjectManager; +/** + * Tests \Magento\Framework\Session\SaveHandler functionality. + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class SaveHandlerTest extends \PHPUnit\Framework\TestCase { /** - * @var \Magento\TestFramework\ObjectManager + * @var ObjectManager */ private $objectManager; @@ -28,15 +35,21 @@ class SaveHandlerTest extends \PHPUnit\Framework\TestCase */ private $saveHandlerFactoryMock; + /** + * @inheritdoc + */ protected function setUp() { - $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->objectManager = Bootstrap::getObjectManager(); $this->deploymentConfigMock = $this->createMock(DeploymentConfig::class); $this->objectManager->addSharedInstance($this->deploymentConfigMock, DeploymentConfig::class); $this->saveHandlerFactoryMock = $this->createMock(SaveHandlerFactory::class); $this->objectManager->addSharedInstance($this->saveHandlerFactoryMock, SaveHandlerFactory::class); } + /** + * @inheritdoc + */ protected function tearDown() { $this->objectManager->removeSharedInstance(DeploymentConfig::class); @@ -44,99 +57,74 @@ protected function tearDown() } /** - * Tests that the session handler is correctly set when object is created. - * - * @dataProvider saveHandlerProvider - * @param string $deploymentConfigHandler + * @return void */ - public function testConstructor($deploymentConfigHandler) + public function testRedisSaveHandler(): void { - $expected = $this->getExpectedSaveHandler($deploymentConfigHandler, ini_get('session.save_handler')); - $this->deploymentConfigMock->method('get') - ->willReturnCallback(function ($configPath) use ($deploymentConfigHandler) { - switch ($configPath) { - case Config::PARAM_SESSION_SAVE_METHOD: - return $deploymentConfigHandler; - case Config::PARAM_SESSION_CACHE_LIMITER: - return 'private_no_expire'; - case Config::PARAM_SESSION_SAVE_PATH: - return 'explicit_save_path'; - default: - return null; - } - }); - - $this->saveHandlerFactoryMock->expects($this->once()) - ->method('create') - ->with($expected); - $sessionConfig = $this->objectManager->create(ConfigInterface::class); - $this->objectManager->create(SaveHandler::class, ['sessionConfig' => $sessionConfig]); + ->willReturnMap( + [ + [Config::PARAM_SESSION_SAVE_METHOD, null, 'redis'], + [Config::PARAM_SESSION_SAVE_PATH, null, 'explicit_save_path'], + ] + ); - // Test expectation - $this->assertEquals( - $expected, - $sessionConfig->getOption('session.save_handler') - ); - } + $redisHandlerMock = $this->getMockBuilder(SaveHandler\Redis::class) + ->disableOriginalConstructor() + ->getMock(); + $redisHandlerMock->method('open') + ->with('explicit_save_path', 'test_session_id') + ->willReturn(true); - public function saveHandlerProvider() - { - return [ - ['db'], - ['redis'], - ['files'], - [false], - ]; + $this->saveHandlerFactoryMock->expects($this->exactly(1)) + ->method('create') + ->with('redis') + ->willReturn($redisHandlerMock); + + $sessionConfig = $this->objectManager->create(ConfigInterface::class); + /** @var SaveHandler $saveHandler */ + $saveHandler = $this->objectManager->create(SaveHandler::class, ['sessionConfig' => $sessionConfig]); + $result = $saveHandler->open('explicit_save_path', 'test_session_id'); + $this->assertTrue($result); } /** - * Retrieve expected session.save_handler - * - * @param string $deploymentConfigHandler - * @param string $iniHandler - * @return string + * @return void */ - private function getExpectedSaveHandler($deploymentConfigHandler, $iniHandler) - { - if ($deploymentConfigHandler) { - return $deploymentConfigHandler; - } elseif ($iniHandler) { - return $iniHandler; - } else { - return SaveHandlerInterface::DEFAULT_HANDLER; - } - } - - public function testConstructorWithException() + public function testRedisSaveHandlerFallbackToDefaultOnSessionException(): void { $this->deploymentConfigMock->method('get') - ->willReturnCallback(function ($configPath) { - switch ($configPath) { - case Config::PARAM_SESSION_SAVE_METHOD: - return 'db'; - case Config::PARAM_SESSION_CACHE_LIMITER: - return 'private_no_expire'; - case Config::PARAM_SESSION_SAVE_PATH: - return 'explicit_save_path'; - default: - return null; - } - }); + ->willReturnMap( + [ + [Config::PARAM_SESSION_SAVE_METHOD, null, 'redis'], + [Config::PARAM_SESSION_SAVE_PATH, null, 'explicit_save_path'], + ] + ); + + $redisHandlerMock = $this->getMockBuilder(SaveHandler\Redis::class) + ->disableOriginalConstructor() + ->getMock(); + $redisHandlerMock->method('open') + ->with('explicit_save_path', 'test_session_id') + ->willThrowException(new SessionException(new Phrase('Session Exception'))); + + $defaultHandlerMock = $this->getMockBuilder(SaveHandler\Native::class) + ->disableOriginalConstructor() + ->getMock(); + $defaultHandlerMock->expects($this->once())->method('open')->with('explicit_save_path', 'test_session_id'); $this->saveHandlerFactoryMock->expects($this->at(0)) ->method('create') - ->willThrowException(new SessionException(new Phrase('Session Exception'))); + ->with('redis') + ->willReturn($redisHandlerMock); $this->saveHandlerFactoryMock->expects($this->at(1)) ->method('create') - ->with(SaveHandlerInterface::DEFAULT_HANDLER); - $sessionConfig = $this->objectManager->create(ConfigInterface::class); - $this->objectManager->create(SaveHandler::class, ['sessionConfig' => $sessionConfig]); + ->with(SaveHandlerInterface::DEFAULT_HANDLER) + ->willReturn($defaultHandlerMock); - // Test expectation - $this->assertEquals( - 'db', - $sessionConfig->getOption('session.save_handler') - ); + $sessionConfig = $this->objectManager->create(ConfigInterface::class); + /** @var SaveHandler $saveHandler */ + $saveHandler = $this->objectManager->create(SaveHandler::class, ['sessionConfig' => $sessionConfig]); + $saveHandler->open('explicit_save_path', 'test_session_id'); } } diff --git a/lib/internal/Magento/Framework/Session/SaveHandler.php b/lib/internal/Magento/Framework/Session/SaveHandler.php index 7959130d1e41c..b43468caa5659 100644 --- a/lib/internal/Magento/Framework/Session/SaveHandler.php +++ b/lib/internal/Magento/Framework/Session/SaveHandler.php @@ -3,13 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Framework\Session; use Magento\Framework\Session\Config\ConfigInterface; -use \Magento\Framework\Exception\SessionException; +use Magento\Framework\Exception\SessionException; /** - * Magento session save handler + * Magento session save handler. */ class SaveHandler implements SaveHandlerInterface { @@ -21,8 +22,21 @@ class SaveHandler implements SaveHandlerInterface protected $saveHandlerAdapter; /** - * Constructor - * + * @var SaveHandlerFactory + */ + private $saveHandlerFactory; + + /** + * @var ConfigInterface + */ + private $sessionConfig; + + /** + * @var string + */ + private $defaultHandler; + + /** * @param SaveHandlerFactory $saveHandlerFactory * @param ConfigInterface $sessionConfig * @param string $default @@ -32,23 +46,13 @@ public function __construct( ConfigInterface $sessionConfig, $default = self::DEFAULT_HANDLER ) { - /** - * Session handler - * - * Save handler may be set to custom value in deployment config, which will override everything else. - * Otherwise, try to read PHP settings for session.save_handler value. Otherwise, use 'files' as default. - */ - $saveMethod = $sessionConfig->getOption('session.save_handler') ?: $default; - - try { - $this->saveHandlerAdapter = $saveHandlerFactory->create($saveMethod); - } catch (SessionException $e) { - $this->saveHandlerAdapter = $saveHandlerFactory->create($default); - } + $this->saveHandlerFactory = $saveHandlerFactory; + $this->sessionConfig = $sessionConfig; + $this->defaultHandler = $default; } /** - * Open Session - retrieve resources + * Open Session - retrieve resources. * * @param string $savePath * @param string $name @@ -56,32 +60,32 @@ public function __construct( */ public function open($savePath, $name) { - return $this->saveHandlerAdapter->open($savePath, $name); + return $this->callSafely('open', $savePath, $name); } /** - * Close Session - free resources + * Close Session - free resources. * * @return bool */ public function close() { - return $this->saveHandlerAdapter->close(); + return $this->callSafely('close'); } /** - * Read session data + * Read session data. * * @param string $sessionId * @return string */ public function read($sessionId) { - return $this->saveHandlerAdapter->read($sessionId); + return $this->callSafely('read', $sessionId); } /** - * Write Session - commit data to resource + * Write Session - commit data to resource. * * @param string $sessionId * @param string $data @@ -89,23 +93,22 @@ public function read($sessionId) */ public function write($sessionId, $data) { - return $this->saveHandlerAdapter->write($sessionId, $data); + return $this->callSafely('write', $sessionId, $data); } /** - * Destroy Session - remove data from resource for given session id + * Destroy Session - remove data from resource for given session id. * * @param string $sessionId * @return bool */ public function destroy($sessionId) { - return $this->saveHandlerAdapter->destroy($sessionId); + return $this->callSafely('destroy', $sessionId); } /** - * Garbage Collection - remove old session data older - * than $maxLifetime (in seconds) + * Garbage Collection - remove old session data older than $maxLifetime (in seconds). * * @param int $maxLifetime * @return bool @@ -113,6 +116,30 @@ public function destroy($sessionId) */ public function gc($maxLifetime) { - return $this->saveHandlerAdapter->gc($maxLifetime); + return $this->callSafely('gc', $maxLifetime); + } + + /** + * Call save handler adapter method. + * + * In case custom handler failed, default files handler is used. + * + * @param string $method + * @param mixed $arguments + * + * @return mixed + */ + private function callSafely(string $method, ...$arguments) + { + try { + if ($this->saveHandlerAdapter === null) { + $saveMethod = $this->sessionConfig->getOption('session.save_handler') ?: $this->defaultHandler; + $this->saveHandlerAdapter = $this->saveHandlerFactory->create($saveMethod); + } + return $this->saveHandlerAdapter->{$method}(...$arguments); + } catch (SessionException $exception) { + $this->saveHandlerAdapter = $this->saveHandlerFactory->create($this->defaultHandler); + return $this->saveHandlerAdapter->{$method}(...$arguments); + } } } From 5d57110df249f75c2d47e1856882af595967c078 Mon Sep 17 00:00:00 2001 From: Viktor Petryk Date: Tue, 28 Jan 2020 15:37:11 +0200 Subject: [PATCH 02/11] MC-25260: A wrong behaviour of a chart order --- .../Magento/Backend/Block/Dashboard/Graph.php | 39 +++---- .../Model/ResourceModel/Order/Collection.php | 1 + .../Block/Dashboard/Tab/OrdersTest.php | 94 ++++++++++++++++ .../Sales/_files/order_list_with_invoice.php | 103 ++++++++++++++++++ .../order_list_with_invoice_rollback.php | 8 ++ 5 files changed, 220 insertions(+), 25 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Backend/Block/Dashboard/Tab/OrdersTest.php create mode 100644 dev/tests/integration/testsuite/Magento/Sales/_files/order_list_with_invoice.php create mode 100644 dev/tests/integration/testsuite/Magento/Sales/_files/order_list_with_invoice_rollback.php diff --git a/app/code/Magento/Backend/Block/Dashboard/Graph.php b/app/code/Magento/Backend/Block/Dashboard/Graph.php index b76421e4e6f67..145c3394efd7b 100644 --- a/app/code/Magento/Backend/Block/Dashboard/Graph.php +++ b/app/code/Magento/Backend/Block/Dashboard/Graph.php @@ -14,9 +14,6 @@ */ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard { - /** - * Api URL - */ const API_URL = 'https://image-charts.com/chart'; /** @@ -190,8 +187,8 @@ public function getChartUrl($directUrl = true) $params = [ 'cht' => 'lc', 'chls' => '7', - 'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0', - 'chm' => 'B,f4d4b2,0,0,0', + 'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0', + 'chm' => 'B,f4d4b2,0,0,0', 'chco' => 'db4814', 'chxs' => '0,0,11|1,0,11', 'chma' => '15,15,15,15' @@ -300,20 +297,23 @@ public function getChartUrl($directUrl = true) $minvalue = min($localminvalue); // default values - $yLabels = []; $miny = 0; $maxy = 0; $yorigin = 0; + $xAxis = 'x'; + $xAxisIndex = 0; + $yAxisIndex = 1; if ($minvalue >= 0 && $maxvalue >= 0) { if ($maxvalue > 10) { - $p = pow(10, $this->_getPow((int) $maxvalue)); + $p = pow(10, $this->_getPow((int)$maxvalue)); $maxy = ceil($maxvalue / $p) * $p; - $yLabels = range($miny, $maxy, $p); + $yRange = "$yAxisIndex,$miny,$maxy,$p"; } else { $maxy = ceil($maxvalue + 1); - $yLabels = range($miny, $maxy, 1); + $yRange = "$yAxisIndex,$miny,$maxy,1"; } + $params['chxr'] = $yRange; $yorigin = 0; } @@ -341,22 +341,11 @@ public function getChartUrl($directUrl = true) $params['chd'] .= $buffer; - $valueBuffer = []; - if (count($this->_axisLabels) > 0) { $params['chxt'] = implode(',', array_keys($this->_axisLabels)); - $indexid = 0; - foreach ($this->_axisLabels as $idx => $labels) { - if ($idx == 'x') { - $this->formatAxisLabelDate((string) $idx, (string) $timezoneLocal); - $tmpstring = implode('|', $this->_axisLabels[$idx]); - $valueBuffer[] = $indexid . ":|" . $tmpstring; - } elseif ($idx == 'y') { - $valueBuffer[] = $indexid . ":|" . implode('|', $yLabels); - } - $indexid++; - } - $params['chxl'] = implode('|', $valueBuffer); + $this->formatAxisLabelDate($xAxis, (string)$timezoneLocal); + $customAxisLabels = $xAxisIndex . ":|" . implode('|', $this->_axisLabels[$xAxis]); + $params['chxl'] = $customAxisLabels . $dataSetdelimiter; } // chart size @@ -368,7 +357,7 @@ public function getChartUrl($directUrl = true) foreach ($params as $name => $value) { $p[] = $name . '=' . urlencode($value); } - return (string) self::API_URL . '?' . implode('&', $p); + return (string)self::API_URL . '?' . implode('&', $p); } $gaData = urlencode(base64_encode(json_encode($params))); $gaHash = $this->_dashboardData->getChartDataHash($gaData); @@ -392,7 +381,7 @@ private function formatAxisLabelDate($idx, $timezoneLocal) switch ($this->getDataHelper()->getParam('period')) { case '24h': $this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime( - $period->setTime((int) $period->format('H'), 0, 0), + $period->setTime((int)$period->format('H'), 0, 0), \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT ); diff --git a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php index d89a118bff94b..0a74c23fad991 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php @@ -461,6 +461,7 @@ public function getDateRange($range, $customStart, $customEnd, $returnObjects = $startMonth = isset($startMonthDay[0]) ? (int)$startMonthDay[0] : 1; $startDay = isset($startMonthDay[1]) ? (int)$startMonthDay[1] : 1; $dateStart->setDate($dateStart->format('Y'), $startMonth, $startDay); + $dateStart->modify('-1 year'); if ($range == '2y') { $dateStart->modify('-1 year'); } diff --git a/dev/tests/integration/testsuite/Magento/Backend/Block/Dashboard/Tab/OrdersTest.php b/dev/tests/integration/testsuite/Magento/Backend/Block/Dashboard/Tab/OrdersTest.php new file mode 100644 index 0000000000000..f5b730173e596 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Backend/Block/Dashboard/Tab/OrdersTest.php @@ -0,0 +1,94 @@ +objectManager = Bootstrap::getObjectManager(); + $this->layout = $this->objectManager->get(LayoutInterface::class); + $this->graphBlock = $this->layout->createBlock(Graph::class); + } + + /** + * @magentoDbIsolation disabled + * @magentoDataFixture Magento/Sales/_files/order_list_with_invoice.php + * @dataProvider chartUrlDataProvider + * @param string $period + * @param string $expectedAxisRange + * @return void + */ + public function testGetChartUrl(string $period, string $expectedAxisRange): void + { + $this->graphBlock->getRequest()->setParams(['period' => $period]); + $ordersBlock = $this->layout->createBlock(Orders::class); + $decodedChartUrl = urldecode($ordersBlock->getChartUrl()); + $chartUrlSegments = explode('&', $decodedChartUrl); + $this->assertEquals($expectedAxisRange, $this->getUrlParamData($chartUrlSegments, 'chxr')); + } + + /** + * @return array + */ + public function chartUrlDataProvider(): array + { + return [ + 'Last 24 Hours' => ['24h', '1,0,2,1'], + 'Last 7 Days' => ['7d', '1,0,3,1'], + 'Current Month' => ['1m', '1,0,3,1'], + 'YTD' => ['1y', '1,0,4,1'], + '2YTD' => ['2y', '1,0,4,1'], + ]; + } + + /** + * @param array $chartUrlSegments + * @param string $paramName + * @return string + */ + private function getUrlParamData(array $chartUrlSegments, string $paramName): string + { + $urlParams = []; + foreach ($chartUrlSegments as $chartUrlSegment) { + list($paramKey, $paramValue) = explode('=', $chartUrlSegment); + $urlParams[$paramKey] = $paramValue; + } + + return $urlParams[$paramName] ?? ''; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/order_list_with_invoice.php b/dev/tests/integration/testsuite/Magento/Sales/_files/order_list_with_invoice.php new file mode 100644 index 0000000000000..06ddb18b009d1 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/order_list_with_invoice.php @@ -0,0 +1,103 @@ +get(OrderInterfaceFactory::class); +/** @var OrderRepositoryInterface $orderRepository */ +$orderRepository = $objectManager->get(OrderRepositoryInterface::class); +/** @var InvoiceManagementInterface $invoiceManagement */ +$invoiceManagement = $objectManager->get(InvoiceManagementInterface::class); +/** @var Transaction $transaction */ +$transaction = $objectManager->get(Transaction::class); + +$dateTime = new \DateTimeImmutable(); +$ordersData = [ + [ + 'increment_id' => '100000002', + 'state' => Order::STATE_PROCESSING, + 'status' => 'processing', + 'base_to_global_rate' => 1, + 'base_grand_total' => 120.00, + 'grand_total' => 120.00, + 'subtotal' => 120.00, + 'created_at' => $dateTime->modify('-1 hour')->format(DateTime::DATETIME_PHP_FORMAT), + ], + [ + 'increment_id' => '100000003', + 'state' => Order::STATE_PROCESSING, + 'status' => 'processing', + 'base_to_global_rate' => 1, + 'base_grand_total' => 130.00, + 'grand_total' => 130.00, + 'subtotal' => 130.00, + 'created_at' => $dateTime->modify('-1 day')->format(DateTime::DATETIME_PHP_FORMAT), + ], + [ + 'increment_id' => '100000004', + 'state' => Order::STATE_PROCESSING, + 'status' => 'processing', + 'base_to_global_rate' => 1, + 'base_grand_total' => 140.00, + 'grand_total' => 140.00, + 'subtotal' => 140.00, + 'created_at' => $dateTime->modify('-1 month')->format(DateTime::DATETIME_PHP_FORMAT), + ], + [ + 'increment_id' => '100000005', + 'state' => Order::STATE_PROCESSING, + 'status' => 'processing', + 'base_to_global_rate' => 1, + 'base_grand_total' => 150.00, + 'grand_total' => 150.00, + 'subtotal' => 150.00, + 'created_at' => $dateTime->modify('-1 year')->format(DateTime::DATETIME_PHP_FORMAT), + ], + [ + 'increment_id' => '100000006', + 'state' => Order::STATE_PROCESSING, + 'status' => 'processing', + 'base_to_global_rate' => 1, + 'base_grand_total' => 160.00, + 'grand_total' => 160.00, + 'subtotal' => 160.00, + 'created_at' => $dateTime->modify('-2 year')->format(DateTime::DATETIME_PHP_FORMAT), + ], +]; + +foreach ($ordersData as $orderData) { + /** @var Order $order */ + $order = $orderFactory->create(); + $order + ->setData($orderData) + ->addItem($orderItem) + ->setCustomerIsGuest(true) + ->setCustomerEmail('customer@null.com') + ->setBillingAddress($billingAddress) + ->setShippingAddress($shippingAddress) + ->setPayment($payment); + $orderRepository->save($order); + + /** @var Invoice $invoice */ + $invoice = $invoiceManagement->prepareInvoice($order); + $invoice->register(); + $order->setIsInProcess(true); + $transaction + ->addObject($order) + ->addObject($invoice) + ->save(); +} diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/order_list_with_invoice_rollback.php b/dev/tests/integration/testsuite/Magento/Sales/_files/order_list_with_invoice_rollback.php new file mode 100644 index 0000000000000..2595d6bf4084a --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/order_list_with_invoice_rollback.php @@ -0,0 +1,8 @@ + Date: Wed, 29 Jan 2020 18:40:52 +0200 Subject: [PATCH 03/11] MC-25260: A wrong behaviour of a chart order --- .../Backend/Block/Dashboard/Tab/OrdersTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Backend/Block/Dashboard/Tab/OrdersTest.php b/dev/tests/integration/testsuite/Magento/Backend/Block/Dashboard/Tab/OrdersTest.php index f5b730173e596..1ac68b8d7ff57 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Block/Dashboard/Tab/OrdersTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Block/Dashboard/Tab/OrdersTest.php @@ -46,7 +46,6 @@ protected function setUp() } /** - * @magentoDbIsolation disabled * @magentoDataFixture Magento/Sales/_files/order_list_with_invoice.php * @dataProvider chartUrlDataProvider * @param string $period @@ -58,8 +57,7 @@ public function testGetChartUrl(string $period, string $expectedAxisRange): void $this->graphBlock->getRequest()->setParams(['period' => $period]); $ordersBlock = $this->layout->createBlock(Orders::class); $decodedChartUrl = urldecode($ordersBlock->getChartUrl()); - $chartUrlSegments = explode('&', $decodedChartUrl); - $this->assertEquals($expectedAxisRange, $this->getUrlParamData($chartUrlSegments, 'chxr')); + $this->assertEquals($expectedAxisRange, $this->getUrlParamData($decodedChartUrl, 'chxr')); } /** @@ -77,18 +75,20 @@ public function chartUrlDataProvider(): array } /** - * @param array $chartUrlSegments + * @param string $chartUrl * @param string $paramName * @return string */ - private function getUrlParamData(array $chartUrlSegments, string $paramName): string + private function getUrlParamData(string $chartUrl, string $paramName): string { - $urlParams = []; + $chartUrlSegments = explode('&', $chartUrl); foreach ($chartUrlSegments as $chartUrlSegment) { - list($paramKey, $paramValue) = explode('=', $chartUrlSegment); - $urlParams[$paramKey] = $paramValue; + [$paramKey, $paramValue] = explode('=', $chartUrlSegment); + if ($paramKey === $paramName) { + return $paramValue; + } } - return $urlParams[$paramName] ?? ''; + return ''; } } From 0702f7d88d4251defe54389fe853c27db3737ae3 Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Tue, 4 Feb 2020 15:07:26 +0200 Subject: [PATCH 04/11] MC-16249: [CLOUD] Attachment is not opened on storefront --- .../Customer/Model/CustomerRegistry.php | 2 +- .../Model/App/Response/HttpPlugin.php | 3 +- .../Model/App/Response/HttpPluginTest.php | 93 +++++++++++++------ .../Php/_files/phpstan/blacklist/common.txt | 1 + 4 files changed, 70 insertions(+), 29 deletions(-) diff --git a/app/code/Magento/Customer/Model/CustomerRegistry.php b/app/code/Magento/Customer/Model/CustomerRegistry.php index b89cce8957487..d68904f6d1645 100644 --- a/app/code/Magento/Customer/Model/CustomerRegistry.php +++ b/app/code/Magento/Customer/Model/CustomerRegistry.php @@ -195,7 +195,7 @@ public function removeByEmail($customerEmail, $websiteId = null) $websiteId = $this->storeManager->getStore()->getWebsiteId(); } $emailKey = $this->getEmailKey($customerEmail, $websiteId); - if ($emailKey) { + if (isset($this->customerRegistryByEmail[$emailKey])) { /** @var Customer $customer */ $customer = $this->customerRegistryByEmail[$emailKey]; unset($this->customerRegistryByEmail[$emailKey]); diff --git a/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php b/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php index bf958707dde49..7a3b9055d0d12 100644 --- a/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php +++ b/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php @@ -19,9 +19,10 @@ class HttpPlugin */ public function beforeSendResponse(\Magento\Framework\App\Response\Http $subject) { - if ($subject instanceof \Magento\Framework\App\PageCache\NotCacheableInterface) { + if ($subject instanceof \Magento\Framework\App\PageCache\NotCacheableInterface || headers_sent()) { return; } + $subject->sendVary(); } } diff --git a/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php b/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php index 59591c8ee957f..5b5fa1f0ff12a 100644 --- a/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php +++ b/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php @@ -4,36 +4,75 @@ * See COPYING.txt for license details. */ -namespace Magento\PageCache\Test\Unit\Model\App\Response; - -use Magento\PageCache\Model\App\Response\HttpPlugin; - -class HttpPluginTest extends \PHPUnit\Framework\TestCase -{ - /** - * @param \Magento\Framework\App\Response\FileInterface $responseInstanceClass - * @param int $sendVaryCalled - * - * @dataProvider beforeSendResponseDataProvider - */ - public function testBeforeSendResponse($responseInstanceClass, $sendVaryCalled) +// @codingStandardsIgnoreStart +namespace Magento\PageCache\Model\App\Response { + $mockPHPFunctions = false; + + function headers_sent() { - /** @var \Magento\Framework\App\Response\Http | \PHPUnit_Framework_MockObject_MockObject $responseMock */ - $responseMock = $this->createMock($responseInstanceClass); - $responseMock->expects($this->exactly($sendVaryCalled)) - ->method('sendVary'); - $plugin = new HttpPlugin(); - $plugin->beforeSendResponse($responseMock); + global $mockPHPFunctions; + if ($mockPHPFunctions) { + return false; + } + + return call_user_func_array('\headers_sent', func_get_args()); } +} + +namespace Magento\PageCache\Test\Unit\Model\App\Response { + + use Magento\Framework\App\Response\Http; + use Magento\MediaStorage\Model\File\Storage\Response; + use Magento\PageCache\Model\App\Response\HttpPlugin; - /** - * @return array - */ - public function beforeSendResponseDataProvider() + // @codingStandardsIgnoreEnd + + class HttpPluginTest extends \PHPUnit\Framework\TestCase { - return [ - [\Magento\Framework\App\Response\Http::class, 1], - [\Magento\MediaStorage\Model\File\Storage\Response::class, 0] - ]; + /** + * @inheritdoc + */ + protected function setUp() + { + global $mockPHPFunctions; + $mockPHPFunctions = true; + } + + /** + * @inheritdoc + */ + protected function tearDown() + { + global $mockPHPFunctions; + $mockPHPFunctions = false; + } + + /** + * @param string $responseInstanceClass + * @param int $sendVaryCalled + * @return void + * + * @dataProvider beforeSendResponseDataProvider + */ + public function testBeforeSendResponse(string $responseInstanceClass, int $sendVaryCalled): void + { + /** @var Http | \PHPUnit_Framework_MockObject_MockObject $responseMock */ + $responseMock = $this->createMock($responseInstanceClass); + $responseMock->expects($this->exactly($sendVaryCalled)) + ->method('sendVary'); + $plugin = new HttpPlugin(); + $plugin->beforeSendResponse($responseMock); + } + + /** + * @return array + */ + public function beforeSendResponseDataProvider(): array + { + return [ + [Http::class, 1], + [Response::class, 0] + ]; + } } } diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt index f54defbd57604..5066040e484cb 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt @@ -14,3 +14,4 @@ dev/tests/api-functional/testsuite/Magento/Customer/Api/AddressRepositoryTest.ph dev/tests/api-functional/testsuite/Magento/Framework/Model/Entity/HydratorTest.php dev/tests/api-functional/testsuite/Magento/Integration/Model/AdminTokenServiceTest.php dev/tests/api-functional/testsuite/Magento/Integration/Model/CustomerTokenServiceTest.php +app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php From 96a2e17754c78e3939fcbe14f7729d7ded52e544 Mon Sep 17 00:00:00 2001 From: Krissy Hiserote Date: Tue, 4 Feb 2020 15:19:37 -0600 Subject: [PATCH 05/11] MC-30236: Upgrade from 2.3.x CE with SD to 2.3.x EE AreaCode Exception --- setup/src/Magento/Setup/Model/Installer.php | 42 +++++++++++++++------ 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 23f8a13c8bfe8..ee7d5a196127b 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -7,6 +7,8 @@ namespace Magento\Setup\Model; use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList; +use Magento\Framework\App\Cache\Type\Block as BlockCache; +use Magento\Framework\App\Cache\Type\Layout as LayoutCache; use Magento\Framework\App\DeploymentConfig\Reader; use Magento\Framework\App\DeploymentConfig\Writer; use Magento\Framework\App\Filesystem\DirectoryList; @@ -35,6 +37,7 @@ use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\Setup\UpgradeDataInterface; use Magento\Framework\Setup\UpgradeSchemaInterface; +use Magento\PageCache\Model\Cache\Type as PageCache; use Magento\Setup\Console\Command\InstallCommand; use Magento\Setup\Controller\ResponseTypeInterface; use Magento\Setup\Model\ConfigModel as SetupConfigModel; @@ -336,7 +339,7 @@ public function install($request) } $script[] = ['Installing database schema:', 'installSchema', [$request]]; $script[] = ['Installing user configuration...', 'installUserConfig', [$request]]; - $script[] = ['Enabling caches:', 'enableCaches', []]; + $script[] = ['Enabling caches:', 'updateCaches', [true]]; $script[] = ['Installing data...', 'installDataFixtures', [$request]]; if (!empty($request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX])) { $script[] = [ @@ -866,6 +869,12 @@ private function convertationOfOldScriptsIsAllowed(array $request) */ public function installDataFixtures(array $request = []) { + $frontendCaches = [ + PageCache::TYPE_IDENTIFIER, + BlockCache::TYPE_IDENTIFIER, + LayoutCache::TYPE_IDENTIFIER, + ]; + /** @var \Magento\Framework\Registry $registry */ $registry = $this->objectManagerProvider->get()->get(\Magento\Framework\Registry::class); //For backward compatibility in install and upgrade scripts with enabled parallelization. @@ -876,7 +885,9 @@ public function installDataFixtures(array $request = []) $setup = $this->dataSetupFactory->create(); $this->checkFilePermissionsForDbUpgrade(); $this->log->log('Data install/update:'); + $this->updateCaches(false, $frontendCaches, false); $this->handleDBSchemaData($setup, 'data', $request); + $this->updateCaches(true, $frontendCaches, false); $registry->unregister('setup-mode-enabled'); } @@ -1248,23 +1259,32 @@ public function uninstall() } /** - * Enables caches after installing application + * Enable or disable caches for specific types * - * @return void + * If no types are specified then it will enable or disable all available types + * Note this is called by install() via callback. * - * @SuppressWarnings(PHPMD.UnusedPrivateMethod) Called by install() via callback. + * @param bool $isEnabled + * @param array $types + * @param bool $logStatus + * @return void */ - private function enableCaches() + private function updateCaches($isEnabled, $types = [], $logStatus = true) { /** @var \Magento\Framework\App\Cache\Manager $cacheManager */ $cacheManager = $this->objectManagerProvider->get()->create(\Magento\Framework\App\Cache\Manager::class); - $types = $cacheManager->getAvailableTypes(); - $enabledTypes = $cacheManager->setEnabled($types, true); - $cacheManager->clean($enabledTypes); + $types = empty($types) ? $cacheManager->getAvailableTypes() : $types; + + $enabledTypes = $cacheManager->setEnabled($types, $isEnabled); + if($isEnabled){ + $cacheManager->clean($enabledTypes); + } - $this->log->log('Current status:'); - // phpcs:ignore Magento2.Functions.DiscouragedFunction - $this->log->log(print_r($cacheManager->getStatus(), true)); + if ($logStatus) { + $this->log->log('Current status:'); + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $this->log->log(print_r($cacheManager->getStatus(), true)); + } } /** From 25886c2d3dd819a65db4a92a888db0d767c53b3b Mon Sep 17 00:00:00 2001 From: Krissy Hiserote Date: Wed, 5 Feb 2020 09:33:05 -0600 Subject: [PATCH 06/11] MC-30236: Upgrade from 2.3.x CE with SD to 2.3.x EE AreaCode Exception - log cache status of only specific types --- setup/src/Magento/Setup/Model/Installer.php | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index ee7d5a196127b..2492248551461 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -885,9 +885,11 @@ public function installDataFixtures(array $request = []) $setup = $this->dataSetupFactory->create(); $this->checkFilePermissionsForDbUpgrade(); $this->log->log('Data install/update:'); - $this->updateCaches(false, $frontendCaches, false); + $this->log->log('Disabling caches:'); + $this->updateCaches(false, $frontendCaches); $this->handleDBSchemaData($setup, 'data', $request); - $this->updateCaches(true, $frontendCaches, false); + $this->log->log('Enabling caches:'); + $this->updateCaches(true, $frontendCaches); $registry->unregister('setup-mode-enabled'); } @@ -1266,25 +1268,31 @@ public function uninstall() * * @param bool $isEnabled * @param array $types - * @param bool $logStatus * @return void */ - private function updateCaches($isEnabled, $types = [], $logStatus = true) + private function updateCaches($isEnabled, $types = []) { /** @var \Magento\Framework\App\Cache\Manager $cacheManager */ $cacheManager = $this->objectManagerProvider->get()->create(\Magento\Framework\App\Cache\Manager::class); - $types = empty($types) ? $cacheManager->getAvailableTypes() : $types; + $types = empty($types) ? $cacheManager->getAvailableTypes() : $types; $enabledTypes = $cacheManager->setEnabled($types, $isEnabled); if($isEnabled){ $cacheManager->clean($enabledTypes); } - if ($logStatus) { - $this->log->log('Current status:'); - // phpcs:ignore Magento2.Functions.DiscouragedFunction - $this->log->log(print_r($cacheManager->getStatus(), true)); - } + // Only get statuses of specific cache types + $cacheStatus = array_filter( + $cacheManager->getStatus(), + function (string $key) use ($types) { + return in_array($key, $types); + }, + ARRAY_FILTER_USE_KEY + ); + + $this->log->log('Current status:'); + // phpcs:ignore Magento2.Functions.DiscouragedFunction + $this->log->log(print_r($cacheStatus, true)); } /** From 5a2ea65fe45f762e9552f2d6f2786636148215fe Mon Sep 17 00:00:00 2001 From: Krissy Hiserote Date: Thu, 6 Feb 2020 10:46:31 -0600 Subject: [PATCH 07/11] MC-30236: Upgrade from 2.3.x CE with SD to 2.3.x EE AreaCode Exception - fix unit and integration tests --- setup/src/Magento/Setup/Model/Installer.php | 7 ++++--- .../Setup/Test/Unit/Model/InstallerTest.php | 21 +++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 2492248551461..535040f942b89 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -1261,7 +1261,7 @@ public function uninstall() } /** - * Enable or disable caches for specific types + * Enable or disable caches for specific types that are available * * If no types are specified then it will enable or disable all available types * Note this is called by install() via callback. @@ -1275,9 +1275,10 @@ private function updateCaches($isEnabled, $types = []) /** @var \Magento\Framework\App\Cache\Manager $cacheManager */ $cacheManager = $this->objectManagerProvider->get()->create(\Magento\Framework\App\Cache\Manager::class); - $types = empty($types) ? $cacheManager->getAvailableTypes() : $types; + $availableTypes = $cacheManager->getAvailableTypes(); + $types = empty($types) ? $availableTypes : array_intersect($availableTypes, $types); $enabledTypes = $cacheManager->setEnabled($types, $isEnabled); - if($isEnabled){ + if ($isEnabled) { $cacheManager->clean($enabledTypes); } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index e600002d53560..7833ec127816f 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -307,8 +307,9 @@ public function testInstall(array $request, array $logMessages) $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->once())->method('setEnabled')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->any())->method('clean'); + $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([]); $appState = $this->getMockBuilder(\Magento\Framework\App\State::class) ->disableOriginalConstructor() ->disableArgumentCloning() @@ -410,15 +411,21 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [''], + [print_r([],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\':'], //['Installing admin user...'], + ['Enabling caches:'], + ['Current status:'], + [print_r([],true)], ['Caches clearing:'], ['Cache cleared successfully'], ['Disabling Maintenance Mode:'], @@ -456,14 +463,20 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [''], + [print_r([],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'], From 4d5f03395d7d2e2da59f89bf4a0c61f9e5921b81 Mon Sep 17 00:00:00 2001 From: Krissy Hiserote Date: Thu, 6 Feb 2020 12:13:47 -0600 Subject: [PATCH 08/11] MC-30236: Upgrade from 2.3.x CE with SD to 2.3.x EE AreaCode Exception - fix static tests --- .../Setup/Test/Unit/Model/InstallerTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 7833ec127816f..d087162f9b06e 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -383,6 +383,7 @@ public function testInstall(array $request, array $logMessages) /** * @return array + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function installDataProvider() { @@ -411,21 +412,20 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [print_r([],true)], + [print_r([], true)], ['Installing data...'], ['Data install/update:'], ['Disabling caches:'], ['Current status:'], - [print_r([],true)], + [print_r([], true)], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Data post-updates:'], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], - //['Installing admin user...'], ['Enabling caches:'], ['Current status:'], - [print_r([],true)], + [print_r([], true)], ['Caches clearing:'], ['Cache cleared successfully'], ['Disabling Maintenance Mode:'], @@ -463,12 +463,12 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [print_r([],true)], + [print_r([], true)], ['Installing data...'], ['Data install/update:'], ['Disabling caches:'], ['Current status:'], - [print_r([],true)], + [print_r([], true)], ['Module \'Foo_One\':'], ['Module \'Bar_Two\':'], ['Data post-updates:'], @@ -476,7 +476,7 @@ public function installDataProvider() ['Module \'Bar_Two\':'], ['Enabling caches:'], ['Current status:'], - [print_r([],true)], + [print_r([], true)], ['Installing admin user...'], ['Caches clearing:'], ['Cache cleared successfully'], From 8641b01b70a7d1b86c1b74548cd62e2e84027e60 Mon Sep 17 00:00:00 2001 From: Viktor Petryk Date: Mon, 10 Feb 2020 00:31:21 -0800 Subject: [PATCH 09/11] MC-25260: A wrong behaviour of a chart order --- app/code/Magento/Backend/Block/Dashboard/Graph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Backend/Block/Dashboard/Graph.php b/app/code/Magento/Backend/Block/Dashboard/Graph.php index 145c3394efd7b..527bb2136b4c5 100644 --- a/app/code/Magento/Backend/Block/Dashboard/Graph.php +++ b/app/code/Magento/Backend/Block/Dashboard/Graph.php @@ -234,7 +234,7 @@ public function getChartUrl($directUrl = true) case '1y': case '2y': $d = $dateStart->format('Y-m'); - $dateStart->modify('+1 month'); + $dateStart->modify('first day of next month'); break; default: $d = $dateStart->format('Y-m-d H:00'); From 1e6f8bc6a811074fe8b504fc60ea3f05fce94e24 Mon Sep 17 00:00:00 2001 From: Andrii Meysar Date: Mon, 10 Feb 2020 12:27:51 +0200 Subject: [PATCH 10/11] MC-16249: [CLOUD] Attachment is not opened on storefront --- .../Model/App/Response/HttpPlugin.php | 9 +- .../Model/App/Response/HttpPluginTest.php | 113 ++++++++---------- .../Php/_files/phpstan/blacklist/common.txt | 1 - 3 files changed, 56 insertions(+), 67 deletions(-) diff --git a/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php b/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php index 7a3b9055d0d12..a6949cccc1add 100644 --- a/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php +++ b/app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php @@ -6,6 +6,9 @@ namespace Magento\PageCache\Model\App\Response; +use Magento\Framework\App\PageCache\NotCacheableInterface; +use Magento\Framework\App\Response\Http as HttpResponse; + /** * HTTP response plugin for frontend. */ @@ -14,12 +17,12 @@ class HttpPlugin /** * Set proper value of X-Magento-Vary cookie. * - * @param \Magento\Framework\App\Response\Http $subject + * @param HttpResponse $subject * @return void */ - public function beforeSendResponse(\Magento\Framework\App\Response\Http $subject) + public function beforeSendResponse(HttpResponse $subject) { - if ($subject instanceof \Magento\Framework\App\PageCache\NotCacheableInterface || headers_sent()) { + if ($subject instanceof NotCacheableInterface || $subject->headersSent()) { return; } diff --git a/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php b/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php index 5b5fa1f0ff12a..6f8f12098dda8 100644 --- a/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php +++ b/app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php @@ -3,76 +3,63 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); -// @codingStandardsIgnoreStart -namespace Magento\PageCache\Model\App\Response { - $mockPHPFunctions = false; +namespace Magento\PageCache\Test\Unit\Model\App\Response; - function headers_sent() - { - global $mockPHPFunctions; - if ($mockPHPFunctions) { - return false; - } - - return call_user_func_array('\headers_sent', func_get_args()); - } -} - -namespace Magento\PageCache\Test\Unit\Model\App\Response { - - use Magento\Framework\App\Response\Http; - use Magento\MediaStorage\Model\File\Storage\Response; - use Magento\PageCache\Model\App\Response\HttpPlugin; +use Magento\Framework\App\Response\Http as HttpResponse; +use Magento\MediaStorage\Model\File\Storage\Response as FileResponse; +use Magento\PageCache\Model\App\Response\HttpPlugin; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; - // @codingStandardsIgnoreEnd +/** + * Tests \Magento\PageCache\Model\App\Response\HttpPlugin. + */ +class HttpPluginTest extends TestCase +{ + /** + * @var HttpPlugin + */ + private $httpPlugin; - class HttpPluginTest extends \PHPUnit\Framework\TestCase + /** + * @inheritdoc + */ + protected function setUp() { - /** - * @inheritdoc - */ - protected function setUp() - { - global $mockPHPFunctions; - $mockPHPFunctions = true; - } + parent::setUp(); + $this->httpPlugin = new HttpPlugin(); + } - /** - * @inheritdoc - */ - protected function tearDown() - { - global $mockPHPFunctions; - $mockPHPFunctions = false; - } + /** + * @param string $responseClass + * @param bool $headersSent + * @param int $sendVaryCalled + * @return void + * + * @dataProvider beforeSendResponseDataProvider + */ + public function testBeforeSendResponse(string $responseClass, bool $headersSent, int $sendVaryCalled): void + { + /** @var HttpResponse|MockObject $responseMock */ + $responseMock = $this->createMock($responseClass); + $responseMock->expects($this->any())->method('headersSent')->willReturn($headersSent); + $responseMock->expects($this->exactly($sendVaryCalled))->method('sendVary'); - /** - * @param string $responseInstanceClass - * @param int $sendVaryCalled - * @return void - * - * @dataProvider beforeSendResponseDataProvider - */ - public function testBeforeSendResponse(string $responseInstanceClass, int $sendVaryCalled): void - { - /** @var Http | \PHPUnit_Framework_MockObject_MockObject $responseMock */ - $responseMock = $this->createMock($responseInstanceClass); - $responseMock->expects($this->exactly($sendVaryCalled)) - ->method('sendVary'); - $plugin = new HttpPlugin(); - $plugin->beforeSendResponse($responseMock); - } + $this->httpPlugin->beforeSendResponse($responseMock); + } - /** - * @return array - */ - public function beforeSendResponseDataProvider(): array - { - return [ - [Http::class, 1], - [Response::class, 0] - ]; - } + /** + * @return array + */ + public function beforeSendResponseDataProvider(): array + { + return [ + 'http_response_headers_not_sent' => [HttpResponse::class, false, 1], + 'http_response_headers_sent' => [HttpResponse::class, true, 0], + 'file_response_headers_not_sent' => [FileResponse::class, false, 0], + 'file_response_headers_sent' => [FileResponse::class, true, 0], + ]; } } diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt index 5066040e484cb..f54defbd57604 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpstan/blacklist/common.txt @@ -14,4 +14,3 @@ dev/tests/api-functional/testsuite/Magento/Customer/Api/AddressRepositoryTest.ph dev/tests/api-functional/testsuite/Magento/Framework/Model/Entity/HydratorTest.php dev/tests/api-functional/testsuite/Magento/Integration/Model/AdminTokenServiceTest.php dev/tests/api-functional/testsuite/Magento/Integration/Model/CustomerTokenServiceTest.php -app/code/Magento/PageCache/Test/Unit/Model/App/Response/HttpPluginTest.php From 262280d869aaf63005aff6074b0ff9c932fe8555 Mon Sep 17 00:00:00 2001 From: Krissy Hiserote Date: Mon, 10 Feb 2020 08:42:19 -0600 Subject: [PATCH 11/11] MC-30236: Upgrade from 2.3.x CE with SD to 2.3.x EE AreaCode Exception - fix unit test --- setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php | 6 +++--- 1 file changed, 3 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 d087162f9b06e..2b992c30615c2 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -309,7 +309,7 @@ public function testInstall(array $request, array $logMessages) $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([]); + $cacheManager->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]); $appState = $this->getMockBuilder(\Magento\Framework\App\State::class) ->disableOriginalConstructor() ->disableArgumentCloning() @@ -412,7 +412,7 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [print_r([], true)], + [print_r(['foo' => 1, 'bar' => 1], true)], ['Installing data...'], ['Data install/update:'], ['Disabling caches:'], @@ -463,7 +463,7 @@ public function installDataProvider() ['Installing user configuration...'], ['Enabling caches:'], ['Current status:'], - [print_r([], true)], + [print_r(['foo' => 1, 'bar' => 1], true)], ['Installing data...'], ['Data install/update:'], ['Disabling caches:'],