@@ -15,6 +15,18 @@ public function test_construct_and_to_string(): void
1515 self ::assertSame ('a.b.c ' , (string ) $ ltree );
1616 }
1717
18+ public function test_construct_trows_on_non_list (): void
19+ {
20+ $ this ->expectException (\InvalidArgumentException::class);
21+ new Ltree ([0 => 'a ' , 2 => 'b ' , 3 => 'c ' ]); // @phpstan-ignore argument.type
22+ }
23+
24+ public function test_construct_trows_on_empty_string_in_branch (): void
25+ {
26+ $ this ->expectException (\InvalidArgumentException::class);
27+ new Ltree (['a ' , '' , 'c ' ]); // @phpstan-ignore argument.type
28+ }
29+
1830 public function test_from_string (): void
1931 {
2032 $ ltree = Ltree::fromString ('x.y.z ' );
@@ -29,6 +41,20 @@ public function test_from_string_empty(): void
2941 self ::assertSame ('' , (string ) $ ltree );
3042 }
3143
44+ public function test_json_serialize (): void
45+ {
46+ $ branch = ['a ' , 'b ' , 'c ' ];
47+ $ ltree = new Ltree ($ branch );
48+ self ::assertSame ($ branch , $ ltree ->jsonSerialize ());
49+ }
50+
51+ public function test_json_encode (): void
52+ {
53+ $ ltree = new Ltree (['a ' , 'b ' , 'c ' ]);
54+ $ json = \json_encode ($ ltree );
55+ self ::assertSame ('["a","b","c"] ' , $ json );
56+ }
57+
3258 public function test_create_leaf (): void
3359 {
3460 $ ltree = new Ltree (['root ' ]);
0 commit comments