Conversation
|
Thanks for opening your first pull request in this repository! ✌️ |
|
@diogopaz the problems in the unit tests aren't caused by your PR. I'll fix this in a separate PR. But have linter issues that you need to solve: https://github.com/LibreSign/libresign/actions/runs/33325571740/job/100018743935?pr=8142 |
|
Once you fix the linter issue and push the changes, the unit tests will work fine. |
6e439af to
e0ecb44
Compare
|
Hi @vitormattos, Sorry for the delay! I've fixed the linter issues (missing imports, multiline array trailing commas, and formatting) and updated the commit. Thanks for the review! |
vitormattos
left a comment
There was a problem hiding this comment.
I checked the PHPUnit failures.
There are two different groups of problems:
-
The
IUserFoldererrors inValidateHelperTestandSignFileServiceTestare not caused by this PR. They come from tests outside the changed file and appear in the Nextcloud master jobs. We should handle this compatibility change separately. -
The failures in
AccountServiceTestare from the tests added in this PR and need to be fixed here before merge. I added inline comments for the main cases.
So you do not need to fix the unrelated IUserFolder failures as part of this PR.
| $this->assertSame($fileToSign, $result['fileToSign']); | ||
| } | ||
|
|
||
| public function testGetFileByUuidUsesCache(): void { |
There was a problem hiding this comment.
I think we should test one more case before making this cache behavior part of the expected behavior.
AccountService caches signRequest, fileData and fileToSign, but the cache does not store which UUID the data belongs to.
This test calls getFileByUuid() twice with the same UUID, so it does not detect what happens with different UUIDs.
Could we also test something like:
$service->getFileByUuid('uuid-a');
$result = $service->getFileByUuid('uuid-b');and verify that the result belongs to uuid-b?
If this fails with the current implementation, we found a bug and should fix it instead of protecting this behavior with the mutation test. This is also tracked in #8328.
There was a problem hiding this comment.
The previous comment became outdated after the rebase, but the point is still valid.
This test only checks one UUID. Could you also use the same AccountService instance with two different UUIDs and verify that the second call returns the data for the second UUID?
For example:
$service = $this->getService();
$service->getFileByUuid('uuid-a');
$result = $service->getFileByUuid('uuid-b');This is important because AccountService caches the sign request and file data. We should make sure the test does not protect a cache behavior that returns data from the previous UUID.
|
@diogopaz, can you rebase your branch on top of I fixed part of the failing tests in this PR: |
|
Heads-up after #8366 was merged (this morning): After rebasing, five expectations in this PR will reference a property that no longer exists. The one-to-one mapping against current
The production calls are Sorry for the extra step — happy to review the rebase if useful. |
Signed-off-by: Diogo Paz <diogoachiles@gmail.com>
e0ecb44 to
aa80d63
Compare
| 'missingIdentify' => [ | ||
| function ($self): array { | ||
| $signRequest = $self->createMock(SignRequest::class); | ||
| $signRequest->method('getId')->willReturn(10); |
There was a problem hiding this comment.
SignRequest uses dynamic getters from Entity, so PHPUnit cannot configure getId(), getFileId() or getDisplayName() on this mock. This is causing several errors in the PHPUnit job.
Could you use a real SignRequest here and set the needed values with setId(), setFileId(), setDisplayName(), etc.? The same fix is needed in the other new tests that mock these getters.
You also can look other examples with getId at other tests.
| } | ||
|
|
||
| public function testGetCertificateEngineName(): void { | ||
| $engine = $this->createMock(ICertificateEngine::class); |
There was a problem hiding this comment.
ICertificateEngine does not exist in the current code. CertificateEngineFactory::getEngine() returns IEngineHandler.
Could you use IEngineHandler in these two tests instead?
| public function testGetConfigWithNullUser(): void { | ||
| $this->idDocsPolicyService->method('isIdentificationDocumentsEnabled')->with(null)->willReturn(false); | ||
| $this->identityDocumentValidator->method('userCanApproveValidationDocuments')->with(null, false)->willReturn(false); | ||
| $this->policyAuthorizationService->method('canUserManageGroupPolicies')->with(null)->willReturn(false); |
There was a problem hiding this comment.
$this->policyAuthorizationService is a real PolicyAuthorizationService, not a PHPUnit mock, so ->method() cannot be used here.
For a null user, the real service already returns false from canUserManageGroupPolicies() and [] from getManageablePolicyGroupIds(). I think these two stubs can just be removed.
Part of #8053
📝 Summary
This PR adds extensive PHPUnit test coverage to
AccountServiceTestto eliminate escaped mutants and improve the mutation testing score with Infection, as part of #8053.🧪 How to test
Run the focused unit test suite for AccountService:
Optionally run Infection on this specific pair to verify mutant coverage:
⚙️ API / Back‑end changes
validateCreateToSign,getFileByUuid,createToSign,saveVisibleElement(s),uploadPfx,updatePfxPassword,readPfxData, and config fallbacks.✅ Checklist
🤖 AI (if applicable)