How to create a plain excel file for testing? #4074
-
Hey there, I have created an controller endpoint to handle a excel file which contents will be imported. Now I want to create a test for this controller and I ask myself how can I create and pass an excel file to my controller endpoint. In version 2.1 I could easily do something like this:
But now, in version 3.1. I also have an array like this:
But how can I create an excel file now with the defined data to be handled by the controller endpoint? In the docs I always find the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't recommend handling export logic outside of an export class in case of actual business logic. In my professional opinion it's a lot better to encapsulate it.
There are three ways to do what you want: Have some generic class
Anonymous classes:
Using the collection macro (https://docs.laravel-excel.com/3.1/exports/collection.html#collection-macros)
You can pick which ever one you like most. |
Beta Was this translation helpful? Give feedback.
I don't recommend handling export logic outside of an export class in case of actual business logic. In my professional opinion it's a lot better to encapsulate it.
There are three ways to do what you want:
Have some generic class
Anonymous classes:
Using the collection macro (https://docs.laravel-excel.com/3.1/exports/collection.html#collection-macros)