summaryrefslogtreecommitdiff
path: root/tests/Unit/SortDirectionsTest.php
diff options
context:
space:
mode:
authorSam Light <samlight1994@gmail.com>2026-07-27 22:28:18 +0100
committerSam Light <samlight1994@gmail.com>2026-07-27 22:28:18 +0100
commit1dc1088933c906d4676056d53395d34ce0a68d01 (patch)
treeb3c39b1e58305e2b0985678b720991883372667f /tests/Unit/SortDirectionsTest.php
parent827a53363e7a03329d6e5972d9d9be99d17c889e (diff)
changed to use sort directionHEADv3.0.0master
Diffstat (limited to 'tests/Unit/SortDirectionsTest.php')
-rw-r--r--tests/Unit/SortDirectionsTest.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/Unit/SortDirectionsTest.php b/tests/Unit/SortDirectionsTest.php
new file mode 100644
index 0000000..c63d5bb
--- /dev/null
+++ b/tests/Unit/SortDirectionsTest.php
@@ -0,0 +1,30 @@
+<?php
+
+use Lightscale\LaralightTables\Support\SortDirections;
+
+describe('SortDirections', function () {
+ it('converts the enum to a query builder direction', function () {
+ expect(SortDirections::value(SortDirection::Ascending))->toBe('asc');
+ expect(SortDirections::value(SortDirection::Descending))->toBe('desc');
+ });
+
+ it('resolves strings to the enum', function () {
+ expect(SortDirections::tryFrom('asc'))->toBe(SortDirection::Ascending);
+ expect(SortDirections::tryFrom('desc'))->toBe(SortDirection::Descending);
+ });
+
+ it('resolves strings case insensitively', function () {
+ expect(SortDirections::tryFrom('ASC'))->toBe(SortDirection::Ascending);
+ expect(SortDirections::tryFrom('Desc'))->toBe(SortDirection::Descending);
+ });
+
+ it('passes an enum straight through', function () {
+ expect(SortDirections::tryFrom(SortDirection::Descending))->toBe(SortDirection::Descending);
+ });
+
+ it('resolves null and unrecognised values to null', function () {
+ expect(SortDirections::tryFrom(null))->toBeNull();
+ expect(SortDirections::tryFrom(''))->toBeNull();
+ expect(SortDirections::tryFrom('nonsense'))->toBeNull();
+ });
+});