From d2557596c67877ec9f6f492316dee544c2117c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Fri, 22 Nov 2024 18:05:31 +0100 Subject: [PATCH] tests --- composer.lock | 34 +++++++++--------- tests/Filters/MediaSearchTest.php | 19 ++++++++++ tests/Filters/SearchTest.php | 31 ++++++++++++++++ .../{SelectFilterTest.php => SelectTest.php} | 2 +- tests/Filters/SortTest.php | 36 +++++++++++++++++++ tests/User.php | 2 +- 6 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 tests/Filters/MediaSearchTest.php create mode 100644 tests/Filters/SearchTest.php rename tests/Filters/{SelectFilterTest.php => SelectTest.php} (97%) create mode 100644 tests/Filters/SortTest.php diff --git a/composer.lock b/composer.lock index 9079f301..0aa00984 100644 --- a/composer.lock +++ b/composer.lock @@ -2118,31 +2118,31 @@ }, { "name": "nunomaduro/termwind", - "version": "v2.2.0", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/nunomaduro/termwind.git", - "reference": "42c84e4e8090766bbd6445d06cd6e57650626ea3" + "reference": "52915afe6a1044e8b9cee1bcff836fb63acf9cda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/termwind/zipball/42c84e4e8090766bbd6445d06cd6e57650626ea3", - "reference": "42c84e4e8090766bbd6445d06cd6e57650626ea3", + "url": "https://api.github.com/repos/nunomaduro/termwind/zipball/52915afe6a1044e8b9cee1bcff836fb63acf9cda", + "reference": "52915afe6a1044e8b9cee1bcff836fb63acf9cda", "shasum": "" }, "require": { "ext-mbstring": "*", "php": "^8.2", - "symfony/console": "^7.1.5" + "symfony/console": "^7.1.8" }, "require-dev": { - "illuminate/console": "^11.28.0", - "laravel/pint": "^1.18.1", + "illuminate/console": "^11.33.2", + "laravel/pint": "^1.18.2", "mockery/mockery": "^1.6.12", "pestphp/pest": "^2.36.0", - "phpstan/phpstan": "^1.12.6", + "phpstan/phpstan": "^1.12.11", "phpstan/phpstan-strict-rules": "^1.6.1", - "symfony/var-dumper": "^7.1.5", + "symfony/var-dumper": "^7.1.8", "thecodingmachine/phpstan-strict-rules": "^1.0.0" }, "type": "library", @@ -2185,7 +2185,7 @@ ], "support": { "issues": "https://github.com/nunomaduro/termwind/issues", - "source": "https://github.com/nunomaduro/termwind/tree/v2.2.0" + "source": "https://github.com/nunomaduro/termwind/tree/v2.3.0" }, "funding": [ { @@ -2201,7 +2201,7 @@ "type": "github" } ], - "time": "2024-10-15T16:15:16+00:00" + "time": "2024-11-21T10:39:51+00:00" }, { "name": "phpoption/phpoption", @@ -5414,16 +5414,16 @@ "packages-dev": [ { "name": "fakerphp/faker", - "version": "v1.24.0", + "version": "v1.24.1", "source": { "type": "git", "url": "https://github.com/FakerPHP/Faker.git", - "reference": "a136842a532bac9ecd8a1c723852b09915d7db50" + "reference": "e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/a136842a532bac9ecd8a1c723852b09915d7db50", - "reference": "a136842a532bac9ecd8a1c723852b09915d7db50", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5", + "reference": "e0ee18eb1e6dc3cda3ce9fd97e5a0689a88a64b5", "shasum": "" }, "require": { @@ -5471,9 +5471,9 @@ ], "support": { "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.24.0" + "source": "https://github.com/FakerPHP/Faker/tree/v1.24.1" }, - "time": "2024-11-07T15:11:20+00:00" + "time": "2024-11-21T13:46:39+00:00" }, { "name": "hamcrest/hamcrest-php", diff --git a/tests/Filters/MediaSearchTest.php b/tests/Filters/MediaSearchTest.php new file mode 100644 index 00000000..36430141 --- /dev/null +++ b/tests/Filters/MediaSearchTest.php @@ -0,0 +1,19 @@ +assertSame( + ['file_name' => null, 'name' => null], + $filter->getSearchableAttributes() + ); + } +} diff --git a/tests/Filters/SearchTest.php b/tests/Filters/SearchTest.php new file mode 100644 index 00000000..000e17e4 --- /dev/null +++ b/tests/Filters/SearchTest.php @@ -0,0 +1,31 @@ +assertSame( + 'select * from "users" where "users"."deleted_at" is null', + $filter->apply($this->app['request'], User::query(), null)->toRawSql() + ); + + $this->assertSame( + 'select * from "users" where ("users"."name" like \'%foo%\' or exists (select * from "teams" inner join "team_user" on "teams"."id" = "team_user"."team_id" where "users"."id" = "team_user"."user_id" and "teams"."id" like \'%foo%\')) and "users"."deleted_at" is null', + $filter->apply($this->app['request'], User::query(), 'foo')->toRawSql() + ); + } +} diff --git a/tests/Filters/SelectFilterTest.php b/tests/Filters/SelectTest.php similarity index 97% rename from tests/Filters/SelectFilterTest.php rename to tests/Filters/SelectTest.php index dfde5f9f..e73fa84c 100644 --- a/tests/Filters/SelectFilterTest.php +++ b/tests/Filters/SelectTest.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; -class SelectFilterTest extends TestCase +class SelectTest extends TestCase { protected Select $filter; diff --git a/tests/Filters/SortTest.php b/tests/Filters/SortTest.php new file mode 100644 index 00000000..2ee05397 --- /dev/null +++ b/tests/Filters/SortTest.php @@ -0,0 +1,36 @@ +sortable(), + MorphTo::make('Employer')->sortable(column: 'name'), + ])); + + $this->assertSame( + 'select * from "users" where "users"."deleted_at" is null', + $filter->apply($this->app['request'], User::query(), ['by' => 'dummy'])->toRawSql() + ); + + $this->assertSame( + 'select * from "users" where "users"."deleted_at" is null order by "users"."name" desc', + $filter->apply($this->app['request'], User::query(), ['by' => 'name'])->toRawSql() + ); + + $this->assertSame( + 'select * from "users" where "users"."deleted_at" is null order by (select "users"."name" from "users" where "users"."employer_id" = "users"."id" and "users"."deleted_at" is null) desc', + $filter->apply($this->app['request'], User::query(), ['by' => 'employer'])->toRawSql() + ); + } +} diff --git a/tests/User.php b/tests/User.php index df139595..d465e2f4 100644 --- a/tests/User.php +++ b/tests/User.php @@ -71,7 +71,7 @@ public function teams(): BelongsToMany public function employer(): MorphTo { - return $this->morphTo(); + return $this->morphTo(ownerKey: 'id'); } public function shouldTwoFactorAuthenticate(Request $request): bool