Skip to content

Test/testcoverage util 1#2115

Merged
osaerdna merged 8 commits into
devfrom
test/testcoverage-util-1
May 21, 2026
Merged

Test/testcoverage util 1#2115
osaerdna merged 8 commits into
devfrom
test/testcoverage-util-1

Conversation

@osaerdna
Copy link
Copy Markdown

No description provided.

@osaerdna osaerdna requested a review from s3inlc May 20, 2026 12:50
Copy link
Copy Markdown

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 tightens type safety in access-control related utility classes and adds PHPUnit coverage for access group and permission group behavior, including singleton/permission checks in AccessControl.

Changes:

  • Added/updated PHP type declarations in AccessGroupUtils, AccessControlUtils, and AccessControl (nullable properties, scalar parameter types, and return types).
  • Introduced PHPUnit tests for AccessGroupUtils, AccessControlUtils, and AccessControl, and updated the shared TestBase.
  • Added small test-environment adjustments (e.g., defaulting $_SERVER values) to reduce PHPUnit warnings.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/inc/utils/AccessGroupUtils.php Adds model import and stricter typing for several access-group utilities.
src/inc/utils/AccessControlUtils.php Adds return/parameter typing for permission-group utilities.
src/inc/utils/AccessControl.php Makes internal state nullable/typed and updates method signatures to support tests and safer initialization.
ci/phpunit/TestBase.php Adds overrides and defaults for server variables used during tests.
ci/phpunit/inc/utils/AccessGroupUtilsTest.php New tests covering access-group behaviors (membership, chunk abort, delete reassignment).
ci/phpunit/inc/utils/AccessControlUtilsTest.php New tests covering permission-group CRUD and permission updates.
ci/phpunit/inc/utils/AccessControlTest.php New tests covering singleton behavior and permission evaluation logic.
Comments suppressed due to low confidence (1)

src/inc/utils/AccessControlUtils.php:30

  • getGroups() is declared to return ?array, but Factory::getRightGroupFactory()->filter([]) returns an array when $single=false. Using a nullable return type here is an inaccurate contract and can spread unnecessary null checks into callers; prefer array (or RightGroup[]).
  public static function getGroups(): ?array {
    return Factory::getRightGroupFactory()->filter([]);
  }

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

Comment thread src/inc/utils/AccessGroupUtils.php Outdated
Comment thread src/inc/utils/AccessControlUtils.php Outdated
Comment on lines +53 to 56
public static function updateGroupPermissions(int $groupId, array $perm): bool {
$group = AccessControlUtils::getGroup($groupId);
if ($group->getPermissions() == 'ALL') {
throw new HTException("Administrator group cannot be changed!");
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Discussions around handling this potential TypeError ended up in that it is only keys read and passed to these functions, so it is not very likely they will appear.
But also, it would be nice to manage this type of error as the code get more typed and these errors become more likely to appear, in this pr we merge as is, and then make a separate fix that changes the exception handling to deal with Throwable in all handlers.

Comment on lines +111 to 114
public static function addAgent(int $agentId, int $groupId): void {
$group = AccessGroupUtils::getGroup($groupId);
$agent = AgentUtils::getAgent($agentId);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Discussions around handling this potential TypeError ended up in that it is only keys read and passed to these functions, so it is not very likely they will appear.
But also, it would be nice to manage this type of error as the code get more typed and these errors become more likely to appear, in this pr we merge as is, and then make a separate fix that changes the exception handling to deal with Throwable in all handlers.

Comment thread ci/phpunit/inc/utils/AccessGroupUtilsTest.php Outdated
@osaerdna osaerdna merged commit c56a748 into dev May 21, 2026
5 checks passed
@s3inlc s3inlc mentioned this pull request May 21, 2026
55 tasks
@s3inlc s3inlc deleted the test/testcoverage-util-1 branch May 22, 2026 06:09
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.

3 participants