Skip to content

Commit 62c86e4

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents d76bf56 + 1d1c2ea commit 62c86e4

File tree

22 files changed

+243
-445
lines changed

22 files changed

+243
-445
lines changed

app/code/Magento/Config/Model/Config/Backend/Serialized.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\Serialize\Serializer\Json;
1010

1111
/**
12+
* Serialized backend model
13+
*
1214
* @api
1315
* @since 100.0.2
1416
*/
@@ -46,17 +48,32 @@ public function __construct(
4648
}
4749

4850
/**
51+
* Processing object after load data
52+
*
4953
* @return void
5054
*/
5155
protected function _afterLoad()
5256
{
5357
$value = $this->getValue();
5458
if (!is_array($value)) {
55-
$this->setValue(empty($value) ? false : $this->serializer->unserialize($value));
59+
try {
60+
$this->setValue(empty($value) ? false : $this->serializer->unserialize($value));
61+
} catch (\Exception $e) {
62+
$this->_logger->critical(
63+
sprintf(
64+
'Failed to unserialize %s config value. The error is: %s',
65+
$this->getPath(),
66+
$e->getMessage()
67+
)
68+
);
69+
$this->setValue(false);
70+
}
5671
}
5772
}
5873

5974
/**
75+
* Processing object before save data
76+
*
6077
* @return $this
6178
*/
6279
public function beforeSave()

app/code/Magento/Config/Test/Unit/Model/Config/Backend/SerializedTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
use Magento\Framework\Model\Context;
1010
use Magento\Framework\Serialize\Serializer\Json;
1111
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Psr\Log\LoggerInterface;
1213

14+
/**
15+
* Class SerializedTest
16+
*/
1317
class SerializedTest extends \PHPUnit\Framework\TestCase
1418
{
1519
/** @var \Magento\Config\Model\Config\Backend\Serialized */
@@ -18,14 +22,20 @@ class SerializedTest extends \PHPUnit\Framework\TestCase
1822
/** @var Json|\PHPUnit_Framework_MockObject_MockObject */
1923
private $serializerMock;
2024

25+
/** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */
26+
private $loggerMock;
27+
2128
protected function setUp()
2229
{
2330
$objectManager = new ObjectManager($this);
2431
$this->serializerMock = $this->createMock(Json::class);
32+
$this->loggerMock = $this->createMock(LoggerInterface::class);
2533
$contextMock = $this->createMock(Context::class);
2634
$eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
2735
$contextMock->method('getEventDispatcher')
2836
->willReturn($eventManagerMock);
37+
$contextMock->method('getLogger')
38+
->willReturn($this->loggerMock);
2939
$this->serializedConfig = $objectManager->getObject(
3040
Serialized::class,
3141
[
@@ -72,6 +82,20 @@ public function afterLoadDataProvider()
7282
];
7383
}
7484

85+
public function testAfterLoadWithException()
86+
{
87+
$value = '{"key":';
88+
$expected = false;
89+
$this->serializedConfig->setValue($value);
90+
$this->serializerMock->expects($this->once())
91+
->method('unserialize')
92+
->willThrowException(new \Exception());
93+
$this->loggerMock->expects($this->once())
94+
->method('critical');
95+
$this->serializedConfig->afterLoad();
96+
$this->assertEquals($expected, $this->serializedConfig->getValue());
97+
}
98+
7599
/**
76100
* @param string $expected
77101
* @param int|double|string|array|boolean|null $value

dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli.php

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use Magento\Mtf\Util\Protocol\CurlInterface;
1010
use Magento\Mtf\Util\Protocol\CurlTransport;
11-
use Magento\Mtf\Util\Protocol\CurlTransport\WebapiDecorator;
1211

1312
/**
1413
* Perform bin/magento commands from command line for functional tests executions.
@@ -18,7 +17,7 @@ class Cli
1817
/**
1918
* Url to command.php.
2019
*/
21-
const URL = '/dev/tests/functional/utils/command.php';
20+
const URL = 'dev/tests/functional/utils/command.php';
2221

2322
/**
2423
* Curl transport protocol.
@@ -27,21 +26,12 @@ class Cli
2726
*/
2827
private $transport;
2928

30-
/**
31-
* Webapi handler.
32-
*
33-
* @var WebapiDecorator
34-
*/
35-
private $webapiHandler;
36-
3729
/**
3830
* @param CurlTransport $transport
39-
* @param WebapiDecorator $webapiHandler
4031
*/
41-
public function __construct(CurlTransport $transport, WebapiDecorator $webapiHandler)
32+
public function __construct(CurlTransport $transport)
4233
{
4334
$this->transport = $transport;
44-
$this->webapiHandler = $webapiHandler;
4535
}
4636

4737
/**
@@ -53,31 +43,22 @@ public function __construct(CurlTransport $transport, WebapiDecorator $webapiHan
5343
*/
5444
public function execute($command, $options = [])
5545
{
56-
$this->transport->write(
57-
rtrim(str_replace('index.php', '', $_ENV['app_frontend_url']), '/') . self::URL,
58-
$this->prepareParamArray($command, $options),
59-
CurlInterface::POST,
60-
[]
61-
);
62-
$this->transport->read();
63-
$this->transport->close();
46+
$curl = $this->transport;
47+
$curl->write($this->prepareUrl($command, $options), [], CurlInterface::GET);
48+
$curl->read();
49+
$curl->close();
6450
}
6551

6652
/**
67-
* Prepare parameter array.
53+
* Prepare url.
6854
*
6955
* @param string $command
7056
* @param array $options [optional]
71-
* @return array
57+
* @return string
7258
*/
73-
private function prepareParamArray($command, $options = [])
59+
private function prepareUrl($command, $options = [])
7460
{
75-
if (!empty($options)) {
76-
$command .= ' ' . implode(' ', $options);
77-
}
78-
return [
79-
'token' => urlencode($this->webapiHandler->getWebapiToken()),
80-
'command' => urlencode($command)
81-
];
61+
$command .= ' ' . implode(' ', $options);
62+
return $_ENV['app_frontend_url'] . self::URL . '?command=' . urlencode($command);
8263
}
8364
}

dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export/Reader.php

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Mtf\Util\Command\File\Export;
78

89
use Magento\Mtf\ObjectManagerInterface;
910
use Magento\Mtf\Util\Protocol\CurlTransport;
1011
use Magento\Mtf\Util\Protocol\CurlInterface;
11-
use Magento\Mtf\Util\Protocol\CurlTransport\WebapiDecorator;
1212

1313
/**
1414
* File reader for Magento export files.
@@ -36,29 +36,16 @@ class Reader implements ReaderInterface
3636
*/
3737
private $transport;
3838

39-
/**
40-
* Webapi handler.
41-
*
42-
* @var WebapiDecorator
43-
*/
44-
private $webapiHandler;
45-
4639
/**
4740
* @param ObjectManagerInterface $objectManager
4841
* @param CurlTransport $transport
49-
* @param WebapiDecorator $webapiHandler
5042
* @param string $template
5143
*/
52-
public function __construct(
53-
ObjectManagerInterface $objectManager,
54-
CurlTransport $transport,
55-
WebapiDecorator $webapiHandler,
56-
$template
57-
) {
44+
public function __construct(ObjectManagerInterface $objectManager, CurlTransport $transport, $template)
45+
{
5846
$this->objectManager = $objectManager;
5947
$this->template = $template;
6048
$this->transport = $transport;
61-
$this->webapiHandler = $webapiHandler;
6249
}
6350

6451
/**
@@ -83,27 +70,20 @@ public function getData()
8370
*/
8471
private function getFiles()
8572
{
86-
$this->transport->write(
87-
rtrim(str_replace('index.php', '', $_ENV['app_frontend_url']), '/') . self::URL,
88-
$this->prepareParamArray(),
89-
CurlInterface::POST,
90-
[]
91-
);
73+
$this->transport->write($this->prepareUrl(), [], CurlInterface::GET);
9274
$serializedFiles = $this->transport->read();
9375
$this->transport->close();
94-
return unserialize($serializedFiles);
76+
// phpcs:ignore Magento2.Security.InsecureFunction
77+
return unserialize($serializedFiles, ['allowed_classes' => false]);
9578
}
9679

9780
/**
98-
* Prepare parameter array.
81+
* Prepare url.
9982
*
100-
* @return array
83+
* @return string
10184
*/
102-
private function prepareParamArray()
85+
private function prepareUrl()
10386
{
104-
return [
105-
'token' => urlencode($this->webapiHandler->getWebapiToken()),
106-
'template' => urlencode($this->template)
107-
];
87+
return $_ENV['app_frontend_url'] . self::URL . '?template=' . urlencode($this->template);
10888
}
10989
}

dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export/ReaderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface ReaderInterface
1414
/**
1515
* Url to export.php.
1616
*/
17-
const URL = '/dev/tests/functional/utils/export.php';
17+
const URL = 'dev/tests/functional/utils/export.php';
1818

1919
/**
2020
* Exporting files as Data object from Magento.

dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Log.php

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\Mtf\Util\Command\File;
88

99
use Magento\Mtf\Util\Protocol\CurlTransport;
10-
use Magento\Mtf\Util\Protocol\CurlTransport\WebapiDecorator;
1110

1211
/**
1312
* Get content of log file in var/log folder.
@@ -17,7 +16,7 @@ class Log
1716
/**
1817
* Url to log.php.
1918
*/
20-
const URL = '/dev/tests/functional/utils/log.php';
19+
const URL = 'dev/tests/functional/utils/log.php';
2120

2221
/**
2322
* Curl transport protocol.
@@ -26,21 +25,12 @@ class Log
2625
*/
2726
private $transport;
2827

29-
/**
30-
* Webapi handler.
31-
*
32-
* @var WebapiDecorator
33-
*/
34-
private $webapiHandler;
35-
3628
/**
3729
* @param CurlTransport $transport
38-
* @param WebapiDecorator $webapiHandler
3930
*/
40-
public function __construct(CurlTransport $transport, WebapiDecorator $webapiHandler)
31+
public function __construct(CurlTransport $transport)
4132
{
4233
$this->transport = $transport;
43-
$this->webapiHandler = $webapiHandler;
4434
}
4535

4636
/**
@@ -51,28 +41,22 @@ public function __construct(CurlTransport $transport, WebapiDecorator $webapiHan
5141
*/
5242
public function getFileContent($name)
5343
{
54-
$this->transport->write(
55-
rtrim(str_replace('index.php', '', $_ENV['app_frontend_url']), '/') . self::URL,
56-
$this->prepareParamArray($name),
57-
CurlInterface::POST,
58-
[]
59-
);
60-
$data = $this->transport->read();
61-
$this->transport->close();
44+
$curl = $this->transport;
45+
$curl->write($this->prepareUrl($name), [], CurlTransport::GET);
46+
$data = $curl->read();
47+
$curl->close();
48+
// phpcs:ignore Magento2.Security.InsecureFunction
6249
return unserialize($data);
6350
}
6451

6552
/**
66-
* Prepare parameter array.
53+
* Prepare url.
6754
*
6855
* @param string $name
69-
* @return array
56+
* @return string
7057
*/
71-
private function prepareParamArray($name)
58+
private function prepareUrl($name)
7259
{
73-
return [
74-
'token' => urlencode($this->webapiHandler->getWebapiToken()),
75-
'name' => urlencode($name)
76-
];
60+
return $_ENV['app_frontend_url'] . self::URL . '?name=' . urlencode($name);
7761
}
7862
}

0 commit comments

Comments
 (0)