VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho-phpstan-plugin/7.3-testing-and-quality-assurance

⇱ Testing and Quality Assurance | MahoCommerce/maho-phpstan-plugin | DeepWiki


Loading...
Menu

Testing and Quality Assurance

Purpose and Scope

This page documents how the maho-phpstan-plugin maintains code quality through self-analysis and automated testing. It covers the configuration and processes used to test the plugin's own codebase, not the testing of Maho/Magento applications that use this plugin.

For information about setting up the development environment, see Development Setup. For information about the CI/CD pipeline architecture, see CI/CD Pipeline.


Self-Analysis Strategy

The maho-phpstan-plugin uses PHPStan to analyze its own source code, creating a bootstrap scenario where the plugin must be internally consistent. This self-analysis approach ensures that the plugin adheres to the same strict static analysis standards it enforces on Maho/Magento codebases.

The plugin analyzes itself at the maximum strictness level (level 10) with additional rule sets enabled, including:

  • Bleeding edge features from PHPStan core
  • Strict rules for opinionated code quality
  • Deprecation detection rules

This approach validates that all plugin components (MageTypeExtension, MageCoreConfig, VarienObjectReflectionExtension, etc.) have proper type declarations and follow best practices.

Sources: .phpstan.dist.neon1-15


PHPStan Configuration for Self-Analysis

The plugin's self-analysis configuration is defined in .phpstan.dist.neon, which specifies strict analysis rules and configuration parameters.

Analysis Configuration Structure


Sources: .phpstan.dist.neon1-15

Configuration Parameters

ParameterValuePurpose
level10Maximum strictness - all PHPStan checks enabled
phpVersion.min80200PHP 8.2.0 minimum version
phpVersion.max80499PHP 8.4.99 maximum version (allows 8.3, 8.4)
pathssrcAnalyze all source code in src/ directory
scanFilesmock/maho-phpstan-plugin/Mage.php
mock/maho-phpstan-plugin/DataObject.php
Load mock framework classes for type resolution

Sources: .phpstan.dist.neon5-14

Included Rule Sets

The configuration includes three additional rule sets beyond the base PHPStan rules:

  1. Bleeding Edge Rules - Latest experimental features and checks from PHPStan core, included via .phpstan.dist.neon2
  2. Strict Rules - Opinionated rules that enforce stricter coding standards than default PHPStan rules, included via .phpstan.dist.neon3
  3. Deprecation Rules - Detect usage of deprecated classes, methods, properties, constants and traits, included via .phpstan.dist.neon4

Sources: .phpstan.dist.neon1-4 composer.lock64-110 composer.lock111-158


Mock Framework Dependencies

The self-analysis configuration includes mock framework files via the scanFiles parameter. These mocks are essential for the plugin to analyze itself correctly.

Why Mock Files are Required


The plugin code references classes like Mage, Varien_Object, and related framework components. Without the mock files, PHPStan would report these as undefined classes during self-analysis. The scanFiles parameter ensures these mock classes are loaded before analysis begins, allowing PHPStan to understand the plugin's type references.

Sources: .phpstan.dist.neon9-11


Continuous Integration Pipeline

The plugin uses GitHub Actions to run automated quality checks on every push and pull request. The workflow tests the plugin across multiple PHP versions to ensure compatibility.

CI/CD Workflow Structure


Sources: .github/workflows/phpstan.yml1-29

Workflow Configuration

The workflow file .github/workflows/phpstan.yml defines the following configuration:

ElementConfigurationPurpose
Triggerspush, pull_requestRun on all pushes and PRs
Strategymatrix: php-version: ['8.3', '8.4', '8.5']Test on three PHP versions
Runnerubuntu-latestUse latest Ubuntu environment
Checkoutactions/checkout@v4Check out repository code
PHP Setupshivammathur/setup-php@v2Install specified PHP version
Dependenciescomposer install --prefer-dist --no-progressInstall PHPStan and dependencies
Analysisvendor/bin/phpstan analyse --error-format=githubRun PHPStan with GitHub-specific error formatting

The --error-format=github flag formats PHPStan output as GitHub annotations, which appear inline in pull request diffs and provide precise error locations.

Sources: .github/workflows/phpstan.yml1-29


Quality Standards and Enforcement

The plugin enforces multiple layers of quality standards through its configuration and CI pipeline.

Quality Standard Layers


Sources: .phpstan.dist.neon1-15 .github/workflows/phpstan.yml14 composer.lock165-166

Level 10 Strictness

PHPStan Level 10 is the maximum strictness level and enforces:

  • All return types must be declared
  • All parameter types must be declared
  • All property types must be declared
  • Dead code detection
  • Unused variable detection
  • Strict comparison requirements
  • Void return type checking
  • Union and intersection type validation

Sources: .phpstan.dist.neon14

Strict Rules Extension

The phpstan-strict-rules extension adds opinionated checks including:

  • Disallow empty() function usage
  • Require explicit comparisons instead of loose checks
  • Disallow variable variables
  • Disallow compact() function usage
  • Enforce stricter type checking

Sources: composer.lock111-158

Deprecation Rules Extension

The phpstan-deprecation-rules extension detects usage of:

  • Deprecated classes
  • Deprecated methods
  • Deprecated properties
  • Deprecated constants
  • Deprecated traits

This ensures the plugin does not use deprecated PHP or PHPStan features that may be removed in future versions.

Sources: composer.lock64-110


PHP Version Compatibility Testing

The plugin tests across multiple PHP versions to ensure compatibility with current and future PHP releases.

Testing Matrix

PHP VersionPurposeStatus
8.3Current stable releaseProduction-ready
8.4Current stable releaseProduction-ready
8.5Development versionForward compatibility testing

The CI pipeline runs all three versions on every commit, ensuring that:

  1. The plugin works with PHP 8.3 (current stable)
  2. The plugin works with PHP 8.4 (latest stable)
  3. The plugin is prepared for PHP 8.5 (upcoming release)

Sources: .github/workflows/phpstan.yml14

Platform Configuration Constraints

The PHPStan configuration specifies PHP version constraints that differ from the runtime testing matrix:

phpVersion:
 min: 80200 # PHP 8.2.0
 max: 80499 # PHP 8.4.99

This configuration tells PHPStan to assume the code may run on PHP 8.2 through 8.4, allowing it to detect version-specific issues. The actual package requires PHP 8.2 or higher via composer.json.

Sources: .phpstan.dist.neon6-8 composer.lock165-166


Local Testing Workflow

Developers can run the same quality checks locally before committing code.

Local Testing Commands


Command sequence:

  1. composer install --prefer-dist --no-progress - Install PHPStan and all dependencies
  2. vendor/bin/phpstan analyse - Run analysis using .phpstan.dist.neon configuration

The local analysis runs the same checks as CI, ensuring developers catch issues before pushing code.

Sources: .github/workflows/phpstan.yml25-29


Error Reporting Format

The CI pipeline uses GitHub-specific error formatting to integrate analysis results with the GitHub pull request interface.

GitHub Error Format

The command vendor/bin/phpstan analyse --error-format=github outputs errors in a format that GitHub Actions can parse and display as inline annotations:

::error file=src/Example.php,line=10,col=5::Method Example::foo() has no return type specified.

These annotations appear:

  • In the Files Changed tab of pull requests
  • At the specific line and column where the issue occurs
  • With a description of the problem

This integration makes it easy for reviewers and contributors to see exactly where quality issues exist without leaving the GitHub interface.

Sources: .github/workflows/phpstan.yml29


Quality Assurance Summary

The maho-phpstan-plugin maintains code quality through a comprehensive testing strategy:

Quality AspectImplementationEnforcement
Type SafetyLevel 10 strictnessAll pushes/PRs
Code StandardsStrict rules extensionAll pushes/PRs
DeprecationsDeprecation rules extensionAll pushes/PRs
Modern FeaturesBleeding edge rulesAll pushes/PRs
PHP CompatibilityMulti-version matrix (8.3, 8.4, 8.5)All pushes/PRs
Self-ConsistencyUses PHPStan to analyze itselfAll pushes/PRs
Local ValidationSame config available locallyDeveloper discretion

This multi-layered approach ensures that the plugin code is:

  • Type-safe and self-documenting
  • Free of deprecated patterns
  • Compatible across PHP versions
  • Consistent with modern PHP best practices
  • Reliable for analyzing Maho/Magento codebases

Sources: .phpstan.dist.neon1-15 .github/workflows/phpstan.yml1-29 composer.lock8-170