Skip to content

Commit

Permalink
Improve testing for CaseSort by checking generated SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
luilliarcec committed Oct 8, 2023
1 parent c23bc3d commit 131cea9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/Sorts/CaseSortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
AllowedSort::custom('classification', new CaseSort($cases)),
]);

expect($queryBuilder->get())
expect($queryBuilder->toSql())
->toBe(
"select * from `books` order by case when books.classification = 1 then 'SuitableForAll' when books.classification = 2 then 'Kids' when books.classification = 3 then 'OverTwelveYearsOld' when books.classification = 4 then 'Adults' end asc"
)
->and($queryBuilder->get())
->sequence(
fn ($book) => $book->classification->toBe(BookClassificationEnum::Adults),
fn ($book) => $book->classification->toBe(BookClassificationEnum::OverTwelveYearsOld),
Expand All @@ -63,7 +67,11 @@
AllowedSort::custom('classification', new CaseSort($cases)),
]);

expect($queryBuilder->get())
expect($queryBuilder->toSql())
->toBe(
"select * from `books` order by case when books.classification = 1 then 'SuitableForAll' when books.classification = 2 then 'Kids' when books.classification = 3 then 'OverTwelveYearsOld' when books.classification = 4 then 'Adults' end desc"
)
->and($queryBuilder->get())
->sequence(
fn ($book) => $book->classification->toBe(BookClassificationEnum::OverTwelveYearsOld),
fn ($book) => $book->classification->toBe(BookClassificationEnum::Adults),
Expand Down

0 comments on commit 131cea9

Please sign in to comment.