Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make QA tools available by default #81

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/.github/ export-ignore
/bin/remove-package-artifacts.php export-ignore
/CHANGELOG.md
/laminas-ci.json export-ignore
33 changes: 33 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace PHPSTORM_META {
override(
\Psr\Container\ContainerInterface::get(0),
map(['@'])
);
}
17 changes: 17 additions & 0 deletions .psalm-stubs.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Psr\Container {
interface ContainerInterface
{
/**
* @psalm-template T of object
* @psalm-param class-string<T>|string $id
* @return (
* $id is class-string<T>
* ? T
* : mixed
* )
*/
public function get(string $id): mixed;
}
}
32 changes: 18 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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.",
Expand All @@ -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
}
}
}
4 changes: 3 additions & 1 deletion config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"additional_composer_arguments": [
"--no-scripts",
"--no-plugins"
],
"ignore_php_platform_requirements": {
}
}
23 changes: 23 additions & 0 deletions module/Application/test/ModuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace ApplicationTest;

use Application\Module;
use PHPUnit\Framework\TestCase;

/**
* @covers \Application\Module;
*/
class ModuleTest extends TestCase
froschdesign marked this conversation as resolved.
Show resolved Hide resolved
{
public function testProvidesConfig(): void
{
$module = new Module();
$config = $module->getConfig();

self::assertArrayHasKey('router', $config);
self::assertArrayHasKey('controllers', $config);
}
}
2 changes: 2 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<exclude-pattern>*.phtml</exclude-pattern>
</rule>
<rule ref="PSR12.Files.FileHeader">
<exclude-pattern>config/*</exclude-pattern>
<exclude-pattern>public/index.php</exclude-pattern>
<exclude-pattern>*.phtml</exclude-pattern>
</rule>

Expand Down
20 changes: 14 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<coverage processUncoveredFiles="true">
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that failOnWarning, failOnNotice and friends would be too strict?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this controls whether phpunit fails on warnings. This makes phpunit report tests that produced warnings or notices in test results.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - I meant: Do you think that failOnWarning and friends should be added to PHPUnit's config?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should.
Not the decision I am going to make here. We don't use them. Users can tighten configuration themselves.

>
<source>
<include>
<directory suffix=".php">./module/*/src</directory>
</include>
</coverage>
</source>

<testsuites>
<testsuite name="Laminas MVC Skeleton Test Suite">
Expand Down
11 changes: 10 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?xml version="1.0"?>
<psalm
resolveFromConfigFile="true"
cacheDirectory="./.psalm-cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorLevel="1"
findUnusedPsalmSuppress="true"
findUnusedCode="true"
findUnusedBaselineEntry="true"
>

<projectFiles>
<directory name="module" />
<directory name="config" />
Expand Down Expand Up @@ -32,6 +37,10 @@
</InternalMethod>
</issueHandlers>

<stubs>
<file name=".psalm-stubs.meta.php"/>
</stubs>

Xerkus marked this conversation as resolved.
Show resolved Hide resolved
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
Expand Down
7 changes: 4 additions & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();