Skip to content

Commit 459ce79

Browse files
committed
chore: add tests for loadFromStream()
1 parent 9191cd6 commit 459ce79

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

test/ConfigBoxTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use PhpPkg\Config\ConfigBox;
66
use PHPUnit\Framework\TestCase;
7+
use Toolkit\FsUtil\File;
8+
use function fclose;
9+
use function fopen;
710
use function vdump;
811

912
/**
@@ -63,4 +66,19 @@ public function testNewFromStrings(): void
6366
$this->assertEquals('val2', $c->get('key2'));
6467
$this->assertEquals('val4', $c->get('key4'));
6568
}
69+
70+
public function testLoadFromStream(): void
71+
{
72+
$s1 = fopen(__DIR__ . '/testdata/config.json', 'rb+');
73+
$c = ConfigBox::newFromStream(ConfigBox::FORMAT_JSON, $s1);
74+
fclose($s1);
75+
76+
$this->assertNotEmpty($c->all());
77+
$this->assertEquals('val at json', $c->get('atJson'));
78+
79+
$s2 = fopen(__DIR__ . '/testdata/config.yml', 'rb+');
80+
$c->loadFromStream(ConfigBox::FORMAT_YML, $s2);
81+
fclose($s2);
82+
$this->assertEquals('val at yaml', $c->get('atYaml'));
83+
}
6684
}

test/testdata/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: inhere
22
age: 89
3-
atYaml: value2
3+
atYaml: val at yaml
44

0 commit comments

Comments
 (0)