Skip to content

Commit 79ab480

Browse files
committed
[tests] Add more tests for string function callback
1 parent aafd45e commit 79ab480

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tests/Processor/CallableContextTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Stefna\Logger\Processor;
44

5+
use Monolog\Level;
6+
use Monolog\LogRecord;
57
use PHPUnit\Framework\TestCase;
68
use Psr\Log\LoggerInterface;
79
use Psr\Log\LogLevel;
@@ -61,6 +63,32 @@ public function testCallbackValueIsRemoved(): void
6163
$this->assertTrue($callbackExecuted);
6264
}
6365

66+
public function testStringCallbacksBeingSkipped(): void
67+
{
68+
$processor = new CallableContextProcessor();
69+
70+
$logRecord = new LogRecord(
71+
new \DateTimeImmutable(),
72+
'test',
73+
Level::Alert,
74+
'message',
75+
[
76+
'nativeFunction' => 'header',
77+
'namespacedFunction' => 'Stefna\Logger\Processor\testingFunction',
78+
'deferredValue' => function () {
79+
return 'complexValue';
80+
}
81+
],
82+
);
83+
84+
$modifiedContext = $processor($logRecord);
85+
$this->assertSame([
86+
'nativeFunction' => 'header',
87+
'namespacedFunction' => 'Stefna\Logger\Processor\testingFunction',
88+
'deferredValue' => 'complexValue',
89+
], $modifiedContext->context);
90+
}
91+
6492
public function testStringFunctionIsNotCalled():void
6593
{
6694
$stringFunction = 'Stefna\Logger\Processor\testingFunction';
@@ -82,7 +110,7 @@ public function testStringFunctionIsNotCalled():void
82110
}
83111
}
84112

85-
function testingFunction()
113+
function testingFunction(): never
86114
{
87-
print("should not print this");
115+
CallableContextTest::fail("Shouldn't be called");
88116
}

0 commit comments

Comments
 (0)