Skip to content

Commit 460ca94

Browse files
committed
Fix psalm 5.x issues
1 parent d5de0c8 commit 460ca94

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

tests/BaseTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,21 @@ public function testLogsMessages(): void
3838

3939
public function testAddsContext(): void
4040
{
41-
$this->log->addContext(['some' => 'context']);
42-
$this->log->info('An info.');
41+
$this->log->addContext(['some' => 'context'])->info('An info.');
4342
$this->assertEquals(['some'], $this->log->contextKeysAt(0));
4443

45-
$this->log->addContext(['more' => 'context']);
46-
$this->log->info('I should have two bits of context.');
44+
$this->log
45+
->addContext(['more' => 'context'])
46+
->info('I should have two bits of context.');
4747
$this->assertEquals(2, $this->log->contextCountAt(1));
4848
$this->assertEquals(['some', 'more'], $this->log->contextKeysAt(1));
4949

50-
$this->log->addContext(['even more' => 'context']);
51-
$this->log->warning('This message should get four context elements.', ['foo' => 'bar']);
50+
$this->log
51+
->addContext(['even more' => 'context'])
52+
->warning(
53+
'This message should get four context elements.',
54+
['foo' => 'bar']
55+
);
5256
$this->assertEquals(4, $this->log->contextCountAt(2));
5357

5458
$this->log->debug('Back to three!');

tests/MonologTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ public function testWithnameConvoluted(): void
9292

9393
$first->debug('First now has one record with two context');
9494
$this->assertCount(1, $first->getChannelRecords());
95-
$this->assertCount(2, $first->getChannelRecords()[0]['context']);
96-
95+
$this->assertCount(2, $first->channelRecordAt(0)['context']);
9796
$this->assertEquals(2, $first->contextCountAt(0));
9897
}
9998
}

tests/Support/LaminasStackLogger.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
use Laminas\Log\Logger;
88
use Laminas\Log\PsrLoggerAdapter;
99
use Laminas\Log\Writer\Mock;
10+
use Psr\Log\LoggerInterface;
1011
use TimDev\StackLogger\Psr3StackLogger;
1112

1213
/**
1314
* Implements TestLoggerInterface by wrapping a \Laminas\Log\PsrLoggerAdapter.
1415
* PsrLoggerAdapter decorates \Laminas\Log\Logger to make it PSR3 compatible.
1516
*
1617
* @psalm-import-type LogRecord from TestStackLogger
18+
* @extends Psr3StackLogger<LoggerInterface>
1719
*/
1820
class LaminasStackLogger extends Psr3StackLogger implements TestStackLogger
1921
{

tests/Support/MonologStackLogger.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* TestLoggerInterface implementation that extends WrappedMonolog.
1313
*
14-
* @psalm-type MonologRecord = array{message:string, context:array, channel:string}
14+
* @psalm-type MonologRecord = array{message:string, context:array, channel:string, ...}
1515
*/
1616
class MonologStackLogger extends BaseMonologStackLogger implements TestStackLogger
1717
{
@@ -42,7 +42,7 @@ public function getRecords(): array
4242
* loggers inherit handlers from their parent, but it's useful in some tests
4343
* to inspect log messages written by a particular instance.
4444
*
45-
* @return array<MonologRecord>
45+
* @return array<int,MonologRecord>
4646
*/
4747
public function getChannelRecords(): array
4848
{
@@ -54,9 +54,13 @@ public function getChannelRecords(): array
5454
);
5555
}
5656

57-
public function channelRecordAt(int $index): ?array
57+
/**
58+
* @param int $index
59+
* @return MonologRecord
60+
*/
61+
public function channelRecordAt(int $index): array
5862
{
59-
return $this->getChannelRecords()[$index] ?? null;
63+
return $this->getChannelRecords()[$index] ?? throw new \OutOfBoundsException("No record at index {$index}");
6064
}
6165

6266
/**

tests/Support/TestStackLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* TestLoggerTrait to get most of this. You may need to override a method or
1212
* two, as we do in ExtendedWrappedMonolog.
1313
*
14-
* @psalm-type LogRecord = array{message:string, context:array, channel:string}
14+
* @psalm-type LogRecord = array{message:string, context:array, channel:string, ...}
1515
*/
1616
interface TestStackLogger extends StackLogger
1717
{

0 commit comments

Comments
 (0)