Skip to content

Commit 7cd9c31

Browse files
committed
MAGETWO-44174: \Magento\Payment\Model\Method\Logger::debug() fails in case Logger was initiated without config instance
1 parent e4716a3 commit 7cd9c31

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

app/code/Magento/Payment/Model/Method/Logger.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ public function __construct(
4141
/**
4242
* Logs payment related information used for debug
4343
*
44-
* @param array $debugData
45-
* @param array|null $debugReplaceKeys
46-
* @param bool|null $debugFlag
44+
* @param array $data
45+
* @param array|null $maskKeys
46+
* @param bool|null $forceDebug
4747
* @return void
4848
*/
49-
public function debug(array $debugData, array $debugReplaceKeys = null, $debugFlag = null)
49+
public function debug(array $data, array $maskKeys = null, $forceDebug = null)
5050
{
51-
$debugReplaceKeys = $debugReplaceKeys !== null ? $debugReplaceKeys : $this->getDebugReplaceFields();
52-
$debugFlag = $debugFlag !== null ? $debugFlag : $this->isDebugOn();
53-
if ($debugFlag === true && !empty($debugData) && !empty($debugReplaceKeys)) {
54-
$debugData = $this->filterDebugData(
55-
$debugData,
56-
$debugReplaceKeys
51+
$maskKeys = $maskKeys !== null ? $maskKeys : $this->getDebugReplaceFields();
52+
$debugOn = $forceDebug !== null ? $forceDebug : $this->isDebugOn();
53+
if ($debugOn === true) {
54+
$data = $this->filterDebugData(
55+
$data,
56+
$maskKeys
5757
);
58-
$this->logger->debug(var_export($debugData, true));
58+
$this->logger->debug(var_export($data, true));
5959
}
6060
}
6161

@@ -66,7 +66,7 @@ public function debug(array $debugData, array $debugReplaceKeys = null, $debugFl
6666
*/
6767
private function getDebugReplaceFields()
6868
{
69-
if ($this->config->getValue('debugReplaceKeys')) {
69+
if ($this->config and $this->config->getValue('debugReplaceKeys')) {
7070
return explode(',', $this->config->getValue('debugReplaceKeys'));
7171
}
7272
return [];
@@ -79,7 +79,7 @@ private function getDebugReplaceFields()
7979
*/
8080
private function isDebugOn()
8181
{
82-
return (bool)$this->config->getValue('debug');
82+
return $this->config and (bool)$this->config->getValue('debug');
8383
}
8484

8585
/**

app/code/Magento/Payment/Test/Unit/Model/Method/LoggerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ public function testDebugOn()
4545
$this->logger->debug($debugData, $debugReplaceKeys, true);
4646
}
4747

48+
public function testDebugOnNoReplaceKeys()
49+
{
50+
$debugData =
51+
[
52+
'request' => ['data1' => '123', 'data2' => '123']
53+
];
54+
55+
$this->loggerMock->expects(static::once())
56+
->method('debug')
57+
->with(var_export($debugData, true));
58+
59+
$this->logger->debug($debugData, [], true);
60+
}
61+
4862
public function testDebugOff()
4963
{
5064
$debugData =

0 commit comments

Comments
 (0)