From 459ce799d7bb312d4b637196bbc2e841528e3af6 Mon Sep 17 00:00:00 2001 From: Inhere Date: Sun, 5 Dec 2021 16:50:47 +0800 Subject: [PATCH] chore: add tests for loadFromStream() --- test/ConfigBoxTest.php | 18 ++++++++++++++++++ test/testdata/config.yml | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/test/ConfigBoxTest.php b/test/ConfigBoxTest.php index 9117091..794c72e 100644 --- a/test/ConfigBoxTest.php +++ b/test/ConfigBoxTest.php @@ -4,6 +4,9 @@ use PhpPkg\Config\ConfigBox; use PHPUnit\Framework\TestCase; +use Toolkit\FsUtil\File; +use function fclose; +use function fopen; use function vdump; /** @@ -63,4 +66,19 @@ public function testNewFromStrings(): void $this->assertEquals('val2', $c->get('key2')); $this->assertEquals('val4', $c->get('key4')); } + + public function testLoadFromStream(): void + { + $s1 = fopen(__DIR__ . '/testdata/config.json', 'rb+'); + $c = ConfigBox::newFromStream(ConfigBox::FORMAT_JSON, $s1); + fclose($s1); + + $this->assertNotEmpty($c->all()); + $this->assertEquals('val at json', $c->get('atJson')); + + $s2 = fopen(__DIR__ . '/testdata/config.yml', 'rb+'); + $c->loadFromStream(ConfigBox::FORMAT_YML, $s2); + fclose($s2); + $this->assertEquals('val at yaml', $c->get('atYaml')); + } } diff --git a/test/testdata/config.yml b/test/testdata/config.yml index f50cd08..44a992b 100644 --- a/test/testdata/config.yml +++ b/test/testdata/config.yml @@ -1,4 +1,4 @@ name: inhere age: 89 -atYaml: value2 +atYaml: val at yaml