Skip to content

Conversation

@g-i-kala
Copy link

@g-i-kala g-i-kala commented Jul 22, 2025

Description

This pull request updates PHPUnit to the latest versions and aligns the test suite with modern expectations. It improves test reliability, resolves deprecations, and enhances local developer tooling.

The solution
e Upgraded PHPUnit to 10.5, then to 12.2, including config file migration and compatibility adjustments.
e Integrated PHPUnit coverage reporting with VSCode using Coverage Gutters.
e Cleaned .gitignore to remove phpcache and test report noise.
t Updated multiple test cases, including ErrorHandlerTest::testEWarning, to follow best practices and verify error conversion behavior.
R!! Added explicit nullable type hints for several classes and interfaces to fix deprecation warnings.
R!! Extracted FileComparatorInterface and declared getApprovalsDirectory to improve interface clarity.
t Validated functionality with targeted test updates like VerifyTransformedList and writeEmpty behavior.

Notation
All commits are prefixed using Arlo's Git Notation with a mix of:
e for environment/config changes
t for test updates
R!! for structural refactoring

Summary by Sourcery

Upgrade to PHPUnit 12.2, modernize test configuration and suite, fix PHP 8.4 deprecation warnings with nullable hints, and refactor approval comparison to use a pluggable FileComparatorInterface

New Features:

  • Add FileComparatorInterface and support custom file comparators in Approvals
  • Integrate PHPUnit coverage reporting in phpunit.xml for HTML, text, and Clover outputs

Bug Fixes:

  • Add nullable type hints to reporter and verification methods to resolve PHP 8.4 deprecation warnings
  • Ensure E_USER_WARNING is converted to ErrorException in ErrorHandlerTest

Enhancements:

  • Refactor Approvals.verify to use filesMatch helper and dynamic comparator
  • Refactor FileApprover to implement FileComparatorInterface and clean up method signatures

Build:

  • Upgrade PHPUnit requirement to ^12.2 in composer.json

CI:

  • Replace phpunit.xml with schema-driven 12.2 config enforcing strict deprecation, execution order, and cache settings

Tests:

  • Update tests for verifyTransformedList and empty approved file creation
  • Migrate test cases to PHPUnit 12.2 syntax and improve tearDown logic

Chores:

  • Clean .gitignore to remove phpcache and test report artifacts

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 22, 2025

Reviewer's Guide

This PR upgrades PHPUnit to 12.2 with config and coverage support, cleans up deprecation issues by introducing nullable type hints, extracts a FileComparatorInterface with related refactoring, and modernizes the test suite with new tests and improved error‐handling cleanup.

Class diagram for FileComparatorInterface extraction and refactoring

classDiagram
    class FileComparatorInterface {
        +checkFiles(string $approvedFilename, string $receivedFilename)
        +clean(string $contents)
    }
    class FileApprover {
        +checkFiles(string $approvedFilename, string $receivedFilename): bool
        +clean(string $contents): string
    }
    FileApprover --|> FileComparatorInterface
    class Approvals {
        <<static>>
        +fileComparator: ?FileComparatorInterface
        +setFileComparator(?FileComparatorInterface $comparator)
        +verifyString($received, ?Reporter $reporter = null)
        +verifyStringWithFileExtension($received, $extensionWithoutDot, ?Reporter $reporter = null)
        +verify(Writer $writer, Namer $namer, ?Reporter $reporter = null)
        -filesMatch(string $approvedFilename, string $receivedFilename)
    }
    Approvals --> FileComparatorInterface : uses
    Approvals --> FileApprover : default implementation
Loading

Class diagram for updated Namer interface

classDiagram
    class Namer {
        <<interface>>
        +getApprovedFile($extension)
        +getReceivedFile($extension)
        +getCallingTestClassName()
        +getCallingTestClassNameWithoutNamespace()
        +getCallingTestMethodName()
        +getCallingTestDirectory()
        +getApprovalsDirectory()
    }
Loading

Class diagram for updated DiffInfo constructor

classDiagram
    class DiffInfo {
        +__construct(string $diffProgram, array $fileExtensions, ?string $parameters = null)
        +diffProgram
        +parameters
        +fileExtensions
    }
Loading

Class diagram for CombinationApprovals nullable reporter refactor

classDiagram
    class CombinationApprovals {
        +verifyAllCombinations1($param, array $values, ?Reporter $reporter = null)
        +verifyAllCombinations2($param, array $values1, array $values2, ?Reporter $reporter = null)
        +verifyAllCombinations3($param, array $values1, array $values2, array $values3, ?Reporter $reporter = null)
        +verifyAllCombinations4($param, array $values1, array $values2, array $values3, array $values4, ?Reporter $reporter = null)
        +verifyAllCombinations5($param, array $values1, array $values2, array $values3, array $values4, array $values5, ?Reporter $reporter = null)
        +verifyAllCombinations6($param, array $values1, array $values2, array $values3, array $values4, array $values5, array $values6, ?Reporter $reporter = null)
        +verifyAllCombinations7($param, array $values1, array $values2, array $values3, array $values4, array $values5, array $values6, array $values7, ?Reporter $reporter = null)
        +verifyAllCombinations8($param, array $values1, array $values2, array $values3, array $values4, array $values5, array $values6, array $values7, array $values8, ?Reporter $reporter = null)
        +verifyAllCombinations9($param, array $values1, array $values2, array $values3, array $values4, array $values5, array $values6, array $values7, array $values8, array $values9, ?Reporter $reporter = null)
    }
Loading

File-Level Changes

Change Details Files
Upgrade PHPUnit and test tooling
  • composer.json updated to require PHPUnit ^12.2
  • New phpunit.xml with schema, coverage reports, strict settings
  • Cleaned .gitignore and added phpunit cache directory
composer.json
phpunit.xml
.gitignore
phpunit.xml.bak
Fix deprecation warnings with nullable type hints
  • Added nullable Reporter hints across Approvals APIs
  • Updated CombinationApprovals methods to accept ?Reporter
  • Adjusted DiffInfo constructor to accept ?string parameters
src/Approvals.php
src/CombinationApprovals.php
src/Reporters/DiffInfo.php
Extract FileComparatorInterface and refactor file approval
  • Introduced FileComparatorInterface
  • FileApprover implements interface with instance methods
  • Approvals now delegates to FileComparatorInterface via setFileComparator and filesMatch
src/FileComparatorInterface.php
src/FileApprover.php
src/Approvals.php
Enhance Namer interface clarity
  • Added getApprovalsDirectory to Namer interface
  • Imported FileComparatorInterface and Namers in tests
src/Namers/Namer.php
tests/ApprovalTest.php
Revamp and extend tests
  • Reorganized ApprovalTest imports and added new test cases
  • Updated ErrorHandlerTest to install/restore error handlers
  • Validated transformed list and empty file behavior with mocks
tests/ApprovalTest.php
tests/ErrorHandlerTest.php

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @g-i-kala - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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