Thanks for these great videos! I was reading some people's very good suggestions in the comment section, I think we could have a great video of you addressing these suggestions?
Awesome, am now getting testing unit test and feature test concept now great mentor. Thank you sir. Please help us do tutorial on saving and retrieving files to S3 bucket of aws while the application hosted on normal shared server
Hi, A big thanks for this series. one question though. if we were to test the price saved in database, could we just add a assertDatabaseHas inside the test_tours_price_is_shown_correctly test, or since its related to database, should it be done in a different test class?
In my case, I wanted to test whether it's *returned* correctly. Whether it's saved in the database correctly - it's a good point to add such assertion, and I would probably add it in the same method, as just another "by the way" assertion. Though, to be honest, it's totally your personal preference how to structure test files/methods/assertions, I've seen a lot of different structures from different people.
Great Course! Thanks for sharing! What do you think of having a specific controller `TravelToursController`? Since the cruddy by design suggests that kind of approach
I think your first test is incorrect: you should probably create 2 travel objects with tours for them, so test could check if your code select exactly tours of specified travel (not both of them). Additionally I would test what your code will do with: - 2 travel with same names (probably with selecting the second one, to avoid auto selected first one by insert order) - URL like '/api/v1/some-travel-%/tours/' (and other potential injections)
Nice Tutorial, but you must doing a lot of stuff in background. You need the relationships in model, constrains in migration. If you have a little bit experience in Laravel, so its cool. But not sooo beginner friendly.
I want to create a system with Laravel containing modules each module can work alone and copy to another project with the same core structure without causing any problems the system in the future will be able to manage companies with many branches like gyms, schools, spas... And I have those modules subscription invoices coupons notifications permissions Payment gateways how can I make a MySQL table for invoices to fit this variant
I would make those as packages not modules, each with their own DB tables and configurable settings. Unfortunately can't comment more as it's not a short question so can't answer in a RUclips comment
@@LaravelDaily thanks a lot for your reply if you can call me I want to discuss many things with you I am working on laravel for 7 years We will come up with better solutions for many issues
My mini code review for you Povilas First use method query when using where to add type hinting to query methods like this Travel::query()->where Second, if you use phpstorm configure on save cleanup code which simplifies class namespaces in code when you write new routes
Thanks for the review! For query() I use it when it makes sense. For phpstorm, I have a bad habit of still doing some things manually instead of thinking "what was that shortcut..". Need to get better.
FAILED Tests\Feature\TourListTest > tours list by travel slug return correct to… Unable to find JSON fragment: [{"id":"996aee6f-ab39-4121-bad0-93e4794a4be2"}] within
Thanks Povilas for these contents. I was trying to do the test tours by travel slug list differently ``` $travel = Travel::factory()->create(); $tour = Tour::factory(2)->create(['travel_id' => $travel->id]); $response = $this->get('/api/v1/travels/' . $travel->slug . '/tours'); $response->assertStatus(200); $response->assertJsonCount(2, 'data'); // $response->assertJsonFragment(['id' => $tour->id]); ``` how do i get $response->assertJsonFragment to work, since more than one data is returned?
Ok I just did $response->assertJsonFragment(['id' => $tour[0]->id]); to essentially pass the test for the first element. Hope there is a better way to test
Thank you Povilas! These videos are great. Grateful for your invaluable contributions!
I dont comment much but I really like to listen you. Im learning more 🎉
I'm a test first guy now
Definitely harder in crud style applications 😊
awesome. just curious, is `is_public` check for the parent table `travel` not needed here?
Good point, probably should add it.
Thank you very much!
Thanks for these great videos! I was reading some people's very good suggestions in the comment section, I think we could have a great video of you addressing these suggestions?
Yes it's in plans, later, with improvements
Awesome, am now getting testing unit test and feature test concept now great mentor.
Thank you sir.
Please help us do tutorial on saving and retrieving files to S3 bucket of aws while the application hosted on normal shared server
I don't work with shared servers, to me they are not normal, sorry. I use mostly digital ocean or aws.
Should we keep unit test code in industry projects?
Hi, A big thanks for this series. one question though. if we were to test the price saved in database, could we just add a assertDatabaseHas inside the test_tours_price_is_shown_correctly test, or since its related to database, should it be done in a different test class?
In my case, I wanted to test whether it's *returned* correctly. Whether it's saved in the database correctly - it's a good point to add such assertion, and I would probably add it in the same method, as just another "by the way" assertion.
Though, to be honest, it's totally your personal preference how to structure test files/methods/assertions, I've seen a lot of different structures from different people.
great job
Great
How did you inser the record in Tour Model in the database ? I get the empty respoonse when i send thhe request
Great Course! Thanks for sharing!
What do you think of having a specific controller `TravelToursController`? Since the cruddy by design suggests that kind of approach
Yeah I would agree with that as alternative approach, but then I would implement full nested resource controllers
I think your first test is incorrect: you should probably create 2 travel objects with tours for them, so test could check if your code select exactly tours of specified travel (not both of them).
Additionally I would test what your code will do with:
- 2 travel with same names (probably with selecting the second one, to avoid auto selected first one by insert order)
- URL like '/api/v1/some-travel-%/tours/' (and other potential injections)
Nice Tutorial, but you must doing a lot of stuff in background. You need the relationships in model, constrains in migration. If you have a little bit experience in Laravel, so its cool. But not sooo beginner friendly.
Yes, I'm not shooting my tutorials for total beginners, sorry.
I want to create a system with Laravel containing modules each module can work alone and copy to another project with the same core structure without causing any problems the system in the future will be able to manage companies with many branches like gyms, schools, spas...
And I have those modules
subscription
invoices
coupons
notifications
permissions
Payment gateways
how can I make a MySQL table for invoices to fit this variant
I would make those as packages not modules, each with their own DB tables and configurable settings. Unfortunately can't comment more as it's not a short question so can't answer in a RUclips comment
@@LaravelDaily thanks a lot for your reply if you can call me I want to discuss many things with you I am working on laravel for 7 years
We will come up with better solutions for many issues
Sorry I don't have time available for personal consultations.
@@LaravelDaily no problem, and thanks again
maybe we will meet someday
My mini code review for you Povilas
First use method query when using where to add type hinting to query methods like this Travel::query()->where
Second, if you use phpstorm configure on save cleanup code which simplifies class namespaces in code when you write new routes
Thanks for the review! For query() I use it when it makes sense.
For phpstorm, I have a bad habit of still doing some things manually instead of thinking "what was that shortcut..". Need to get better.
FAILED Tests\Feature\TourListTest > tours list by travel slug return correct to…
Unable to find JSON fragment:
[{"id":"996aee6f-ab39-4121-bad0-93e4794a4be2"}]
within
Sorry I can't debug it for you just from that error message. I created the record with a factory, in the beginning of the same method.
Thanks Povilas for these contents.
I was trying to do the test tours by travel slug list differently
```
$travel = Travel::factory()->create();
$tour = Tour::factory(2)->create(['travel_id' => $travel->id]);
$response = $this->get('/api/v1/travels/' . $travel->slug . '/tours');
$response->assertStatus(200);
$response->assertJsonCount(2, 'data');
// $response->assertJsonFragment(['id' => $tour->id]);
```
how do i get $response->assertJsonFragment to work, since more than one data is returned?
Ok I just did $response->assertJsonFragment(['id' => $tour[0]->id]); to essentially pass the test for the first element. Hope there is a better way to test
It's the case of "whatever works for you", in my opinion :)