Skip to content

Improve testing and fix PHPStan errors#24

Merged
jsirish merged 5 commits intomainfrom
fix/improve-testing
Nov 19, 2025
Merged

Improve testing and fix PHPStan errors#24
jsirish merged 5 commits intomainfrom
fix/improve-testing

Conversation

@jsirish
Copy link
Member

@jsirish jsirish commented Nov 19, 2025

This PR improves test coverage and code quality for the user-invitation module.

Changes

PHPStan Level 4

  • Added phpstan.neon.dist with level 4 configuration
  • Fixed all 36 PHPStan errors related to code quality
  • Added @config annotations to all static configuration properties
  • Added ignoreErrors for property.onlyWritten identifier (SilverStripe framework pattern)
  • Removed baseline file in favor of proper configuration

Test Improvements

  • Fixed all 25 existing PHPUnit tests (now 100% passing)
  • Added new testGetInvitationLink() to validate URL generation
  • Updated Groups format to JSON throughout tests and fixtures
  • Fixed URL assertions (added leading slashes)
  • Fixed validation tests (create new controller after config change)
  • Added LastEdited to expired invitation fixtures

Code Quality

  • Fixed PHPDoc annotations (@Property, @method syntax)
  • Added proper return type hints
  • Fixed Convert::array2json() → json_encode()
  • Added missing return statement in Link() method
  • Fixed parameter type hints

CMS Testing

  • Verified custom "Send invitation" action displays correctly in CMS
  • Tested email sending functionality via Mailpit
  • Confirmed invitation URLs render correctly in email templates

Test Results

✅ All tests passing: 26/26 tests, 60 assertions
✅ PHPStan: Clean at level 4
✅ PHPCS: Clean

Verification

The changes have been tested in a live DDEV environment:

  • Custom CMS action displays and functions correctly
  • Emails send successfully to Mailpit
  • Invitation URLs are correctly formatted and functional

- Add phpstan.neon.dist with level 4 configuration
- Add phpstan-baseline.neon.dist for framework false positives
- Fix PHPStan errors:
  * Correct @Property syntax in UserInvitation (add $ prefix)
  * Fix return type hints in UserController
  * Add missing return statement in Link() method
  * Fix Convert::array2json() call (use json_encode in SS6)
  * Update parameter type hints
- Fix all PHPUnit tests (25/25 passing):
  * Update Groups format in fixtures to JSON
  * Add LastEdited to expired invitation fixtures
  * Fix URL assertions (add leading slashes)
  * Fix validation test to properly validate after config change
  * Update testGetCMSFields to check for readonly TempHash field
- All tests passing: PHPUnit ✅ PHPStan level 4 ✅
- Added PHPStan level 4 configuration
- Fixed all 36 PHPStan errors (code quality improvements)
- Fixed all 25 PHPUnit tests (100% passing)
- Updated Groups format to JSON throughout tests and fixtures
- Fixed URL assertions (added leading slashes)
- Fixed validation tests (create new controller after config change)
- Added @config annotations to all static properties
- Removed phpstan-baseline.neon.dist
- Added ignoreErrors for property.onlyWritten identifier
  (SilverStripe config properties read via Config::inst()->get())
- Added testGetInvitationLink() to validate URL generation
- Verified CMS custom action displays correctly
- Tested email sending via Mailpit (invitation emails working)

All tests passing: 26/26 tests, 60 assertions
PHPStan: Clean at level 4
Coverage reporting not needed for this module
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves code quality and test coverage for the user-invitation module by implementing PHPStan level 4 compliance and enhancing tests. The changes focus on fixing PHPDoc annotations, correcting data serialization formats, and adding comprehensive test coverage for invitation link generation.

  • Configures PHPStan level 4 with appropriate ignores for SilverStripe patterns
  • Fixes 36 PHPStan errors through improved type hints and annotations
  • Updates test fixtures and code to use JSON format for group data serialization
  • Adds new test for invitation URL generation

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
phpstan.neon.dist Adds PHPStan level 4 configuration with ignores for optional dependencies and SilverStripe config property patterns
src/Model/UserInvitation.php Adds @config annotations to static properties, fixes PHPDoc syntax (adds $ prefix and proper @method format), updates return type documentation
src/Control/UserController.php Adds @config annotation, fixes PHPDoc parameter and return types, replaces deprecated Convert::array2json() with json_encode(), adds missing return statement
src/Admin/UserInvitationsAdmin.php Adds @config annotations to all static configuration properties
tests/php/UserInvitationTest.yml Adds LastEdited field to expired invitation fixture (required for isExpired() method)
tests/php/UserInvitationTest.php Updates test comment to reflect readonly field behavior, adds new testGetInvitationLink() for URL generation validation
tests/php/UserControllerTest.yml Updates Groups format from CSV to JSON, adds LastEdited to expired invitation
tests/php/UserControllerTest.php Updates test assertions for JSON group format, fixes validation test to create new controller after config change, corrects URL assertions with leading slashes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @property string Groups
* @property int InvitedByID
* @property Member InvitedBy
* @property string $FirstName
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

There is trailing whitespace after $FirstName in the PHPDoc comment. This should be removed to maintain clean code formatting.

Copilot uses AI. Check for mistakes.

/**
* @config
*/
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

There is trailing whitespace after @config in the PHPDoc comment. This should be removed to maintain clean code formatting.

Copilot uses AI. Check for mistakes.
{
/** @var UserInvitation $joe */
$joe = $this->objFromFixture(UserInvitation::class, 'joe');

Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

This line contains only whitespace characters. Empty lines should be completely empty with no trailing spaces or tabs.

Suggested change

Copilot uses AI. Check for mistakes.
PHPStan not found in CI - silverstan provides phpstan/phpstan
CmsActions is now a required dependency, so the class is found
@jsirish jsirish merged commit f374645 into main Nov 19, 2025
16 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