File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -43,11 +43,21 @@ public function deepScan(): static
4343 return new self ($ this ->path .'.. ' );
4444 }
4545
46- public function anyIndex (): static
46+ public function all (): static
4747 {
4848 return new self ($ this ->path .'[*] ' );
4949 }
5050
51+ public function first (): static
52+ {
53+ return new self ($ this ->path .'[0] ' );
54+ }
55+
56+ public function last (): static
57+ {
58+ return new self ($ this ->path .'[-1] ' );
59+ }
60+
5161 public function slice (int $ start , ?int $ end = null , ?int $ step = null ): static
5262 {
5363 $ slice = $ start ;
Original file line number Diff line number Diff line change @@ -35,4 +35,31 @@ public function testBuildWithFilter()
3535
3636 $ this ->assertSame ('$.users[?(@.age > 18)] ' , (string ) $ path );
3737 }
38+
39+ public function testAll ()
40+ {
41+ $ path = new JsonPath ();
42+ $ path = $ path ->key ('users ' )
43+ ->all ();
44+
45+ $ this ->assertSame ('$.users[*] ' , (string ) $ path );
46+ }
47+
48+ public function testFirst ()
49+ {
50+ $ path = new JsonPath ();
51+ $ path = $ path ->key ('users ' )
52+ ->first ();
53+
54+ $ this ->assertSame ('$.users[0] ' , (string ) $ path );
55+ }
56+
57+ public function testLast ()
58+ {
59+ $ path = new JsonPath ();
60+ $ path = $ path ->key ('users ' )
61+ ->last ();
62+
63+ $ this ->assertSame ('$.users[-1] ' , (string ) $ path );
64+ }
3865}
You can’t perform that action at this time.
0 commit comments