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

Migrate to Pest, Add Rector, and Improve CI #29

Merged
merged 8 commits into from
Mar 4, 2025

Conversation

n4ss1m
Copy link
Collaborator

@n4ss1m n4ss1m commented Mar 4, 2025

This PR introduces major testing and automation improvements by replacing PHPUnit with Pest, integrating Rector for automated refactoring, and enhancing CI/CD workflows. The changes aim to improve maintainability, enforce better coding practices, and streamline test execution.

Key Changes

1. Migration to Pest for Testing

  • Replaced PHPUnit with Pest as the primary test framework.
  • Updated composer.json dependencies:
    • Removed phpunit/phpunit
    • Added pestphp/pest (supports PHP 8.1+).
  • Refactored test files:
    • Ensured tests have correct type hints (: void).

2. Added Rector for Automated Refactoring

  • Introduced rector.php configuration file:
    • Enabled code quality and type declaration rules.
    • Automated dead code removal and coding style improvements.
  • Added Composer scripts:
    • test:refactor: Runs Rector in dry-run mode.
    • refactor: Applies Rector transformations.

3. Improved CI/CD Pipeline

  • Deleted .github/workflows/fix-php-code-style-issues.yml (code style checks now integrated into composer test).
  • Updated .github/workflows/laravel.yml:
    • Enabled Xdebug for coverage (coverage: xdebug).
    • Replaced PHPUnit with Pest for tests.
    • Moved code style checks and static analysis to composer test:
      • PHPStan analysis moved under test commands.
      • Removed redundant PHPStan analyse step.
  • Added coverage-report output directory to .gitignore.

4. Composer Enhancements

  • Introduced new test commands in composer.json:
    "scripts": {
        "test:unit": "pest --parallel --coverage --min=54",
        "test:format": "pint --test",
        "test:refactor": "rector --dry-run",
        "test:types": "vendor/bin/phpstan analyse --memory-limit=256M",
        "test": [
            "@test:unit",
            "@test:format",
            "@test:refactor",
            "@test:types"
        ],
        "refactor": "rector",
        "format": "vendor/bin/pint"
    }

5. Type Safety and Code Quality Improvements

  • Added strict typing across several classes:
    • Updated function return types (e.g., handle(): void, rules(): array).
    • Used sprintf() for dynamic query placeholders in controllers.
  • Updated route definitions:
    • Added : void return type hints in routes/api.php.
    • Improved controller route syntax.

6. PHPUnit Coverage Reporting

  • Enabled HTML test coverage reporting in phpunit.xml:
    <coverage>
        <report>
            <html outputDirectory="coverage-report"/>
        </report>
    </coverage>

Why These Changes?

  • Pest improves test readability, parallel execution, and overall developer experience.
  • Rector automates repetitive refactoring and ensures the codebase remains up to modern standards.
  • CI/CD improvements help enforce code quality, automate formatting, and detect issues earlier.
  • Type safety enhancements improve code robustness and prevent runtime errors.

Potential Breaking Changes

  • PHPUnit-specific commands/scripts have been removed in favor of Pest.

Testing & Validation

  • Run composer test to verify tests and code quality.

@n4ss1m n4ss1m merged commit e67e40b into kossa:master Mar 4, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant