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 with the folllowing error:

$cache = Cache::spy();

// ...

$cache->shouldHaveReceived('remember');

// Call to a member function remember() on null

Rewriting the test to the following also results in an error:

$cache = Cache::memo()->spy();

// method spy() is not available on MemoizedCacheStore

Steps To Reproduce

I've created a showcase repository here: https://github.com/Propaganistas/laravel-issue-57853

It contains two commits:

  • Fresh Laravel application
  • Minimal code to reproduce the issue

Run php artisan test or composer test to see the error.

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