@@ -27,20 +27,24 @@ public function setUp()
2727 /** @test */
2828 public function it_can_sort_a_collection_ascending ()
2929 {
30+ \DB ::enableQueryLog ();
3031 $ sortedModels = $ this
3132 ->createQueryFromSortRequest ('name ' )
3233 ->get ();
3334
35+ $ this ->assertSame (\DB ::getQueryLog ()[0 ]['query ' ], 'select "test_models".* from "test_models" order by "name" asc ' );
3436 $ this ->assertSortedAscending ($ sortedModels , 'name ' );
3537 }
3638
3739 /** @test */
3840 public function it_can_sort_a_collection_descending ()
3941 {
42+ \DB ::enableQueryLog ();
4043 $ sortedModels = $ this
4144 ->createQueryFromSortRequest ('-name ' )
4245 ->get ();
4346
47+ $ this ->assertSame (\DB ::getQueryLog ()[0 ]['query ' ], 'select "test_models".* from "test_models" order by "name" desc ' );
4448 $ this ->assertSortedDescending ($ sortedModels , 'name ' );
4549 }
4650
@@ -89,22 +93,26 @@ public function it_wont_sort_if_no_sort_query_parameter_is_given()
8993 /** @test */
9094 public function it_uses_default_sort_parameter ()
9195 {
96+ \DB ::enableQueryLog ();
9297 $ sortedModels = QueryBuilder::for (TestModel::class, new Request ())
9398 ->allowedSorts ('name ' )
9499 ->defaultSort ('name ' )
95100 ->get ();
96101
102+ $ this ->assertSame (\DB ::getQueryLog ()[0 ]['query ' ], 'select "test_models".* from "test_models" order by "name" asc ' );
97103 $ this ->assertSortedAscending ($ sortedModels , 'name ' );
98104 }
99105
100106 /** @test */
101107 public function it_can_allow_multiple_sort_parameters ()
102108 {
109+ \DB ::enableQueryLog ();
103110 $ sortedModels = $ this
104111 ->createQueryFromSortRequest ('name ' )
105112 ->allowedSorts ('id ' , 'name ' )
106113 ->get ();
107114
115+ $ this ->assertSame (\DB ::getQueryLog ()[0 ]['query ' ], 'select "test_models".* from "test_models" order by "name" asc ' );
108116 $ this ->assertSortedAscending ($ sortedModels , 'name ' );
109117 }
110118
@@ -123,14 +131,15 @@ public function it_can_allow_multiple_sort_parameters_as_an_array()
123131 public function it_can_sort_by_multiple_columns ()
124132 {
125133 factory (TestModel::class, 3 )->create (['name ' => 'foo ' ]);
134+ \DB ::enableQueryLog ();
126135
127136 $ sortedModels = $ this
128137 ->createQueryFromSortRequest ('name,-id ' )
129138 ->allowedSorts ('name ' , 'id ' )
130139 ->get ();
131140
132141 $ expected = TestModel::orderBy ('name ' )->orderByDesc ('id ' );
133-
142+ $ this -> assertSame (\ DB :: getQueryLog ()[ 0 ][ ' query ' ], ' select "test_models".* from "test_models" order by "name" asc, "id" desc ' );
134143 $ this ->assertEquals ($ expected ->pluck ('id ' ), $ sortedModels ->pluck ('id ' ));
135144 }
136145
0 commit comments