Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PreventsSavingStacheItemsToDisk doesn't work in Pest #11401

Closed
edalzell opened this issue Jan 28, 2025 · 2 comments
Closed

PreventsSavingStacheItemsToDisk doesn't work in Pest #11401

edalzell opened this issue Jan 28, 2025 · 2 comments
Labels

Comments

@edalzell
Copy link
Contributor

Bug description

I can't figure out how, in an addon, to use Pest and the PreventsSavingStacheItemsToDisk trait. Every which way I try I get an error:

Image

And the path is wonky too: /Users/erin/Development/events/vendor/pestphp/pest/src/Factories/tests/__fixtures__/dev-null

How to reproduce

Try to use the PreventsSavingStacheItemsToDisk in your add-on's Pest tests

Logs

Environment

It's an addon, there are no support details. However this was on the latest (5.41) version of Statamic and Laravel 11.

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@ryanmitchell
Copy link
Contributor

I have this working in some add-ons. You just need to specify $fakeStacheDirectory and make sure the directory exists in setup.

abstract class TestCase extends AddonTestCase
{
    use PreventsSavingStacheItemsToDisk;

    protected $fakeStacheDirectory = __DIR__.'/__fixtures__/dev-null';

    protected string $addonServiceProvider = ServiceProvider::class;

    protected $shouldFakeVersion = true;

    protected function setUp(): void
    {
        parent::setUp();

        if (! file_exists($this->fakeStacheDirectory)) {
            mkdir($this->fakeStacheDirectory, 0777, true);
        }
    }
}

@duncanmcclean
Copy link
Member

You can either push an empty directory (like we do in Core) or adjust your TestCase to handle it, like @ryanmitchell suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants