Skip to content

Commit d19ae3a

Browse files
committed
Add test logger
1 parent 4aeedc2 commit d19ae3a

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

tests/dcg/GeneratorFactoryTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use DrupalCodeGenerator\ClassResolver\SimpleClassResolver;
77
use DrupalCodeGenerator\GeneratorFactory;
88
use PHPUnit\Framework\TestCase;
9-
use Psr\Log\Test\TestLogger;
109

1110
/**
1211
* Test for GeneratorsDiscovery.
@@ -32,7 +31,12 @@ public function testGetGenerators(): void {
3231
}
3332
self::assertCount(self::TOTAL_GENERATORS, $generators);
3433

35-
self::assertTrue($logger->hasDebugThatMatches('/^Total generators: {total}/'));
34+
$log_records[] = [
35+
'level' => 'debug',
36+
'message' => 'Total generators: {total}',
37+
'context' => ['total' => 15],
38+
];
39+
self::assertSame($log_records, $logger->records);
3640
}
3741

3842
}

tests/dcg/TestLogger.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace DrupalCodeGenerator\Tests;
4+
5+
use Psr\Log\AbstractLogger;
6+
7+
/**
8+
* Test logger.
9+
*/
10+
final class TestLogger extends AbstractLogger {
11+
12+
public array $records = [];
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
public function log($level, $message, array $context = []) {
18+
$this->records[] = [
19+
'level' => $level,
20+
'message' => $message,
21+
'context' => $context,
22+
];
23+
}
24+
25+
}

0 commit comments

Comments
 (0)