Skip to content

Improve tests for SyncService #12594

@kesselb

Description

@kesselb

Follow up #12548

$this->createStub(\Horde_Imap_Client_Socket::class),

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.

->with($this->createStub(\Horde_Imap_Client_Socket::class), $mailbox);

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.

->willReturn($this->createStub(\Horde_Imap_Client_Socket::class));

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.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions