Improve tests for SyncService

Open Beginner friendly
#12,594 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Stale
Tech stack
php
Domain
testing-qa

Research direction

Open tests/Unit/Service/Sync/SyncServiceTest.php around lines 96, 105, and 114, then inspect how the IMAP client factory and SyncService are set up. Reuse the same client and logger stubs across the expectations, or apply the stated constraints, and run the SyncService unit test to confirm the argument matching works.

Written by the indexing model from the issue text.

Description

1. to develop technical debt

Follow up https://github.com/nextcloud/mail/pull/12548

https://github.com/nextcloud/mail/blob/65a26b2441c025d916f91c44d39fe3219c688753/tests/Unit/Service/Sync/SyncServiceTest.php#L105

The sync() expectation is matching against fresh stubs created inline for the IMAP client and logger. SyncService is very likely to pass the exact instances it uses internally (client from the factory, logger from the constructor), so these should be captured into variables/properties and reused in with(...) (or replaced with looser constraints) to avoid brittle, failing argument matching.

https://github.com/nextcloud/mail/blob/65a26b2441c025d916f91c44d39fe3219c688753/tests/Unit/Service/Sync/SyncServiceTest.php#L114

syncStats() is asserted with a newly created IMAP client stub. This will not be the same instance as the client returned by the factory in this test, so the expectation is likely to fail. Reuse the same $client stub (or use a type/constraint matcher) for both the factory return and the syncStats() expectation.

https://github.com/nextcloud/mail/blob/65a26b2441c025d916f91c44d39fe3219c688753/tests/Unit/Service/Sync/SyncServiceTest.php#L96

In this test you create a new IMAP client stub inline in the willReturn(...) call, but later the expectations use different stubs for the IMAP client argument. If SyncService::syncMailbox() passes the client returned by IMAPClientFactory::getClient() through, these argument comparisons will not match and the test will fail. Assign the client stub to a variable (or use a constraint like isInstanceOf) and reuse it consistently across all expectations.

Dominant language
JavaScript
Stars
1k
Forks
348
Avg merge
14h 51m
Merged PRs (30d)
85

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nextcloud/mail

All issues in nextcloud/mail

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.