Skip to content

Commit

Permalink
[EngCom] Public Pull Requests - 2.3-develop
Browse files Browse the repository at this point in the history
 - merged latest code from mainline branch
  • Loading branch information
magento-engcom-team authored Apr 23, 2019
2 parents d76bf56 + 1d1c2ea commit 62c86e4
Show file tree
Hide file tree
Showing 22 changed files with 243 additions and 445 deletions.
19 changes: 18 additions & 1 deletion app/code/Magento/Config/Model/Config/Backend/Serialized.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Framework\Serialize\Serializer\Json;

/**
* Serialized backend model
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -46,17 +48,32 @@ public function __construct(
}

/**
* Processing object after load data
*
* @return void
*/
protected function _afterLoad()
{
$value = $this->getValue();
if (!is_array($value)) {
$this->setValue(empty($value) ? false : $this->serializer->unserialize($value));
try {
$this->setValue(empty($value) ? false : $this->serializer->unserialize($value));
} catch (\Exception $e) {
$this->_logger->critical(
sprintf(
'Failed to unserialize %s config value. The error is: %s',
$this->getPath(),
$e->getMessage()
)
);
$this->setValue(false);
}
}
}

/**
* Processing object before save data
*
* @return $this
*/
public function beforeSave()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
use Magento\Framework\Model\Context;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Psr\Log\LoggerInterface;

/**
* Class SerializedTest
*/
class SerializedTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Config\Model\Config\Backend\Serialized */
Expand All @@ -18,14 +22,20 @@ class SerializedTest extends \PHPUnit\Framework\TestCase
/** @var Json|\PHPUnit_Framework_MockObject_MockObject */
private $serializerMock;

/** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */
private $loggerMock;

protected function setUp()
{
$objectManager = new ObjectManager($this);
$this->serializerMock = $this->createMock(Json::class);
$this->loggerMock = $this->createMock(LoggerInterface::class);
$contextMock = $this->createMock(Context::class);
$eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
$contextMock->method('getEventDispatcher')
->willReturn($eventManagerMock);
$contextMock->method('getLogger')
->willReturn($this->loggerMock);
$this->serializedConfig = $objectManager->getObject(
Serialized::class,
[
Expand Down Expand Up @@ -72,6 +82,20 @@ public function afterLoadDataProvider()
];
}

public function testAfterLoadWithException()
{
$value = '{"key":';
$expected = false;
$this->serializedConfig->setValue($value);
$this->serializerMock->expects($this->once())
->method('unserialize')
->willThrowException(new \Exception());
$this->loggerMock->expects($this->once())
->method('critical');
$this->serializedConfig->afterLoad();
$this->assertEquals($expected, $this->serializedConfig->getValue());
}

/**
* @param string $expected
* @param int|double|string|array|boolean|null $value
Expand Down
41 changes: 11 additions & 30 deletions dev/tests/functional/lib/Magento/Mtf/Util/Command/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use Magento\Mtf\Util\Protocol\CurlInterface;
use Magento\Mtf\Util\Protocol\CurlTransport;
use Magento\Mtf\Util\Protocol\CurlTransport\WebapiDecorator;

/**
* Perform bin/magento commands from command line for functional tests executions.
Expand All @@ -18,7 +17,7 @@ class Cli
/**
* Url to command.php.
*/
const URL = '/dev/tests/functional/utils/command.php';
const URL = 'dev/tests/functional/utils/command.php';

/**
* Curl transport protocol.
Expand All @@ -27,21 +26,12 @@ class Cli
*/
private $transport;

/**
* Webapi handler.
*
* @var WebapiDecorator
*/
private $webapiHandler;

/**
* @param CurlTransport $transport
* @param WebapiDecorator $webapiHandler
*/
public function __construct(CurlTransport $transport, WebapiDecorator $webapiHandler)
public function __construct(CurlTransport $transport)
{
$this->transport = $transport;
$this->webapiHandler = $webapiHandler;
}

/**
Expand All @@ -53,31 +43,22 @@ public function __construct(CurlTransport $transport, WebapiDecorator $webapiHan
*/
public function execute($command, $options = [])
{
$this->transport->write(
rtrim(str_replace('index.php', '', $_ENV['app_frontend_url']), '/') . self::URL,
$this->prepareParamArray($command, $options),
CurlInterface::POST,
[]
);
$this->transport->read();
$this->transport->close();
$curl = $this->transport;
$curl->write($this->prepareUrl($command, $options), [], CurlInterface::GET);
$curl->read();
$curl->close();
}

/**
* Prepare parameter array.
* Prepare url.
*
* @param string $command
* @param array $options [optional]
* @return array
* @return string
*/
private function prepareParamArray($command, $options = [])
private function prepareUrl($command, $options = [])
{
if (!empty($options)) {
$command .= ' ' . implode(' ', $options);
}
return [
'token' => urlencode($this->webapiHandler->getWebapiToken()),
'command' => urlencode($command)
];
$command .= ' ' . implode(' ', $options);
return $_ENV['app_frontend_url'] . self::URL . '?command=' . urlencode($command);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Mtf\Util\Command\File\Export;

use Magento\Mtf\ObjectManagerInterface;
use Magento\Mtf\Util\Protocol\CurlTransport;
use Magento\Mtf\Util\Protocol\CurlInterface;
use Magento\Mtf\Util\Protocol\CurlTransport\WebapiDecorator;

/**
* File reader for Magento export files.
Expand Down Expand Up @@ -36,29 +36,16 @@ class Reader implements ReaderInterface
*/
private $transport;

/**
* Webapi handler.
*
* @var WebapiDecorator
*/
private $webapiHandler;

/**
* @param ObjectManagerInterface $objectManager
* @param CurlTransport $transport
* @param WebapiDecorator $webapiHandler
* @param string $template
*/
public function __construct(
ObjectManagerInterface $objectManager,
CurlTransport $transport,
WebapiDecorator $webapiHandler,
$template
) {
public function __construct(ObjectManagerInterface $objectManager, CurlTransport $transport, $template)
{
$this->objectManager = $objectManager;
$this->template = $template;
$this->transport = $transport;
$this->webapiHandler = $webapiHandler;
}

/**
Expand All @@ -83,27 +70,20 @@ public function getData()
*/
private function getFiles()
{
$this->transport->write(
rtrim(str_replace('index.php', '', $_ENV['app_frontend_url']), '/') . self::URL,
$this->prepareParamArray(),
CurlInterface::POST,
[]
);
$this->transport->write($this->prepareUrl(), [], CurlInterface::GET);
$serializedFiles = $this->transport->read();
$this->transport->close();
return unserialize($serializedFiles);
// phpcs:ignore Magento2.Security.InsecureFunction
return unserialize($serializedFiles, ['allowed_classes' => false]);
}

/**
* Prepare parameter array.
* Prepare url.
*
* @return array
* @return string
*/
private function prepareParamArray()
private function prepareUrl()
{
return [
'token' => urlencode($this->webapiHandler->getWebapiToken()),
'template' => urlencode($this->template)
];
return $_ENV['app_frontend_url'] . self::URL . '?template=' . urlencode($this->template);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface ReaderInterface
/**
* Url to export.php.
*/
const URL = '/dev/tests/functional/utils/export.php';
const URL = 'dev/tests/functional/utils/export.php';

/**
* Exporting files as Data object from Magento.
Expand Down
38 changes: 11 additions & 27 deletions dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace Magento\Mtf\Util\Command\File;

use Magento\Mtf\Util\Protocol\CurlTransport;
use Magento\Mtf\Util\Protocol\CurlTransport\WebapiDecorator;

/**
* Get content of log file in var/log folder.
Expand All @@ -17,7 +16,7 @@ class Log
/**
* Url to log.php.
*/
const URL = '/dev/tests/functional/utils/log.php';
const URL = 'dev/tests/functional/utils/log.php';

/**
* Curl transport protocol.
Expand All @@ -26,21 +25,12 @@ class Log
*/
private $transport;

/**
* Webapi handler.
*
* @var WebapiDecorator
*/
private $webapiHandler;

/**
* @param CurlTransport $transport
* @param WebapiDecorator $webapiHandler
*/
public function __construct(CurlTransport $transport, WebapiDecorator $webapiHandler)
public function __construct(CurlTransport $transport)
{
$this->transport = $transport;
$this->webapiHandler = $webapiHandler;
}

/**
Expand All @@ -51,28 +41,22 @@ public function __construct(CurlTransport $transport, WebapiDecorator $webapiHan
*/
public function getFileContent($name)
{
$this->transport->write(
rtrim(str_replace('index.php', '', $_ENV['app_frontend_url']), '/') . self::URL,
$this->prepareParamArray($name),
CurlInterface::POST,
[]
);
$data = $this->transport->read();
$this->transport->close();
$curl = $this->transport;
$curl->write($this->prepareUrl($name), [], CurlTransport::GET);
$data = $curl->read();
$curl->close();
// phpcs:ignore Magento2.Security.InsecureFunction
return unserialize($data);
}

/**
* Prepare parameter array.
* Prepare url.
*
* @param string $name
* @return array
* @return string
*/
private function prepareParamArray($name)
private function prepareUrl($name)
{
return [
'token' => urlencode($this->webapiHandler->getWebapiToken()),
'name' => urlencode($name)
];
return $_ENV['app_frontend_url'] . self::URL . '?name=' . urlencode($name);
}
}
Loading

0 comments on commit 62c86e4

Please sign in to comment.