@@ -74,52 +74,48 @@ public function test_complex_query_can_ignore_select_in_count()
7474 $ this ->assertQueryHasNoSelect (true , $ dataTable ->prepareCountQuery ());
7575 $ this ->assertEquals (20 , $ dataTable ->count ());
7676 }
77-
78- public function test_complexe_queries_with_complexe_select_are_wrapped_without_selects ()
77+
78+ public function test_simple_queries_with_complexe_select_are_not_wrapped ()
7979 {
8080 /** @var \Yajra\DataTables\QueryDataTable $dataTable */
8181 $ dataTable = app ('datatables ' )->of (
82- DB ::table ('users ' )
83- ->select ([ 'users.* ' , DB :: raw ( ' count(*) as posts_count ' )] )
82+ DB ::table ('users ' )
83+ ->select ('users.* ' )
8484 ->addSelect ([
8585 'last_post_id ' => DB ::table ('posts ' )
8686 ->whereColumn ('posts.user_id ' , 'users.id ' )
8787 ->orderBy ('created_at ' )
8888 ->select ('id ' ),
8989 ])
90- ->join ('posts ' , 'posts.user_id ' , 'users.id ' )
91- ->groupBy ('users.id ' )
9290 );
9391
94-
95- $ this ->assertQueryWrapped (true , $ dataTable ->prepareCountQuery ());
96- $ this ->assertQueryHasNoSelect (false , $ dataTable ->prepareCountQuery ());
92+ $ this ->assertQueryWrapped (false , $ dataTable ->prepareCountQuery ());
9793 $ this ->assertEquals (20 , $ dataTable ->count ());
9894 }
9995
100- public function test_simple_queries_with_complexe_select_are_not_wrapped ()
96+ public function test_simple_queries_with_complexe_where_are_not_wrapped ()
10197 {
10298 /** @var \Yajra\DataTables\QueryDataTable $dataTable */
10399 $ dataTable = app ('datatables ' )->of (
104100 DB ::table ('users ' )
105101 ->select ('users.* ' )
106- ->addSelect ([
107- ' last_post_id ' => DB ::table ('posts ' )
102+ ->where (
103+ DB ::table ('posts ' )
108104 ->whereColumn ('posts.user_id ' , 'users.id ' )
109105 ->orderBy ('created_at ' )
110- ->select ('id ' ),
111- ] )
106+ ->select ('title ' ), ' User-1 Post-1 '
107+ )
112108 );
113109
114110 $ this ->assertQueryWrapped (false , $ dataTable ->prepareCountQuery ());
115- $ this ->assertEquals (20 , $ dataTable ->count ());
111+ $ this ->assertEquals (1 , $ dataTable-> prepareCountQuery () ->count ());
116112 }
117113
118- public function test_simple_queries_with_complexe_where_are_not_wrapped ()
114+ public function test_simple_eloquent_queries_with_complexe_where_are_not_wrapped ()
119115 {
120116 /** @var \Yajra\DataTables\QueryDataTable $dataTable */
121117 $ dataTable = app ('datatables ' )->of (
122- DB :: table ( ' users ' )
118+ User:: query ( )
123119 ->select ('users.* ' )
124120 ->where (
125121 DB ::table ('posts ' )
@@ -157,10 +153,10 @@ public function test_complexe_queries_can_be_wrapped_and_countable()
157153
158154 /**
159155 * @param $expected bool
160- * @param $query \Illuminate\Database\Eloquent\Builder|\Illuminate \Database\Query\Builder
156+ * @param $query \Illuminate\Contracts \Database\Query\Builder
161157 * @return void
162158 */
163- protected function assertQueryWrapped ($ expected , $ query )
159+ protected function assertQueryWrapped ($ expected , $ query ): void
164160 {
165161 $ sql = $ query ->toSql ();
166162
@@ -169,10 +165,10 @@ protected function assertQueryWrapped($expected, $query)
169165
170166 /**
171167 * @param $expected bool
172- * @param $query \Illuminate\Database\Eloquent\Builder|\Illuminate \Database\Query\Builder
168+ * @param $query \Illuminate\Contracts \Database\Query\Builder
173169 * @return void
174170 */
175- public function assertQueryHasNoSelect ($ expected , $ query )
171+ public function assertQueryHasNoSelect ($ expected , $ query ): void
176172 {
177173 $ sql = $ query ->select (DB ::raw ('count(*) ' ))->toSql ();
178174
0 commit comments