File tree Expand file tree Collapse file tree 4 files changed +120
-61
lines changed Expand file tree Collapse file tree 4 files changed +120
-61
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Algolia \AlgoliaSearch \Test \Unit \Logger \Handler ;
4
+
5
+ use Magento \Framework \Logger \Handler \Base ;
6
+ use PHPUnit \Framework \TestCase ;
7
+
8
+ abstract class AbstractHandlerTest extends TestCase
9
+ {
10
+ protected ?Base $ handler = null ;
11
+
12
+ /**
13
+ * Monolog v3 uses LogRecord
14
+ * v2 uses arrays only
15
+ */
16
+ protected function makeLogRecord (int $ level , string $ message )
17
+ {
18
+ if (class_exists (\Monolog \LogRecord::class)) {
19
+ // Monolog v3
20
+ $ levelEnum = $ this ->convertLevelToEnum ($ level );
21
+ return new \Monolog \LogRecord (
22
+ new \DateTimeImmutable (),
23
+ 'test ' ,
24
+ $ levelEnum ,
25
+ $ message
26
+ );
27
+ }
28
+
29
+ // Monolog v2
30
+ return [
31
+ 'message ' => $ message ,
32
+ 'level ' => $ level
33
+ ];
34
+ }
35
+
36
+ protected function convertLevelToEnum (int $ level ): \Monolog \Level
37
+ {
38
+ if (class_exists (\Monolog \Level::class)) {
39
+ return \Monolog \Level::from ($ level );
40
+ }
41
+
42
+ throw new \RuntimeException ('Monolog v3 Level enum not available ' );
43
+ }
44
+
45
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Algolia \AlgoliaSearch \Test \Unit \Logger \Handler ;
4
+
5
+ use Algolia \AlgoliaSearch \Logger \Handler \AlgoliaLoggerHandler ;
6
+ use Magento \Framework \Filesystem \DriverInterface ;
7
+
8
+ class AlgoliaLoggerHandlerTest extends AbstractHandlerTest
9
+ {
10
+ protected function setUp (): void
11
+ {
12
+ $ this ->handler = new AlgoliaLoggerHandler (
13
+ $ this ->createMock (DriverInterface::class)
14
+ );
15
+ }
16
+
17
+ public function testAlgoliaHandlerLogsEverything (): void
18
+ {
19
+ $ debugRecord = $ this ->makeLogRecord (
20
+ \Monolog \Logger::DEBUG ,
21
+ 'Should log '
22
+ );
23
+
24
+ $ infoRecord = $ this ->makeLogRecord (
25
+ \Monolog \Logger::INFO ,
26
+ 'Should log '
27
+ );
28
+
29
+ $ errorRecord = $ this ->makeLogRecord (
30
+ \Monolog \Logger::ERROR ,
31
+ 'Should log '
32
+ );
33
+
34
+ $ this ->assertTrue ($ this ->handler ->isHandling ($ debugRecord ), 'DEBUG should be handled ' );
35
+ $ this ->assertTrue ($ this ->handler ->isHandling ($ infoRecord ), 'INFO should be handled ' );
36
+ $ this ->assertTrue ($ this ->handler ->isHandling ($ errorRecord ), 'ERROR should be handled ' );
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Algolia \AlgoliaSearch \Test \Unit \Logger \Handler ;
4
+
5
+ use Algolia \AlgoliaSearch \Logger \Handler \SystemLoggerHandler ;
6
+ use Magento \Framework \Filesystem \DriverInterface ;
7
+ use Magento \Framework \Logger \Handler \Exception as ExceptionHandler ;
8
+
9
+ class SystemLoggerHandlerTest extends AbstractHandlerTest
10
+ {
11
+ /**
12
+ * @throws \Exception
13
+ */
14
+ protected function setUp (): void
15
+ {
16
+ $ this ->handler = new SystemLoggerHandler (
17
+ $ this ->createMock (DriverInterface::class),
18
+ $ this ->createMock (ExceptionHandler::class),
19
+ );
20
+ }
21
+
22
+ public function testSystemHandlerFiltersBelowError (): void
23
+ {
24
+ $ infoRecord = $ this ->makeLogRecord (
25
+ \Monolog \Logger::INFO ,
26
+ 'Should not log '
27
+ );
28
+
29
+ $ errorRecord = $ this ->makeLogRecord (
30
+ \Monolog \Logger::ERROR ,
31
+ 'Should log '
32
+ );
33
+
34
+ $ this ->assertFalse ($ this ->handler ->isHandling ($ infoRecord ), 'INFO should be ignored ' );
35
+ $ this ->assertTrue ($ this ->handler ->isHandling ($ errorRecord ), 'ERROR should be handled ' );
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments