@@ -37,169 +37,250 @@ final class QueryTest extends TestCase {
3737
3838 public function testBasicFilterEqual (): void {
3939 foreach ($this -> tests as $test ) {
40- $this -> assertSame(
41- " equal( \" attr \" , $test -> expectedValues ) " ,
42- Query :: equal (' attr' , $test -> value ),
43- $test -> description ,
44- );
40+ $query = json_decode ( Query :: equal( ' attr ' , $test -> value ), true );
41+ $expected = json_decode ( $test -> expectedValues , true );
42+ $this -> assertSame (' attr' , $query [ ' attribute ' ], $ test-> description );
43+ $this -> assertSame( $expected , $query [ ' values ' ], $test -> description );
44+ $this -> assertSame( ' equal ' , $query [ ' method ' ], $test -> description );
4545 }
4646 }
4747
4848 public function testBasicFilterNotEqual (): void {
4949 foreach ($this -> tests as $test ) {
50- $this -> assertSame(
51- " notEqual( \" attr \" , $test -> expectedValues ) " ,
52- Query :: notEqual (' attr' , $test -> value ),
53- $test -> description ,
54- );
50+ $query = json_decode ( Query :: notEqual( ' attr ' , $test -> value ), true );
51+ $expected = json_decode ( $test -> expectedValues , true );
52+ $this -> assertSame (' attr' , $query [ ' attribute ' ], $ test-> description );
53+ $this -> assertSame( $expected , $query [ ' values ' ], $test -> description );
54+ $this -> assertSame( ' notEqual ' , $query [ ' method ' ], $test -> description );
5555 }
5656 }
5757
5858 public function testBasicFilterLessThan (): void {
5959 foreach ($this -> tests as $test ) {
60- $this -> assertSame(
61- " lessThan( \" attr \" , $test -> expectedValues ) " ,
62- Query :: lessThan (' attr' , $test -> value ),
63- $test -> description ,
64- );
60+ $query = json_decode ( Query :: lessThan( ' attr ' , $test -> value ), true );
61+ $expected = json_decode ( $test -> expectedValues , true );
62+ $this -> assertSame (' attr' , $query [ ' attribute ' ], $ test-> description );
63+ $this -> assertSame( $expected , $query [ ' values ' ], $test -> description );
64+ $this -> assertSame( ' lessThan ' , $query [ ' method ' ], $test -> description );
6565 }
6666 }
6767
6868 public function testBasicFilterLessThanEqual (): void {
6969 foreach ($this -> tests as $test ) {
70- $this -> assertSame(
71- " lessThanEqual( \" attr \" , $test -> expectedValues ) " ,
72- Query :: lessThanEqual (' attr' , $test -> value ),
73- $test -> description ,
74- );
70+ $query = json_decode ( Query :: lessThanEqual( ' attr ' , $test -> value ), true );
71+ $expected = json_decode ( $test -> expectedValues , true );
72+ $this -> assertSame (' attr' , $query [ ' attribute ' ], $ test-> description );
73+ $this -> assertSame( $expected , $query [ ' values ' ], $test -> description );
74+ $this -> assertSame( ' lessThanEqual ' , $query [ ' method ' ], $test -> description );
7575 }
7676 }
7777
7878 public function testBasicFilterGreaterThan (): void {
7979 foreach ($this -> tests as $test ) {
80- $this -> assertSame(
81- " greaterThan( \" attr \" , $test -> expectedValues ) " ,
82- Query :: greaterThan (' attr' , $test -> value ),
83- $test -> description ,
84- );
80+ $query = json_decode ( Query :: greaterThan( ' attr ' , $test -> value ), true );
81+ $expected = json_decode ( $test -> expectedValues , true );
82+ $this -> assertSame (' attr' , $query [ ' attribute ' ], $ test-> description );
83+ $this -> assertSame( $expected , $query [ ' values ' ], $test -> description );
84+ $this -> assertSame( ' greaterThan ' , $query [ ' method ' ], $test -> description );
8585 }
8686 }
8787
8888 public function testBasicFilterGreaterThanEqual (): void {
8989 foreach ($this -> tests as $test ) {
90- $this -> assertSame(
91- " greaterThanEqual( \" attr \" , $test -> expectedValues ) " ,
92- Query :: greaterThanEqual (' attr' , $test -> value ),
93- $test -> description ,
94- );
90+ $query = json_decode ( Query :: greaterThanEqual( ' attr ' , $test -> value ), true );
91+ $expected = json_decode ( $test -> expectedValues , true );
92+ $this -> assertSame (' attr' , $query [ ' attribute ' ], $ test-> description );
93+ $this -> assertSame( $expected , $query [ ' values ' ], $test -> description );
94+ $this -> assertSame( ' greaterThanEqual ' , $query [ ' method ' ], $test -> description );
9595 }
9696 }
9797
9898 public function testSearch (): void {
99- $this -> assertSame(' search("attr", ["keyword1 keyword2"])' , Query :: search(' attr' , ' keyword1 keyword2' ));
99+ $query = json_decode (Query :: search(' attr' , ' keyword1 keyword2' ), true );
100+ $this -> assertSame(' attr' , $query [' attribute' ]);
101+ $this -> assertSame([' keyword1 keyword2' ], $query [' values' ]);
102+ $this -> assertSame(' search' , $query [' method' ]);
100103 }
101104
102105 public function testIsNull (): void {
103- $this -> assertSame(' isNull("attr")' , Query :: isNull(' attr' ));
106+ $query = json_decode (Query :: isNull(' attr' ), true );
107+ $this -> assertSame(' attr' , $query [' attribute' ]);
108+ $this -> assertNull($query [' values' ] ?? null );
109+ $this -> assertSame(' isNull' , $query [' method' ]);
104110 }
105111
106112 public function testIsNotNull (): void {
107- $this -> assertSame(' isNotNull("attr")' , Query :: isNotNull(' attr' ));
113+ $query = json_decode (Query :: isNotNull(' attr' ), true );
114+ $this -> assertSame(' attr' , $query [' attribute' ]);
115+ $this -> assertNull($query [' values' ] ?? null );
116+ $this -> assertSame(' isNotNull' , $query [' method' ]);
108117 }
109118
110119 public function testBetweenWithIntegers (): void {
111- $this -> assertSame(' between("attr", 1, 2)' , Query :: between(' attr' , 1 , 2 ));
120+ $query = json_decode (Query :: between(' attr' , 1 , 2 ), true );
121+ $this -> assertSame(' attr' , $query [' attribute' ]);
122+ $this -> assertSame([1 , 2 ], $query [' values' ]);
123+ $this -> assertSame(' between' , $query [' method' ]);
112124 }
113125
114126 public function testBetweenWithDoubles (): void {
115- $this -> assertSame(' between("attr", 1, 2)' , Query :: between(' attr' , 1.0 , 2.0 ));
127+ $query = json_decode (Query :: between(' attr' , 1.0 , 2.0 ), true );
128+ $this -> assertSame(' attr' , $query [' attribute' ]);
129+ $this -> assertSame([1 , 2 ], $query [' values' ]);
130+ $this -> assertSame(' between' , $query [' method' ]);
116131 }
117132
118133 public function testBetweenWithStrings (): void {
119- $this -> assertSame(' between("attr", "a", "z")' , Query :: between(' attr' , ' a' , ' z' ));
134+ $query = json_decode (Query :: between(' attr' , ' a' , ' z' ), true );
135+ $this -> assertSame(' attr' , $query [' attribute' ]);
136+ $this -> assertSame([' a' , ' z' ], $query [' values' ]);
137+ $this -> assertSame(' between' , $query [' method' ]);
120138 }
121139
122140 public function testSelect (): void {
123- $this -> assertSame(' select(["attr1","attr2"])' , Query :: select([' attr1' , ' attr2' ]));
141+ $query = json_decode (Query :: select([' attr1' , ' attr2' ]), true );
142+ $this -> assertNull($query [' attribute' ] ?? null );
143+ $this -> assertSame([' attr1' , ' attr2' ], $query [' values' ]);
144+ $this -> assertSame(' select' , $query [' method' ]);
124145 }
125146
126147 public function testOrderAsc (): void {
127- $this -> assertSame(' orderAsc("attr")' , Query :: orderAsc(' attr' ));
148+ $query = json_decode (Query :: orderAsc(' attr' ), true );
149+ $this -> assertSame(' attr' , $query [' attribute' ]);
150+ $this -> assertNull($query [' values' ] ?? null );
151+ $this -> assertSame(' orderAsc' , $query [' method' ]);
128152 }
129153
130154 public function testOrderDesc (): void {
131- $this -> assertSame(' orderDesc("attr")' , Query :: orderDesc(' attr' ));
155+ $query = json_decode (Query :: orderDesc(' attr' ), true );
156+ $this -> assertSame(' attr' , $query [' attribute' ]);
157+ $this -> assertNull($query [' values' ] ?? null );
158+ $this -> assertSame(' orderDesc' , $query [' method' ]);
132159 }
133160
134161 public function testOrderRandom (): void {
135- $this -> assertSame(' {"method":"orderRandom"}' , Query :: orderRandom());
162+ $query = json_decode (Query :: orderRandom(), true );
163+ $this -> assertNull($query [' attribute' ] ?? null );
164+ $this -> assertNull($query [' values' ] ?? null );
165+ $this -> assertSame(' orderRandom' , $query [' method' ]);
136166 }
137167
138168 public function testCursorBefore (): void {
139- $this -> assertSame(' cursorBefore("attr")' , Query :: cursorBefore(' attr' ));
169+ $query = json_decode (Query :: cursorBefore(' attr' ), true );
170+ $this -> assertNull($query [' attribute' ] ?? null );
171+ $this -> assertSame([' attr' ], $query [' values' ]);
172+ $this -> assertSame(' cursorBefore' , $query [' method' ]);
140173 }
141174
142175 public function testCursorAfter (): void {
143- $this -> assertSame(' cursorAfter("attr")' , Query :: cursorAfter(' attr' ));
176+ $query = json_decode (Query :: cursorAfter(' attr' ), true );
177+ $this -> assertNull($query [' attribute' ] ?? null );
178+ $this -> assertSame([' attr' ], $query [' values' ]);
179+ $this -> assertSame(' cursorAfter' , $query [' method' ]);
144180 }
145181
146182 public function testLimit (): void {
147- $this -> assertSame(' limit(1)' , Query :: limit(1 ));
183+ $query = json_decode (Query :: limit(1 ), true );
184+ $this -> assertNull($query [' attribute' ] ?? null );
185+ $this -> assertSame([1 ], $query [' values' ]);
186+ $this -> assertSame(' limit' , $query [' method' ]);
148187 }
149188
150189 public function testOffset (): void {
151- $this -> assertSame(' offset(1)' , Query :: offset(1 ));
190+ $query = json_decode (Query :: offset(1 ), true );
191+ $this -> assertNull($query [' attribute' ] ?? null );
192+ $this -> assertSame([1 ], $query [' values' ]);
193+ $this -> assertSame(' offset' , $query [' method' ]);
152194 }
153195
154196 public function testNotContains (): void {
155- $this -> assertSame(' notContains("attr", ["value"])' , Query :: notContains(' attr' , ' value' ));
197+ $query = json_decode (Query :: notContains(' attr' , ' value' ), true );
198+ $this -> assertSame(' attr' , $query [' attribute' ]);
199+ $this -> assertSame([' value' ], $query [' values' ]);
200+ $this -> assertSame(' notContains' , $query [' method' ]);
156201 }
157202
158203 public function testNotSearch (): void {
159- $this -> assertSame(' notSearch("attr", ["keyword1 keyword2"])' , Query :: notSearch(' attr' , ' keyword1 keyword2' ));
204+ $query = json_decode (Query :: notSearch(' attr' , ' keyword1 keyword2' ), true );
205+ $this -> assertSame(' attr' , $query [' attribute' ]);
206+ $this -> assertSame([' keyword1 keyword2' ], $query [' values' ]);
207+ $this -> assertSame(' notSearch' , $query [' method' ]);
160208 }
161209
162210 public function testNotBetweenWithIntegers (): void {
163- $this -> assertSame(' notBetween("attr", 1, 2)' , Query :: notBetween(' attr' , 1 , 2 ));
211+ $query = json_decode (Query :: notBetween(' attr' , 1 , 2 ), true );
212+ $this -> assertSame(' attr' , $query [' attribute' ]);
213+ $this -> assertSame([1 , 2 ], $query [' values' ]);
214+ $this -> assertSame(' notBetween' , $query [' method' ]);
164215 }
165216
166217 public function testNotBetweenWithDoubles (): void {
167- $this -> assertSame(' notBetween("attr", 1, 2)' , Query :: notBetween(' attr' , 1.0 , 2.0 ));
218+ $query = json_decode (Query :: notBetween(' attr' , 1.0 , 2.0 ), true );
219+ $this -> assertSame(' attr' , $query [' attribute' ]);
220+ $this -> assertSame([1 , 2 ], $query [' values' ]);
221+ $this -> assertSame(' notBetween' , $query [' method' ]);
168222 }
169223
170224 public function testNotBetweenWithStrings (): void {
171- $this -> assertSame(' notBetween("attr", "a", "z")' , Query :: notBetween(' attr' , ' a' , ' z' ));
225+ $query = json_decode (Query :: notBetween(' attr' , ' a' , ' z' ), true );
226+ $this -> assertSame(' attr' , $query [' attribute' ]);
227+ $this -> assertSame([' a' , ' z' ], $query [' values' ]);
228+ $this -> assertSame(' notBetween' , $query [' method' ]);
172229 }
173230
174231 public function testNotStartsWith (): void {
175- $this -> assertSame(' notStartsWith("attr", ["prefix"])' , Query :: notStartsWith(' attr' , ' prefix' ));
232+ $query = json_decode (Query :: notStartsWith(' attr' , ' prefix' ), true );
233+ $this -> assertSame(' attr' , $query [' attribute' ]);
234+ $this -> assertSame([' prefix' ], $query [' values' ]);
235+ $this -> assertSame(' notStartsWith' , $query [' method' ]);
176236 }
177237
178238 public function testNotEndsWith (): void {
179- $this -> assertSame(' notEndsWith("attr", ["suffix"])' , Query :: notEndsWith(' attr' , ' suffix' ));
239+ $query = json_decode (Query :: notEndsWith(' attr' , ' suffix' ), true );
240+ $this -> assertSame(' attr' , $query [' attribute' ]);
241+ $this -> assertSame([' suffix' ], $query [' values' ]);
242+ $this -> assertSame(' notEndsWith' , $query [' method' ]);
180243 }
181244
182245 public function testCreatedBefore (): void {
183- $this -> assertSame(' lessThan("$createdAt", ["2023-01-01"])' , Query :: createdBefore(' 2023-01-01' ));
246+ $query = json_decode (Query :: createdBefore(' 2023-01-01' ), true );
247+ $this -> assertSame(' $createdAt' , $query [' attribute' ]);
248+ $this -> assertSame([' 2023-01-01' ], $query [' values' ]);
249+ $this -> assertSame(' lessThan' , $query [' method' ]);
184250 }
185251
186252 public function testCreatedAfter (): void {
187- $this -> assertSame(' greaterThan("$createdAt", ["2023-01-01"])' , Query :: createdAfter(' 2023-01-01' ));
253+ $query = json_decode (Query :: createdAfter(' 2023-01-01' ), true );
254+ $this -> assertSame(' $createdAt' , $query [' attribute' ]);
255+ $this -> assertSame([' 2023-01-01' ], $query [' values' ]);
256+ $this -> assertSame(' greaterThan' , $query [' method' ]);
188257 }
189258
190259 public function testCreatedBetween (): void {
191- $this -> assertSame(' between("$createdAt", ["2023-01-01","2023-12-31"])' , Query :: createdBetween(' 2023-01-01' , ' 2023-12-31' ));
260+ $query = json_decode (Query :: createdBetween(' 2023-01-01' , ' 2023-12-31' ), true );
261+ $this -> assertSame(' $createdAt' , $query [' attribute' ]);
262+ $this -> assertSame([' 2023-01-01' , ' 2023-12-31' ], $query [' values' ]);
263+ $this -> assertSame(' between' , $query [' method' ]);
192264 }
193265
194266 public function testUpdatedBefore (): void {
195- $this -> assertSame(' lessThan("$updatedAt", ["2023-01-01"])' , Query :: updatedBefore(' 2023-01-01' ));
267+ $query = json_decode (Query :: updatedBefore(' 2023-01-01' ), true );
268+ $this -> assertSame(' $updatedAt' , $query [' attribute' ]);
269+ $this -> assertSame([' 2023-01-01' ], $query [' values' ]);
270+ $this -> assertSame(' lessThan' , $query [' method' ]);
196271 }
197272
198273 public function testUpdatedAfter (): void {
199- $this -> assertSame(' greaterThan("$updatedAt", ["2023-01-01"])' , Query :: updatedAfter(' 2023-01-01' ));
274+ $query = json_decode (Query :: updatedAfter(' 2023-01-01' ), true );
275+ $this -> assertSame(' $updatedAt' , $query [' attribute' ]);
276+ $this -> assertSame([' 2023-01-01' ], $query [' values' ]);
277+ $this -> assertSame(' greaterThan' , $query [' method' ]);
200278 }
201279
202280 public function testUpdatedBetween (): void {
203- $this -> assertSame(' between("$updatedAt", ["2023-01-01","2023-12-31"])' , Query :: updatedBetween(' 2023-01-01' , ' 2023-12-31' ));
281+ $query = json_decode (Query :: updatedBetween(' 2023-01-01' , ' 2023-12-31' ), true );
282+ $this -> assertSame(' $updatedAt' , $query [' attribute' ]);
283+ $this -> assertSame([' 2023-01-01' , ' 2023-12-31' ], $query [' values' ]);
284+ $this -> assertSame(' between' , $query [' method' ]);
204285 }
205286}
0 commit comments