Skip to content

Commit 95843d3

Browse files
committed
CE-32868: Fixed tests
1 parent 8e6aedc commit 95843d3

File tree

4 files changed

+51
-48
lines changed

4 files changed

+51
-48
lines changed

dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\TestFramework\ErrorLog;
79

10+
use Magento\Framework\Logger\Monolog;
811
use Monolog\Handler\HandlerInterface;
912

10-
class Logger extends \Magento\Framework\Logger\Monolog
13+
class Logger extends Monolog
1114
{
1215
/**
1316
* @var array
@@ -16,49 +19,58 @@ class Logger extends \Magento\Framework\Logger\Monolog
1619

1720
/**
1821
* Minimum error level to log message
19-
* Possible values: -1 ignore all errors, and level constants form http://tools.ietf.org/html/rfc5424 standard
22+
* Possible values: -1 ignore all errors,
23+
* and level constants form http://tools.ietf.org/html/rfc5424 standard
2024
*
2125
* @var int
2226
*/
2327
protected $minimumErrorLevel;
2428

2529
/**
26-
* @param string $name The logging channel
27-
* @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc
28-
* @param callable[] $processors Optional array of processors
30+
* @param string $name The logging channel
31+
* @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc
32+
* @param callable[] $processors Optional array of processors
2933
*/
30-
public function __construct($name, array $handlers = [], array $processors = [])
31-
{
32-
$this->minimumErrorLevel = defined('TESTS_ERROR_LOG_LISTENER_LEVEL') ? TESTS_ERROR_LOG_LISTENER_LEVEL : -1;
34+
public function __construct(
35+
string $name,
36+
array $handlers = [],
37+
array $processors = []
38+
) {
39+
$this->minimumErrorLevel = defined('TESTS_ERROR_LOG_LISTENER_LEVEL')
40+
? TESTS_ERROR_LOG_LISTENER_LEVEL
41+
: -1;
3342
parent::__construct($name, $handlers, $processors);
3443
}
3544

3645
/**
3746
* @return void
3847
*/
39-
public function clearMessages()
48+
public function clearMessages(): void
4049
{
4150
$this->messages = [];
4251
}
4352

4453
/**
4554
* @return array
4655
*/
47-
public function getMessages()
56+
public function getMessages(): array
4857
{
4958
return $this->messages;
5059
}
5160

5261
/**
53-
* @{inheritDoc}
62+
* @inheritdoc
5463
*
55-
* @param integer $level The logging level
56-
* @param string $message The log message
57-
* @param array $context The log context
58-
* @return Boolean Whether the record has been processed
64+
* @param int $level The logging level
65+
* @param string $message The log message
66+
* @param array $context The log context
67+
* @return bool Whether the record has been processed
5968
*/
60-
public function addRecord($level, $message, array $context = [])
61-
{
69+
public function addRecord(
70+
int $level,
71+
string $message,
72+
array $context = []
73+
): bool {
6274
if ($level <= $this->minimumErrorLevel) {
6375
$this->messages[] = [
6476
'level' => $this->getLevelName($level),

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,4 @@ public function testSanitizeParentLevelFolder()
6161
$this->sanitizeMethod->invokeArgs($this->model, ['../../../var/hack/custom.log'])
6262
);
6363
}
64-
65-
public function testSanitizeFileException()
66-
{
67-
$this->expectException('InvalidArgumentException');
68-
$this->expectExceptionMessage('Filename expected to be a string');
69-
$this->sanitizeMethod->invokeArgs($this->model, [['filename' => 'notValid']]);
70-
}
7164
}

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
namespace Magento\Framework\Logger\Test\Unit\Handler;
99

10+
use DateTime;
11+
use Exception;
1012
use Magento\Framework\Filesystem\DriverInterface;
11-
use Magento\Framework\Logger\Handler\Exception;
13+
use Magento\Framework\Logger\Handler\Exception as ExceptionHandler;
1214
use Magento\Framework\Logger\Handler\System;
1315
use Monolog\Logger;
1416
use PHPUnit\Framework\MockObject\MockObject as Mock;
@@ -27,20 +29,22 @@ class SystemTest extends TestCase
2729
private $filesystemMock;
2830

2931
/**
30-
* @var Exception|Mock
32+
* @var ExceptionHandler|Mock
3133
*/
3234
private $exceptionHandlerMock;
3335

3436
/**
3537
* @inheritdoc
38+
*
39+
* @throws Exception
3640
*/
3741
protected function setUp(): void
3842
{
3943
$this->filesystemMock = $this->getMockBuilder(DriverInterface::class)
4044
->getMockForAbstractClass();
41-
$this->exceptionHandlerMock = $this->getMockBuilder(Exception::class)
42-
->disableOriginalConstructor()
43-
->getMock();
45+
$this->exceptionHandlerMock = $this->getMockBuilder(
46+
ExceptionHandler::class
47+
)->disableOriginalConstructor()->getMock();
4448

4549
$this->model = new System(
4650
$this->filesystemMock,
@@ -62,7 +66,7 @@ public function testWrite()
6266
public function testWriteException()
6367
{
6468
$record = $this->getRecord();
65-
$record['context']['exception'] = new \Exception('Some exception');
69+
$record['context']['exception'] = new Exception('Some exception');
6670

6771
$this->exceptionHandlerMock->expects($this->once())
6872
->method('handle')
@@ -79,15 +83,21 @@ public function testWriteException()
7983
* @param array $context
8084
* @return array
8185
*/
82-
private function getRecord($level = Logger::WARNING, $message = 'test', $context = [])
83-
{
86+
private function getRecord(
87+
int $level = Logger::WARNING,
88+
string $message = 'test',
89+
array $context = []
90+
): array {
8491
return [
8592
'message' => $message,
8693
'context' => $context,
8794
'level' => $level,
8895
'level_name' => Logger::getLevelName($level),
8996
'channel' => 'test',
90-
'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true))),
97+
'datetime' => DateTime::createFromFormat(
98+
'U.u',
99+
sprintf('%.6F', microtime(true))
100+
),
91101
'extra' => [],
92102
];
93103
}

lib/internal/Magento/Framework/Logger/Test/Unit/MonologTest.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
namespace Magento\Framework\Logger\Test\Unit;
99

10+
use Exception;
1011
use Magento\Framework\Logger\Monolog;
1112
use Monolog\Handler\TestHandler;
13+
use Monolog\Logger;
1214
use PHPUnit\Framework\TestCase;
1315

1416
class MonologTest extends TestCase
@@ -20,23 +22,9 @@ public function testAddRecord()
2022

2123
$logger->pushHandler($handler);
2224

23-
$logger->addError('test');
25+
$logger->addRecord(Logger::ERROR, 'test');
2426
list($record) = $handler->getRecords();
2527

2628
$this->assertSame('test', $record['message']);
2729
}
28-
29-
public function testAddRecordAsException()
30-
{
31-
$logger = new Monolog(__METHOD__);
32-
$handler = new TestHandler();
33-
34-
$logger->pushHandler($handler);
35-
36-
$logger->addError(new \Exception('Some exception'));
37-
list($record) = $handler->getRecords();
38-
39-
$this->assertInstanceOf(\Exception::class, $record['context']['exception']);
40-
$this->assertSame('Some exception', $record['message']);
41-
}
4230
}

0 commit comments

Comments
 (0)