22. Oct 2022 |

Laravel associative array to collection for unit test

I need to test helper method that accepts Illuminate\Database\Eloquent\Collection as a parameter. But I can not figure out how to prepare it inside a unit test. My logic says it should be simple to create Collection from assoc array. But I just can’t get it to work.

At the moment, not to get stuck, I will probably use feature testing (because if feature (API endpoint) works then probably my helper method also works). Though, it feels stupid workaround.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.