Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

seb7's avatar
Level 1

Assert cache is empty.

Hi folks,

** Is the a way to assert that laravel cache is empty, in laravel 4 ? **

This is for acceptance testing. For example : - empty cache - view a post - update post - assert cache is empty

For the moment, I just use a file cache and assert there no more file in the cache folder (that's ok but not in the default path). But writing files to disk is slow. I don't think I can do this sort of tests using a memory cache (I am wrong) ?

The solution I'm thinking about is to implement an override of a storecache (apc I think, adding a registry touched when inserting and deleting caches, so I can implement a method isEmpty() that will satisfy my needs.


Why do I want to test cache while making acceptance tests ? Because I choose to implement only accept tests, that allow my project to fully change, inside, without having to rewrite the tests, urls will stay the same.

0 likes
3 replies
kfirba's avatar
kfirba
Best Answer
Level 50

@seb7 If you are trying to test your cache with acceptance tests it means that the whole process should be done from the outside in. I believe your user don't have the ability to access your cache files and read them right?

The way I would go about it is something like this:

  1. Create some post and cache it -> save content as for assertion
  2. Update a post -> clear cache
  3. Assert the post's content is different from step 1 which indicates that the cache was rewritten.
seb7's avatar
Level 1

Yeah, I didn't think of checking the content has changed, good idea ! Thanks.

seb7's avatar
Level 1

I did not grab the content but just before caching content, after it is rendered in response, I add . So now I can easily see if content from cache or not.

Thanks for the idea :)

Please or to participate in this conversation.