Skip to content

Commit

Permalink
chore: add tests for loadFromStream()
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 5, 2021
1 parent 9191cd6 commit 459ce79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions test/ConfigBoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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'));
}
}
2 changes: 1 addition & 1 deletion test/testdata/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: inhere
age: 89
atYaml: value2
atYaml: val at yaml

0 comments on commit 459ce79

Please sign in to comment.