@@ -74,52 +74,48 @@ public function test_complex_query_can_ignore_select_in_count()
74
74
$ this ->assertQueryHasNoSelect (true , $ dataTable ->prepareCountQuery ());
75
75
$ this ->assertEquals (20 , $ dataTable ->count ());
76
76
}
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 ()
79
79
{
80
80
/** @var \Yajra\DataTables\QueryDataTable $dataTable */
81
81
$ dataTable = app ('datatables ' )->of (
82
- DB ::table ('users ' )
83
- ->select ([ 'users.* ' , DB :: raw ( ' count(*) as posts_count ' )] )
82
+ DB ::table ('users ' )
83
+ ->select ('users.* ' )
84
84
->addSelect ([
85
85
'last_post_id ' => DB ::table ('posts ' )
86
86
->whereColumn ('posts.user_id ' , 'users.id ' )
87
87
->orderBy ('created_at ' )
88
88
->select ('id ' ),
89
89
])
90
- ->join ('posts ' , 'posts.user_id ' , 'users.id ' )
91
- ->groupBy ('users.id ' )
92
90
);
93
91
94
-
95
- $ this ->assertQueryWrapped (true , $ dataTable ->prepareCountQuery ());
96
- $ this ->assertQueryHasNoSelect (false , $ dataTable ->prepareCountQuery ());
92
+ $ this ->assertQueryWrapped (false , $ dataTable ->prepareCountQuery ());
97
93
$ this ->assertEquals (20 , $ dataTable ->count ());
98
94
}
99
95
100
- public function test_simple_queries_with_complexe_select_are_not_wrapped ()
96
+ public function test_simple_queries_with_complexe_where_are_not_wrapped ()
101
97
{
102
98
/** @var \Yajra\DataTables\QueryDataTable $dataTable */
103
99
$ dataTable = app ('datatables ' )->of (
104
100
DB ::table ('users ' )
105
101
->select ('users.* ' )
106
- ->addSelect ([
107
- ' last_post_id ' => DB ::table ('posts ' )
102
+ ->where (
103
+ DB ::table ('posts ' )
108
104
->whereColumn ('posts.user_id ' , 'users.id ' )
109
105
->orderBy ('created_at ' )
110
- ->select ('id ' ),
111
- ] )
106
+ ->select ('title ' ), ' User-1 Post-1 '
107
+ )
112
108
);
113
109
114
110
$ this ->assertQueryWrapped (false , $ dataTable ->prepareCountQuery ());
115
- $ this ->assertEquals (20 , $ dataTable ->count ());
111
+ $ this ->assertEquals (1 , $ dataTable-> prepareCountQuery () ->count ());
116
112
}
117
113
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 ()
119
115
{
120
116
/** @var \Yajra\DataTables\QueryDataTable $dataTable */
121
117
$ dataTable = app ('datatables ' )->of (
122
- DB :: table ( ' users ' )
118
+ User:: query ( )
123
119
->select ('users.* ' )
124
120
->where (
125
121
DB ::table ('posts ' )
@@ -157,10 +153,10 @@ public function test_complexe_queries_can_be_wrapped_and_countable()
157
153
158
154
/**
159
155
* @param $expected bool
160
- * @param $query \Illuminate\Database\Eloquent\Builder|\Illuminate \Database\Query\Builder
156
+ * @param $query \Illuminate\Contracts \Database\Query\Builder
161
157
* @return void
162
158
*/
163
- protected function assertQueryWrapped ($ expected , $ query )
159
+ protected function assertQueryWrapped ($ expected , $ query ): void
164
160
{
165
161
$ sql = $ query ->toSql ();
166
162
@@ -169,10 +165,10 @@ protected function assertQueryWrapped($expected, $query)
169
165
170
166
/**
171
167
* @param $expected bool
172
- * @param $query \Illuminate\Database\Eloquent\Builder|\Illuminate \Database\Query\Builder
168
+ * @param $query \Illuminate\Contracts \Database\Query\Builder
173
169
* @return void
174
170
*/
175
- public function assertQueryHasNoSelect ($ expected , $ query )
171
+ public function assertQueryHasNoSelect ($ expected , $ query ): void
176
172
{
177
173
$ sql = $ query ->select (DB ::raw ('count(*) ' ))->toSql ();
178
174
0 commit comments