File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,13 @@ private function __construct(mixed $resource)
1616
1717 public static function from (mixed $ resource = null ): LogStream
1818 {
19- return new LogStream (resource: $ resource ?? STDERR );
19+ if ($ resource !== null ) {
20+ return new LogStream (resource: $ resource );
21+ }
22+
23+ $ fallback = fopen ('php://stderr ' , 'wb ' );
24+
25+ return new LogStream (resource: $ fallback );
2026 }
2127
2228 public function write (string $ content ): void
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Test \TinyBlocks \Logger \Internal \Stream ;
6+
7+ use PHPUnit \Framework \TestCase ;
8+ use TinyBlocks \Logger \Internal \Stream \LogStream ;
9+
10+ final class LogStreamTest extends TestCase
11+ {
12+ /** @noinspection PhpConditionAlreadyCheckedInspection */
13+ public function testFromWithoutResourceFallsBackToStderr (): void
14+ {
15+ /** @Given no resource is provided */
16+ /** @When creating a LogStream without a resource */
17+ $ logStream = LogStream::from ();
18+
19+ /** @Then a LogStream instance should be returned (using stderr as fallback) */
20+ self ::assertInstanceOf (LogStream::class, $ logStream );
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments