File tree 2 files changed +38
-1
lines changed
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
43
43
return new self ($ this ->path .'.. ' );
44
44
}
45
45
46
- public function anyIndex (): static
46
+ public function all (): static
47
47
{
48
48
return new self ($ this ->path .'[*] ' );
49
49
}
50
50
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
+
51
61
public function slice (int $ start , ?int $ end = null , ?int $ step = null ): static
52
62
{
53
63
$ slice = $ start ;
Original file line number Diff line number Diff line change @@ -35,4 +35,31 @@ public function testBuildWithFilter()
35
35
36
36
$ this ->assertSame ('$.users[?(@.age > 18)] ' , (string ) $ path );
37
37
}
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
+ }
38
65
}
You can’t perform that action at this time.
0 commit comments