From 28b6700dce4c59cae522c967602d1d95989f4325 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Tue, 28 Nov 2023 09:57:46 +1000 Subject: [PATCH 1/5] Make QA tools available by default Signed-off-by: Aleksei Khudiakov --- .gitignore | 5 +++-- composer.json | 32 ++++++++++++++++++-------------- phpcs.xml | 2 ++ phpunit.xml.dist | 20 ++++++++++++++------ psalm.xml | 7 ++++++- 5 files changed, 43 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 465f9c7..bf2ae9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ -.vagrant/ +/.phpcs-cache +/.phpunit.cache +/.psalm-cache vendor/ config/development.config.php data/cache/* !data/cache/.gitkeep phpunit.xml composer.lock -.phpunit.result.cache diff --git a/composer.json b/composer.json index bcdf3c6..2beaef6 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,18 @@ ], "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", - "laminas/laminas-component-installer": "^3.2", - "laminas/laminas-development-mode": "^3.10", - "laminas/laminas-skeleton-installer": "^1.2", - "laminas/laminas-mvc": "^3.6.0" + "laminas/laminas-component-installer": "^3.4.0", + "laminas/laminas-development-mode": "^3.12.0", + "laminas/laminas-mvc": "^3.7.0", + "laminas/laminas-skeleton-installer": "^1.3.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "laminas/laminas-test": "^4.9", + "phpunit/phpunit": "^10.4", + "psalm/plugin-phpunit": "^0.18.4", + "squizlabs/php_codesniffer": "^3.7", + "vimeo/psalm": "^5.13" }, "autoload": { "psr-4": { @@ -87,12 +95,6 @@ "prompt": "Would you like to install sessions support?", "module": true }, - { - "name": "laminas/laminas-test", - "constraint": "^4.7.0", - "prompt": "Would you like to install MVC testing tools for testing support?", - "dev": true - }, { "name": "laminas/laminas-di", "constraint": "^3.12.0", @@ -111,8 +113,7 @@ "post-create-project-cmd": [ "@development-enable", "php bin/update-gitignore.php", - "php -r 'if (file_exists(\"bin/remove-package-artifacts.php\")) include \"bin/remove-package-artifacts.php\";'", - "php -r 'if (file_exists(\"CHANGELOG.md\")) unlink(\"CHANGELOG.md\");'" + "php -r 'if (file_exists(\"bin/remove-package-artifacts.php\")) include \"bin/remove-package-artifacts.php\";'" ], "post-install-cmd": "@clear-config-cache", "post-update-cmd": "@clear-config-cache", @@ -121,7 +122,7 @@ "php -S 0.0.0.0:8080 -t public" ], "test": "vendor/bin/phpunit", - "static-analysis": "vendor/bin/psalm --shepherd --stats" + "static-analysis": "vendor/bin/psalm --stats" }, "scripts-descriptions": { "clear-config-cache": "Clears merged config cache. Required for config changes to be applied.", @@ -131,12 +132,15 @@ "development-enable": "Enable development mode.", "development-status": "Detail whether or not the application is in development mode.", "serve": "Start the built-in PHP web server and serve the application.", + "static-analysis": "Run static analysis tool Psalm.", "test": "Run unit tests." }, "config": { + "sort-packages": true, "allow-plugins": { "laminas/laminas-component-installer": true, - "laminas/laminas-skeleton-installer": true + "laminas/laminas-skeleton-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true } } } diff --git a/phpcs.xml b/phpcs.xml index cb4ec5a..4ba621a 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -30,6 +30,8 @@ *.phtml + config/* + public/index.php *.phtml diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 43aceff..ac61a8a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,22 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" + bootstrap="vendor/autoload.php" + cacheDirectory=".phpunit.cache" + displayDetailsOnIncompleteTests="true" + displayDetailsOnSkippedTests="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnTestsThatTriggerErrors="true" + displayDetailsOnTestsThatTriggerNotices="true" + displayDetailsOnTestsThatTriggerWarnings="true" + colors="true" +> + ./module/*/src - + diff --git a/psalm.xml b/psalm.xml index 681e467..dec1ac3 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,10 +1,15 @@ + From c2f484770e0ec51428eef5def1241c6d3e5ace49 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Tue, 28 Nov 2023 11:30:00 +1000 Subject: [PATCH 2/5] Apply changes to reach green psalm Signed-off-by: Aleksei Khudiakov --- config/container.php | 4 +++- module/Application/test/ModuleTest.php | 23 +++++++++++++++++++++++ psalm.xml | 4 ++++ public/index.php | 7 ++++--- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 module/Application/test/ModuleTest.php diff --git a/config/container.php b/config/container.php index ec8cb42..117b945 100644 --- a/config/container.php +++ b/config/container.php @@ -6,7 +6,9 @@ // Retrieve configuration $appConfig = require __DIR__ . '/application.config.php'; if (file_exists(__DIR__ . '/development.config.php')) { - $appConfig = ArrayUtils::merge($appConfig, require __DIR__ . '/development.config.php'); + /** @var array $devConfig */ + $devConfig = require __DIR__ . '/development.config.php'; + $appConfig = ArrayUtils::merge($appConfig, $devConfig); } return Application::init($appConfig) diff --git a/module/Application/test/ModuleTest.php b/module/Application/test/ModuleTest.php new file mode 100644 index 0000000..d4368d6 --- /dev/null +++ b/module/Application/test/ModuleTest.php @@ -0,0 +1,23 @@ +getConfig(); + + self::assertArrayHasKey('router', $config); + self::assertArrayHasKey('controllers', $config); + } +} diff --git a/psalm.xml b/psalm.xml index dec1ac3..c9e2e08 100644 --- a/psalm.xml +++ b/psalm.xml @@ -37,6 +37,10 @@ + + + + diff --git a/public/index.php b/public/index.php index d5bb012..6bd404c 100644 --- a/public/index.php +++ b/public/index.php @@ -12,7 +12,7 @@ // Decline static file requests back to the PHP built-in webserver if (php_sapi_name() === 'cli-server') { - $path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); + $path = realpath(__DIR__ . parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH)); if (is_string($path) && __FILE__ !== $path && is_file($path)) { return false; } @@ -32,5 +32,6 @@ $container = require __DIR__ . '/../config/container.php'; // Run the application! -$container->get('Application') - ->run(); +/** @var Application $app */ +$app = $container->get('Application'); +$app->run(); From b55dd0ea96ad246d67a80ecdeacd543fdf269591 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Tue, 28 Nov 2023 11:49:13 +1000 Subject: [PATCH 3/5] Add psalm and phpstorm stubs for ContainerInterface Signed-off-by: Aleksei Khudiakov --- .phpstorm.meta.php | 8 ++++++++ .psalm-stubs.meta.php | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 .phpstorm.meta.php create mode 100644 .psalm-stubs.meta.php diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php new file mode 100644 index 0000000..2ed7926 --- /dev/null +++ b/.phpstorm.meta.php @@ -0,0 +1,8 @@ +|string $id + * @return ( + * $id is class-string + * ? T + * : mixed + * ) + */ + public function get(string $id): mixed; + } +} From 403dd255a0156ab2685326e00ff0d2cef5a840fb Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Tue, 28 Nov 2023 11:55:29 +1000 Subject: [PATCH 4/5] Reenable continous integration workflow Signed-off-by: Aleksei Khudiakov --- .gitattributes | 2 +- .github/workflows/continuous-integration.yml | 33 ++++++++++++++++++++ laminas-ci.json | 8 +++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/continuous-integration.yml create mode 100644 laminas-ci.json diff --git a/.gitattributes b/.gitattributes index f966b98..7af1a68 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,3 @@ /.github/ export-ignore /bin/remove-package-artifacts.php export-ignore -/CHANGELOG.md +/laminas-ci.json export-ignore diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..fe5f1b4 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,33 @@ +name: "Continuous Integration" + +on: + pull_request: + push: + branches: + - '[0-9]+.[0-9]+.x' + - 'refs/pull/*' + tags: + +jobs: + matrix: + name: Generate job matrix + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.matrix.outputs.matrix }} + steps: + - name: Gather CI configuration + id: matrix + uses: laminas/laminas-ci-matrix-action@v1 + + qa: + name: QA Checks + needs: [matrix] + runs-on: ${{ matrix.operatingSystem }} + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }} + steps: + - name: ${{ matrix.name }} + uses: laminas/laminas-continuous-integration-action@v1 + with: + job: ${{ matrix.job }} \ No newline at end of file diff --git a/laminas-ci.json b/laminas-ci.json new file mode 100644 index 0000000..64be8c2 --- /dev/null +++ b/laminas-ci.json @@ -0,0 +1,8 @@ +{ + "additional_composer_arguments": [ + "--no-scripts", + "--no-plugins" + ], + "ignore_php_platform_requirements": { + } +} \ No newline at end of file From c4f109067cb8019e30ece161e8de4ea542710f0a Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Wed, 29 Nov 2023 00:41:36 +1000 Subject: [PATCH 5/5] Use same extension for psalm stubs as psalm itself Signed-off-by: Aleksei Khudiakov --- .psalm-stubs.meta.php => .psalm-stubs.phpstub | 0 psalm.xml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .psalm-stubs.meta.php => .psalm-stubs.phpstub (100%) diff --git a/.psalm-stubs.meta.php b/.psalm-stubs.phpstub similarity index 100% rename from .psalm-stubs.meta.php rename to .psalm-stubs.phpstub diff --git a/psalm.xml b/psalm.xml index c9e2e08..4bd5722 100644 --- a/psalm.xml +++ b/psalm.xml @@ -38,7 +38,7 @@ - +