Skip to content

Commit c901290

Browse files
committed
AC-12022::Upgrade monolog/monolog system dependency to the latest major version
1 parent 114fb65 commit c901290

File tree

3 files changed

+80
-58
lines changed

3 files changed

+80
-58
lines changed

app/code/Magento/Developer/Test/Unit/Model/Logger/Handler/DebugTest.php

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
*/
66
namespace Magento\Developer\Test\Unit\Model\Logger\Handler;
77

8+
use Magento\Config\Setup\ConfigOptionsList;
89
use Magento\Developer\Model\Logger\Handler\Debug;
910
use Magento\Framework\App\Config\ScopeConfigInterface;
1011
use Magento\Framework\App\DeploymentConfig;
1112
use Magento\Framework\App\State;
1213
use Magento\Framework\Filesystem\DriverInterface;
1314
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1415
use Monolog\Formatter\FormatterInterface;
16+
use Monolog\Level;
1517
use Monolog\Logger;
18+
use Monolog\LogRecord;
1619
use PHPUnit\Framework\MockObject\MockObject;
1720
use PHPUnit\Framework\TestCase;
1821

@@ -51,6 +54,11 @@ class DebugTest extends TestCase
5154
*/
5255
private $deploymentConfigMock;
5356

57+
/**
58+
* @var LogRecord
59+
*/
60+
private $logRecord;
61+
5462
/**
5563
* @inheritdoc
5664
*/
@@ -81,6 +89,16 @@ protected function setUp(): void
8189
'deploymentConfig' => $this->deploymentConfigMock
8290
]);
8391
$this->model->setFormatter($this->formatterMock);
92+
93+
$this->logRecord = new LogRecord(
94+
new \DateTimeImmutable(),
95+
'testChannel',
96+
Level::Debug,
97+
'testMessage',
98+
$context = [],
99+
$extra = [],
100+
$formatted = false
101+
);
84102
}
85103

86104
/**
@@ -99,7 +117,7 @@ public function testHandleEnabledInDeveloperMode()
99117
->expects($this->never())
100118
->method('getValue');
101119

102-
$this->assertTrue($this->model->isHandling(['formatted' => false, 'level' => Logger::DEBUG]));
120+
$this->assertTrue($this->model->isHandling($this->logRecord));
103121
}
104122

105123
/**
@@ -118,7 +136,7 @@ public function testHandleEnabledInDefaultMode()
118136
->expects($this->never())
119137
->method('getValue');
120138

121-
$this->assertTrue($this->model->isHandling(['formatted' => false, 'level' => Logger::DEBUG]));
139+
$this->assertTrue($this->model->isHandling($this->logRecord));
122140
}
123141

124142
/**
@@ -137,7 +155,7 @@ public function testHandleDisabledByProduction()
137155
->expects($this->never())
138156
->method('getValue');
139157

140-
$this->assertFalse($this->model->isHandling(['formatted' => false, 'level' => Logger::DEBUG]));
158+
$this->assertFalse($this->model->isHandling($this->logRecord));
141159
}
142160

143161
/**
@@ -148,15 +166,22 @@ public function testHandleDisabledByLevel()
148166
$this->deploymentConfigMock->expects($this->once())
149167
->method('isAvailable')
150168
->willReturn(true);
151-
$this->stateMock
152-
->expects($this->never())
153-
->method('getMode')
154-
->willReturn(State::MODE_DEVELOPER);
155-
$this->scopeConfigMock
156-
->expects($this->never())
157-
->method('getValue');
169+
$this->deploymentConfigMock->expects($this->once())
170+
->method('get')
171+
->with(ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING)
172+
->willReturn(false);
158173

159-
$this->assertFalse($this->model->isHandling(['formatted' => false, 'level' => Logger::API]));
174+
$this->assertFalse($this->model->isHandling(
175+
new LogRecord(
176+
new \DateTimeImmutable(),
177+
'testChannel',
178+
Level::Error,
179+
'testMessage',
180+
$context = [],
181+
$extra = [],
182+
$formatted = false
183+
)
184+
));
160185
}
161186

162187
/**
@@ -174,6 +199,6 @@ public function testDeploymentConfigIsNotAvailable()
174199
->expects($this->never())
175200
->method('getValue');
176201

177-
$this->assertTrue($this->model->isHandling(['formatted' => false, 'level' => Logger::DEBUG]));
202+
$this->assertTrue($this->model->isHandling($this->logRecord));
178203
}
179204
}

app/code/Magento/Developer/Test/Unit/Model/Logger/Handler/SyslogTest.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Framework\App\Config\ScopeConfigInterface;
1313
use Magento\Framework\App\DeploymentConfig;
1414
use Magento\Framework\Logger\Monolog;
15+
use Monolog\Handler\AbstractHandler;
16+
use Monolog\Level;
1517
use Monolog\LogRecord;
1618
use PHPUnit\Framework\MockObject\MockObject as Mock;
1719
use PHPUnit\Framework\TestCase;
@@ -37,18 +39,27 @@ class SyslogTest extends TestCase
3739
private $deploymentConfigMock;
3840

3941
/**
40-
* @var LogRecord|Mock
42+
* @var LogRecord
4143
*/
42-
private $logRecordMock;
44+
private $logRecord;
4345

46+
/**
47+
* @var AbstractHandler|Mock
48+
*/
49+
private $abstractHandlerMock;
4450
/**
4551
* @inheritdoc
4652
*/
4753
protected function setUp(): void
4854
{
4955
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
5056
$this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
51-
$this->logRecordMock = $this->createMock(LogRecord::class);
57+
$this->logRecord = new LogRecord(
58+
new \DateTimeImmutable(),
59+
'testChannel',
60+
Level::Debug,
61+
'testMessage'
62+
);
5263

5364
$this->model = new Syslog(
5465
$this->deploymentConfigMock,
@@ -61,10 +72,6 @@ protected function setUp(): void
6172
*/
6273
public function testIsHandling(): void
6374
{
64-
// $record = [
65-
// 'level' => Monolog::DEBUG,
66-
// ];
67-
6875
$this->scopeConfigMock
6976
->expects($this->never())
7077
->method('getValue');
@@ -79,7 +86,7 @@ public function testIsHandling(): void
7986
->willReturn(1);
8087

8188
$this->assertTrue(
82-
$this->model->isHandling($this->logRecordMock)
89+
$this->model->isHandling($this->logRecord)
8390
);
8491
}
8592

@@ -88,10 +95,6 @@ public function testIsHandling(): void
8895
*/
8996
public function testIsHandlingNotInstalled(): void
9097
{
91-
// $record = [
92-
// 'level' => Monolog::DEBUG,
93-
// ];
94-
9598
$this->scopeConfigMock
9699
->expects($this->never())
97100
->method('getValue');
@@ -101,7 +104,7 @@ public function testIsHandlingNotInstalled(): void
101104
->willReturn(false);
102105

103106
$this->assertFalse(
104-
$this->model->isHandling($this->logRecordMock)
107+
$this->model->isHandling($this->logRecord)
105108
);
106109
}
107110

@@ -110,10 +113,6 @@ public function testIsHandlingNotInstalled(): void
110113
*/
111114
public function testIsHandlingDisabled(): void
112115
{
113-
// $record = [
114-
// 'level' => Monolog::DEBUG,
115-
// ];
116-
117116
$this->scopeConfigMock
118117
->expects($this->never())
119118
->method('getValue');
@@ -128,7 +127,7 @@ public function testIsHandlingDisabled(): void
128127
->willReturn(0);
129128

130129
$this->assertFalse(
131-
$this->model->isHandling($this->logRecordMock)
130+
$this->model->isHandling($this->logRecord)
132131
);
133132
}
134133
}

lib/internal/Magento/Framework/Logger/Test/Unit/Handler/SystemTest.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use Magento\Framework\Filesystem\DriverInterface;
1313
use Magento\Framework\Logger\Handler\Exception as ExceptionHandler;
1414
use Magento\Framework\Logger\Handler\System;
15+
use Monolog\Level;
1516
use Monolog\Logger;
17+
use Monolog\LogRecord;
1618
use PHPUnit\Framework\MockObject\MockObject as Mock;
1719
use PHPUnit\Framework\TestCase;
1820

@@ -54,51 +56,47 @@ protected function setUp(): void
5456

5557
public function testWrite()
5658
{
59+
$record = $this->getRecord(Level::Warning, 'Test message', []);
5760
$this->filesystemMock->expects($this->once())
5861
->method('getParentDirectory');
5962
$this->filesystemMock->expects($this->once())
6063
->method('isDirectory')
6164
->willReturn('true');
62-
63-
$this->model->write($this->getRecord());
65+
$this->exceptionHandlerMock->expects($this->never())->method('handle');
66+
$this->model->write($record);
6467
}
6568

6669
public function testWriteException()
6770
{
68-
$record = $this->getRecord();
69-
$record['context']['exception'] = new Exception('Some exception');
70-
71-
$this->exceptionHandlerMock->expects($this->once())
72-
->method('handle')
73-
->with($record);
71+
$exception = new \Exception('Test exception');
72+
$record = $this->getRecord(Level::Error, 'Error message', ['exception' => $exception]);
73+
// Expect the exception handler to be called once with the record
74+
$this->exceptionHandlerMock->expects($this->once())->method('handle')->with($this->equalTo($record));
7475
$this->filesystemMock->expects($this->never())
7576
->method('getParentDirectory');
76-
7777
$this->model->write($record);
7878
}
7979

8080
/**
81-
* @param int $level
81+
* @param Level $level
8282
* @param string $message
83-
* @param array $context
84-
* @return array
83+
* @param array $exception
84+
* @return LogRecord
8585
*/
8686
private function getRecord(
87-
int $level = Logger::WARNING,
88-
string $message = 'test',
89-
array $context = []
90-
): array {
91-
return [
92-
'message' => $message,
93-
'context' => $context,
94-
'level' => $level,
95-
'level_name' => Logger::getLevelName($level),
96-
'channel' => 'test',
97-
'datetime' => DateTime::createFromFormat(
98-
'U.u',
99-
sprintf('%.6F', microtime(true))
100-
),
101-
'extra' => [],
102-
];
87+
Level $level,
88+
string $message,
89+
$exception
90+
): LogRecord {
91+
return new LogRecord(
92+
new \DateTimeImmutable(),
93+
'test',
94+
$level,
95+
$message,
96+
$exception,
97+
[],
98+
[],
99+
$message
100+
);
103101
}
104102
}

0 commit comments

Comments
 (0)