Skip to content

Memoized cache errors when spying in test #57853

@Propaganistas

Description

@Propaganistas

Laravel Version

12.39.0

PHP Version

8.4.15

Database Driver & Version

No response

Description

I am adding some memoization to some cache calls:

// from
Cache::remember(...)
// to
Cache::memo()->remember(...)

But tests using a cache spy start failing after this addition. The spy's expectation isn't met anymore.
Looking at the logs I can see the following server error:

Call to a member function remember() on null

Steps To Reproduce

Cache::memo()->remember(...)

In a test:

$cache = Cache::spy();

//...

$cache->shouldHaveReceived(...);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions