diff --git a/README.md b/README.md index 27d31a5..36461f2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ # VDF Converter ![Tests](https://github.com/exayer/vdf-converter/workflows/Tests/badge.svg) -[![Total Downloads](https://img.shields.io/packagist/dt/EXayer/vdf-converter)](https://packagist.org/packages/exayer/vdf-converter) ![Latest Stable Version](https://img.shields.io/packagist/v/exayer/vdf-converter) A memory efficient parser for the Valve Data Format (*.vdf) written in PHP. @@ -144,7 +143,7 @@ After creating your formatter, you can specify its class name in the `uniqueKeyF You can also specify a signer for a specific webhook call: ```php -$config = (new VdfConverterConfig()) +$config = VdfConverterConfig::create() ->uniqueKeyFormatter(YourCustomFormatter::class); $iterator = VdfConverter::fromString($vdf, $config); diff --git a/tests/ParserTest.php b/tests/ParserTest.php index b4db7be..6d8cc52 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -5,6 +5,7 @@ use EXayer\VdfConverter\Exception\CouldNotParseException; use EXayer\VdfConverter\Lexer; use EXayer\VdfConverter\Parser; +use EXayer\VdfConverter\VdfConverterConfig; use PHPUnit\Framework\TestCase; class ParserTest extends TestCase @@ -16,7 +17,7 @@ class ParserTest extends TestCase */ public function testSyntax($vdf, $expectedResult) { - $parser = new Parser(new Lexer(new \ArrayIterator([$vdf]))); + $parser = new Parser(new Lexer(new \ArrayIterator([$vdf])), new VdfConverterConfig()); $result = iterator_to_array($parser); $this->assertEquals($expectedResult, $result); @@ -87,13 +88,13 @@ public function syntaxDataProvider() [ 'a' => [ 'b' => 1, - 'x' => ['x' => 1, 'x__2' => 2], + 'x' => ['x' => 1, 'x__[2]' => 2], 'e' => [ - 'f' => ['x' => 1, '' => 1, '__2' => 2, 'x__2' => 2], - 'f__2' => [], + 'f' => ['x' => 1, '' => 1, '__[2]' => 2, 'x__[2]' => 2], + 'f__[2]' => [], ], - 'x__2' => [], - 'e__2' => [], + 'x__[2]' => [], + 'e__[2]' => [], ], ], ], @@ -103,14 +104,14 @@ public function syntaxDataProvider() [ 'a' => 1, - 'b' => ['c' => 1, 'c__2' => 2], - 'a__2' => [ - 'b' => ['c' => 1, 'c__2' => 2], - 'b__2' => [], + 'b' => ['c' => 1, 'c__[2]' => 2], + 'a__[2]' => [ + 'b' => ['c' => 1, 'c__[2]' => 2], + 'b__[2]' => [], ], - 'a__3' => [], + 'a__[3]' => [], 'c' => [], - 'c__2' => [], + 'c__[2]' => [], ], ], // all duplicates @@ -118,13 +119,13 @@ public function syntaxDataProvider() '{"x" "1" "x" {"x" "1" "x" "2"} "x" {"x" {"x" "1" "x" "2"} "x" {}} "x" {} "x" {}}', [ 'x' => 1, - 'x__2' => ['x' => 1, 'x__2' => 2], - 'x__3' => [ - 'x' => ['x' => 1, 'x__2' => 2], - 'x__2' => [], + 'x__[2]' => ['x' => 1, 'x__[2]' => 2], + 'x__[3]' => [ + 'x' => ['x' => 1, 'x__[2]' => 2], + 'x__[2]' => [], ], - 'x__4' => [], - 'x__5' => [], + 'x__[4]' => [], + 'x__[5]' => [], ], ], ]; @@ -138,7 +139,7 @@ public function testSyntaxError(string $brokenVdf) { $this->expectException(CouldNotParseException::class); - iterator_to_array(new Parser(new Lexer(new \ArrayIterator([$brokenVdf])))); + iterator_to_array(new Parser(new Lexer(new \ArrayIterator([$brokenVdf])), new VdfConverterConfig())); } public function syntaxErrorDataProvider() @@ -162,7 +163,7 @@ public function testUnexpectedEndError(string $vdf) { $this->expectExceptionMessage(CouldNotParseException::unexpectedEnding()->getMessage()); - iterator_to_array(new Parser(new Lexer(new \ArrayIterator([$vdf])))); + iterator_to_array(new Parser(new Lexer(new \ArrayIterator([$vdf])), new VdfConverterConfig())); } public function unexpectedEndExceptionDataProvider() diff --git a/tests/UniqueKey/DefaultFormatterTest.php b/tests/UniqueKey/DefaultFormatterTest.php new file mode 100644 index 0000000..98285a7 --- /dev/null +++ b/tests/UniqueKey/DefaultFormatterTest.php @@ -0,0 +1,17 @@ +buildKeyName('sample_key', 9); + + $this->assertEquals($formattedKey, 'sample_key__[9]'); + } +} \ No newline at end of file diff --git a/tests/UniqueKeyTest.php b/tests/UniqueKey/UniqueKeyTest.php similarity index 81% rename from tests/UniqueKeyTest.php rename to tests/UniqueKey/UniqueKeyTest.php index 890553b..188baa7 100644 --- a/tests/UniqueKeyTest.php +++ b/tests/UniqueKey/UniqueKeyTest.php @@ -1,8 +1,9 @@ $key) { @@ -44,7 +45,7 @@ public function storageDataProvider() [ [[1 => 'key'], [1 => 'key']], [], - [1, 'key', 'key__3'] + [1, 'key', 'key__[3]'] ], [ [[1 => 'key'], [1 => 'key'], [2 => 'key'], [3 => 'key']], @@ -54,7 +55,7 @@ public function storageDataProvider() [ [[1 => 'key'], [2 => 'key'], [3 => 'key']], [2, 3], - [1, 'key', 'key__2'] + [1, 'key', 'key__[2]'] ], ]; } diff --git a/tests/VdfConverterConfigTest.php b/tests/VdfConverterConfigTest.php new file mode 100644 index 0000000..78fb014 --- /dev/null +++ b/tests/VdfConverterConfigTest.php @@ -0,0 +1,16 @@ +uniqueKeyFormatter(DefaultFormatter::class); + + $this->assertEquals(new DefaultFormatter(), $config->getUniqueKeyFormatter()); + } +} \ No newline at end of file