From 17c68325de6715c76ef93877fe11eaad0c9cf21c Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Sat, 20 Apr 2024 17:09:59 -0400 Subject: [PATCH 1/5] Fix issue with sprunje using multiple listable fetched from database https://chat.userfrosting.com/channel/support?msg=sgMq8sbAjsCN2ZGXj --- CHANGELOG.md | 3 +++ app/src/Sprunje/Sprunje.php | 5 ++++- app/tests/Integration/Sprunje/SprunjeTest.php | 21 ++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01a4abc4..4d7ef561 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [5.1.1](https://github.com/userfrosting/sprinkle-core/compare/5.1.0...5.1.1) +- Fix issue with sprunje using multiple listable fetched from database ([Chat Reference](https://chat.userfrosting.com/channel/support?msg=sgMq8sbAjsCN2ZGXj)) + ## [5.1.0](https://github.com/userfrosting/sprinkle-core/compare/5.0.1...5.1.0) - Drop PHP 8.1 support, add PHP 8.3 support - Update to Laravel 10 diff --git a/app/src/Sprunje/Sprunje.php b/app/src/Sprunje/Sprunje.php index 6f8cd825..b9335a3f 100644 --- a/app/src/Sprunje/Sprunje.php +++ b/app/src/Sprunje/Sprunje.php @@ -647,8 +647,11 @@ abstract protected function baseQuery(); */ protected function getColumnValues(string $column): array { + // Clone query, so we don't modify the initial one + $query = clone $this->query; + /** @var Collection */ - $rawValues = $this->query->select($column) + $rawValues = $query->select($column) ->distinct() ->orderBy($column, 'asc') ->get(); diff --git a/app/tests/Integration/Sprunje/SprunjeTest.php b/app/tests/Integration/Sprunje/SprunjeTest.php index 93de66cb..100f653d 100644 --- a/app/tests/Integration/Sprunje/SprunjeTest.php +++ b/app/tests/Integration/Sprunje/SprunjeTest.php @@ -33,16 +33,20 @@ class SprunjeTest extends CoreTestCase { /** @var mixed[] */ protected array $listable = [ + 'type' => [ + ['value' => 1, 'text' => 'TYPE A'], + ['value' => 2, 'text' => 'TYPE B'], + ], 'name' => [ // N.B.: Values are sorted automatically ['value' => 'bar', 'text' => 'bar'], ['value' => 'foo', 'text' => 'foo'], ['value' => 'foobar', 'text' => 'foobar'], ], - 'type' => [ - ['value' => 1, 'text' => 'TYPE A'], - ['value' => 2, 'text' => 'TYPE B'], - ], + 'active' => [ + ['value' => false, 'text' => false], + ['value' => true, 'text' => true], + ] ]; public function setUp(): void @@ -203,11 +207,11 @@ public function testWithCustomSort(): void public function testWithSortException(): void { $sprunje = new TestSprunje([ - 'sorts' => ['description' => 'desc'], + 'sorts' => ['active' => 'desc'], ]); $this->expectException(SprunjeException::class); - $this->expectExceptionMessage('Bad sort: description'); + $this->expectExceptionMessage('Bad sort: active'); $sprunje->getArray(); } @@ -491,11 +495,14 @@ class TestSprunje extends Sprunje protected array $sortable = [ 'id', 'name', + 'description', + 'type', ]; protected array $listable = [ - 'name', 'type', + 'name', + 'active', ]; protected function baseQuery() From 5c163cfff767a794f63b903fe5809ce02d831cde Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Fri, 26 Apr 2024 20:21:09 -0400 Subject: [PATCH 2/5] Update PHPStan config --- .github/workflows/PHPStan.yml | 2 +- phpstan.neon | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/PHPStan.yml b/.github/workflows/PHPStan.yml index d16e6266..f7e8cc18 100644 --- a/.github/workflows/PHPStan.yml +++ b/.github/workflows/PHPStan.yml @@ -30,4 +30,4 @@ jobs: run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Run PHPStan - run: vendor/bin/phpstan analyse app/src/ app/tests/ + run: vendor/bin/phpstan analyse diff --git a/phpstan.neon b/phpstan.neon index 9c246679..9c2d8e88 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,8 @@ parameters: level: 8 + paths: + - app/src/ + - app/tests/ reportUnmatchedIgnoredErrors: false ignoreErrors: - '#Dynamic call to static method PHPUnit\\Framework\\.*#' From 701f05c91bfd4221045ec22e863e55352dd4d975 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Sat, 27 Apr 2024 20:03:52 -0400 Subject: [PATCH 3/5] Update metadata --- .github/FUNDING.yml | 12 --------- .github/ISSUE_TEMPLATE.md | 2 -- .gitignore | 5 ---- .vscode/extensions.json | 9 +++++++ .vscode/launch.json | 15 ++++++++++++ .vscode/tasks.json | 43 +++++++++++++++++++++++++++++++++ README.md | 4 +-- STYLE-GUIDE.md | 51 --------------------------------------- 8 files changed, 69 insertions(+), 72 deletions(-) delete mode 100644 .github/FUNDING.yml delete mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json delete mode 100644 STYLE-GUIDE.md diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 7a2e0ce7..00000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,12 +0,0 @@ -# These are supported funding model platforms - -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: # Replace with a single Patreon username -open_collective: userfrosting # Replace with a single Open Collective username -ko_fi: lcharette # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 2ab6792f..00000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,2 +0,0 @@ -🛑 STOP! -Issues should be opened on the main repo : https://github.com/userfrosting/UserFrosting/issues diff --git a/.gitignore b/.gitignore index 0bb94e4c..a1135354 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,3 @@ -# Ignores text editor metadata -*.komodoproject -.editorconfig -.vscode - # Ignores Mac metadata. You can configure this globally if you use a Mac: http://islegend.com/development/setting-global-gitignore-mac-windows/ .DS_Store diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..de32a0c6 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,9 @@ +{ + "recommendations": [ + "junstyle.php-cs-fixer", + "xdebug.php-debug", + "neilbrayfield.php-docblocker", + "bmewburn.vscode-intelephense-client", + "sanderronde.phpstan-vscode" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..53f00dd6 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for XDebug", + "type": "php", + "request": "launch", + "port": 9000, + "log": false, + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..7d998236 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,43 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "PHPUnit", + "type": "shell", + "options": { + "env": { + "XDEBUG_CONFIG": "idekey=VSCODE" + } + }, + "command": "printf '\\33c\\e[3J' && vendor/bin/phpunit --stop-on-error --stop-on-failure", // + // "command": "printf '\\33c\\e[3J' && vendor/bin/phpunit --filter SprunjeTest --stop-on-error --stop-on-failure", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "PHP CS Fixer", + "type": "shell", + "options": {}, + "command": "vendor/bin/php-cs-fixer fix", + "problemMatcher": [], + }, + { + "label": "Serve", + "type": "shell", + "options": {}, + "command": "php bakery serve", + "problemMatcher": [], + }, + { + "label": "PHPStan", + "type": "shell", + "command": "vendor/bin/phpstan analyse", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 6ac986f8..f5ec0c3d 100644 --- a/README.md +++ b/README.md @@ -80,10 +80,10 @@ See main [UserFrosting Documentation](https://learn.userfrosting.com) for more i - [Changelog](CHANGELOG.md) - [Issues](https://github.com/userfrosting/UserFrosting/issues) - [License](LICENSE.md) -- [Style Guide](STYLE-GUIDE.md) +- [Style Guide](https://github.com/userfrosting/.github/blob/main/.github/STYLE-GUIDE.md) ## Contributing -This project exists thanks to all the people who contribute. If you're interested in contributing to the UserFrosting codebase, please see our [contributing guidelines](https://github.com/userfrosting/UserFrosting/blob/5.1/.github/CONTRIBUTING.md) as well as our [style guidelines](.github/STYLE-GUIDE.md). +This project exists thanks to all the people who contribute. If you're interested in contributing to the UserFrosting codebase, please see our [contributing guidelines](https://github.com/userfrosting/.github/blob/main/.github/CONTRIBUTING.md) as well as our [style guidelines](https://github.com/userfrosting/.github/blob/main/.github/STYLE-GUIDE.md). [![](https://opencollective.com/userfrosting/contributors.svg?width=890&button=true)](https://github.com/userfrosting/sprinkle-core/graphs/contributors) diff --git a/STYLE-GUIDE.md b/STYLE-GUIDE.md deleted file mode 100644 index 0b3d368d..00000000 --- a/STYLE-GUIDE.md +++ /dev/null @@ -1,51 +0,0 @@ -# Style guide for contributing to UserFrosting - -## PHP - -All PHP contributions must adhere to [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-2](http://www.php-fig.org/psr/psr-2/) specifications. - -In addition: - -### Documentation - -- All documentation blocks must adhere to the [PHPDoc](https://phpdoc.org/) format and syntax. -- All PHP files MUST contain the following documentation block immediately after the opening ` Date: Fri, 21 Jun 2024 22:31:54 -0400 Subject: [PATCH 4/5] Fix slim App type hints --- app/src/Csrf/CsrfGuard.php | 7 +++++++ app/src/Listeners/SetRouteCaching.php | 2 +- app/src/Util/RouteList.php | 5 +++++ app/tests/Integration/Util/RouteParserTest.php | 2 +- app/tests/Unit/Listeners/SetRouteCachingTest.php | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/Csrf/CsrfGuard.php b/app/src/Csrf/CsrfGuard.php index 9de148a4..373c2d24 100644 --- a/app/src/Csrf/CsrfGuard.php +++ b/app/src/Csrf/CsrfGuard.php @@ -30,6 +30,13 @@ */ class CsrfGuard extends Guard { + /** + * Overwrites the default constructor to inject dependencies + * + * @param Config $config + * @param Session $session + * @param App<\DI\Container> $app + */ public function __construct( protected Config $config, Session $session, diff --git a/app/src/Listeners/SetRouteCaching.php b/app/src/Listeners/SetRouteCaching.php index 3ca2b3da..f91cbc5b 100755 --- a/app/src/Listeners/SetRouteCaching.php +++ b/app/src/Listeners/SetRouteCaching.php @@ -31,7 +31,7 @@ class SetRouteCaching * * @param Config $config * @param ResourceLocatorInterface $locator - * @param App $app + * @param App<\DI\Container> $app */ public function __construct( protected Config $config, diff --git a/app/src/Util/RouteList.php b/app/src/Util/RouteList.php index 151cdccf..c95faaac 100644 --- a/app/src/Util/RouteList.php +++ b/app/src/Util/RouteList.php @@ -23,6 +23,11 @@ */ class RouteList { + /** + * Inject dependencies + * + * @param App<\DI\Container> $app + */ public function __construct(protected App $app) { } diff --git a/app/tests/Integration/Util/RouteParserTest.php b/app/tests/Integration/Util/RouteParserTest.php index 527b8b90..163349a8 100644 --- a/app/tests/Integration/Util/RouteParserTest.php +++ b/app/tests/Integration/Util/RouteParserTest.php @@ -36,7 +36,7 @@ public function setUp(): void { parent::setUp(); - /** @var App */ + /** @var App<\DI\Container> */ $app = $this->ci->get(App::class); $collector = $app->getRouteCollector(); $collector->setBasePath('/Myfoo'); diff --git a/app/tests/Unit/Listeners/SetRouteCachingTest.php b/app/tests/Unit/Listeners/SetRouteCachingTest.php index 9017138b..cdffb641 100644 --- a/app/tests/Unit/Listeners/SetRouteCachingTest.php +++ b/app/tests/Unit/Listeners/SetRouteCachingTest.php @@ -44,7 +44,7 @@ public function testSetRouteCaching(): void ->shouldReceive('setCacheFile')->with('/foo/route.cache')->once() ->getMock(); - /** @var App */ + /** @var App<\DI\Container> */ $app = Mockery::mock(App::class) ->shouldReceive('getRouteCollector')->once()->andReturn($collector) ->getMock(); From 17a5bef2ae6df7168305b51553b00c40c2650d9c Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 22 Jun 2024 02:32:13 +0000 Subject: [PATCH 5/5] Apply fixes from StyleCI --- app/src/Csrf/CsrfGuard.php | 2 +- app/src/Util/RouteList.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/Csrf/CsrfGuard.php b/app/src/Csrf/CsrfGuard.php index 373c2d24..bee6ed27 100644 --- a/app/src/Csrf/CsrfGuard.php +++ b/app/src/Csrf/CsrfGuard.php @@ -31,7 +31,7 @@ class CsrfGuard extends Guard { /** - * Overwrites the default constructor to inject dependencies + * Overwrites the default constructor to inject dependencies. * * @param Config $config * @param Session $session diff --git a/app/src/Util/RouteList.php b/app/src/Util/RouteList.php index c95faaac..de3f62e8 100644 --- a/app/src/Util/RouteList.php +++ b/app/src/Util/RouteList.php @@ -24,7 +24,7 @@ class RouteList { /** - * Inject dependencies + * Inject dependencies. * * @param App<\DI\Container> $app */