summaryrefslogtreecommitdiff
path: root/tests/app/Utils/dotpathUtilTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/app/Utils/dotpathUtilTest.php')
-rw-r--r--tests/app/Utils/dotpathUtilTest.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/app/Utils/dotpathUtilTest.php b/tests/app/Utils/dotpathUtilTest.php
new file mode 100644
index 000000000..e4eab3041
--- /dev/null
+++ b/tests/app/Utils/dotpathUtilTest.php
@@ -0,0 +1,44 @@
+<?php
+declare(strict_types=1);
+
+class dotpathUtilTest extends PHPUnit\Framework\TestCase {
+
+ /**
+ * @return Traversable<array{array<string,mixed>,string,mixed}>
+ */
+ public function provideJsonDots(): Traversable {
+ $json = <<<json
+ {
+ "hello": "world",
+ "deeper": {
+ "hello": "again"
+ },
+ "items": [
+ {
+ "meta": {"title": "first"}
+ },
+ {
+ "meta": {"title": "second"}
+ }
+ ]
+ }
+ json;
+ $array = json_decode($json, true);
+
+ yield [$array, 'hello', 'world'];
+ yield [$array, 'deeper.hello', 'again'];
+ yield [$array, 'items.0.meta.title', 'first'];
+ yield [$array, 'items[0].meta.title', 'first'];
+ yield [$array, 'items.1.meta.title', 'second'];
+ yield [$array, 'items[1].meta.title', 'second'];
+ }
+
+ /**
+ * @dataProvider provideJsonDots
+ * @param array<string,mixed> $array
+ */
+ public function testJsonDots(array $array, string $key, mixed $expected): void {
+ $value = FreshRSS_dotpath_Util::get($array, $key);
+ self::assertEquals($expected, $value);
+ }
+}