Let's add a strategy for filling data automatically
Opened this issue · 4 comments
Mdhesari commented
I have a scenario in my mind let's see how it works :
- I wanna write TDD tests for a book store management.
- Let's start with the Book entity & CRUD
- I start by creating a BookTest and try to store a new book with POST method.
$this->get(route('books.store'), [ 'name' => 'Programming', 'publisher' => 'Laravel', 'author' => 'Taylor Outwell', ]);
- Now I start to enter CRUD generator command for my book, when the command executes, it will go through its tests and if there is an available test, it will look for POST method and the data we are passing to that route, it will collect the data we are passing and replace it to Form Request & Model fillables property.
Now we just need to add validation and most of the work is done by the command generator...
nafiesl commented
Hi @Mdhesari I am not sure if I get your point correctly, here are my understanding:
- We create a
Feature/ManageBookTest
and create 1 methoduser_can_create_book()
- We run an artisan command with the test class name as an argument
- The command will check the test method and see what attributes are given on the request
- The command will collect the attributes, then push them into the FormRequest class and fillable attributes on the model.
Are those correct @Mdhesari?
In general, I was thinking your idea is:
- We provide tests (with attributes)
- The command will generate the feature code for us (Model, Controller, Model Factory, DB Migration file, Policy Object, etc).
Not sure my understandings are correct, let me know, @Mdhesari.
Thanks.
nafiesl commented
Hi @Mdhesari, currently I have no time to try to dig it further to start implementing it. If you wailing to write the plan in more detail, or even submit a pull request, that will be very helpful. We can review them together.
Meanwhile, I will keep this issue open as a feature suggestion.
Thanks.
Mdhesari commented
sure, I will try to do it when there was a chance to do.