33namespace Tests \LIQRGV \QueryFilter ;
44
55use Illuminate \Database \Query \Builder ;
6- use Illuminate \Http \Request ;
7- use Illuminate \Routing \Route ;
8- use Illuminate \Support \Facades \Config ;
9- use LIQRGV \QueryFilter \Exception \ModelNotFoundException ;
10- use LIQRGV \QueryFilter \Exception \NotModelException ;
116use LIQRGV \QueryFilter \Mocks \MockModelController ;
127use LIQRGV \QueryFilter \Mocks \RelationMocks \MockModelWithRelationOne ;
138use LIQRGV \QueryFilter \RequestParser ;
@@ -39,18 +34,20 @@ function testFilterRelationOne()
3934 $ this ->assertEquals ("mock_model_with_relation_ones " , $ query ->from );
4035
4136 // assert relation first
42- $ this ->assertEquals ("Column " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [0 ]["type " ]);
43- $ this ->assertEquals ("mock_model_with_relation_ones.id " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [0 ]["first " ]);
44- $ this ->assertEquals ("= " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [0 ]["operator " ]);
45- $ this ->assertEquals ("mock_models.mock_model_with_relation_one_id " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [0 ]["second " ]);
46- $ this ->assertEquals ("and " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [0 ]["boolean " ]);
37+ $ firstQueryWhere = $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [0 ];
38+ $ this ->assertEquals ("Column " , $ firstQueryWhere ["type " ]);
39+ $ this ->assertEquals ("mock_model_with_relation_ones.id " , $ firstQueryWhere ["first " ]);
40+ $ this ->assertEquals ("= " , $ firstQueryWhere ["operator " ]);
41+ $ this ->assertEquals ("mock_models.mock_model_with_relation_one_id " , $ firstQueryWhere ["second " ]);
42+ $ this ->assertEquals ("and " , $ firstQueryWhere ["boolean " ]);
4743
4844 // assert relation query
49- $ this ->assertEquals ("Basic " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [1 ]["type " ]);
50- $ this ->assertEquals ("mock_models.id " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [1 ]["column " ]);
51- $ this ->assertEquals ("= " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [1 ]["operator " ]);
52- $ this ->assertEquals ("2 " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [1 ]["value " ]);
53- $ this ->assertEquals ("and " , $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [1 ]["boolean " ]);
45+ $ secondQueryWhere = $ builder ->getQuery ()->wheres [0 ]["query " ]->wheres [1 ];
46+ $ this ->assertEquals ("Basic " , $ secondQueryWhere ["type " ]);
47+ $ this ->assertEquals ("mock_models.id " , $ secondQueryWhere ["column " ]);
48+ $ this ->assertEquals ("= " , $ secondQueryWhere ["operator " ]);
49+ $ this ->assertEquals ("2 " , $ secondQueryWhere ["value " ]);
50+ $ this ->assertEquals ("and " , $ secondQueryWhere ["boolean " ]);
5451 }
5552
5653 function testFilterOrRelationOne ()
@@ -76,11 +73,12 @@ function testFilterOrRelationOne()
7673 $ this ->assertEquals ("mock_model_with_relation_ones " , $ query ->from );
7774
7875 // assert nested query
79- $ this ->assertEquals ("Nested " , $ builder ->getQuery ()->wheres [0 ]["type " ]);
80- $ this ->assertEquals ("and " , $ builder ->getQuery ()->wheres [0 ]["boolean " ]);
76+ $ firstQueryWhere = $ builder ->getQuery ()->wheres [0 ];
77+ $ this ->assertEquals ("Nested " , $ firstQueryWhere ["type " ]);
78+ $ this ->assertEquals ("and " , $ firstQueryWhere ["boolean " ]);
8179
8280 /** @var Builder $nestedQuery */
83- $ nestedQuery = $ builder -> getQuery ()-> wheres [ 0 ] ["query " ];
81+ $ nestedQuery = $ firstQueryWhere ["query " ];
8482
8583 $ this ->assertEquals ("Exists " , $ nestedQuery ->wheres [0 ]["type " ]);
8684 $ this ->assertEquals ("Exists " , $ nestedQuery ->wheres [1 ]["type " ]);
0 commit comments