"All new business logic should have corresponding unit tests."
Description
This PR introduces unit tests for the HomeController to ensure the new business logic behaves as expected. The tests cover the index method, verifying that it correctly fetches featured properties from the database and returns the expected view.
Additionally, the PR ensures that the route for the HomeController's index method is correctly set up and named, facilitating easier testing.
Summary of Changes
Created a new test file tests/Feature/HomeControllerTest.php with two tests:
testIndexMethodReturnsFeaturedProperties: This test mocks the Property model's where method to return a predefined set of properties marked as featured. It then makes a GET request to the home route and asserts that the response status is 200 and the view contains the mocked featured properties.
testIndexMethodView: This test makes a GET request to the home route and asserts that the response status is 200 and the correct view is returned.
Verified the route definition for the HomeController's index method in routes/web.php, ensuring it is correctly set up and named for easier testing.
These changes help ensure the reliability of the application by testing new business logic introduced in the HomeController.
PR Feedback (click)
I created this PR to address this rule:
"All new business logic should have corresponding unit tests."
Description
This PR introduces unit tests for the
HomeController
to ensure the new business logic behaves as expected. The tests cover theindex
method, verifying that it correctly fetches featured properties from the database and returns the expected view.Additionally, the PR ensures that the route for the
HomeController
'sindex
method is correctly set up and named, facilitating easier testing.Summary of Changes
tests/Feature/HomeControllerTest.php
with two tests:testIndexMethodReturnsFeaturedProperties
: This test mocks theProperty
model'swhere
method to return a predefined set of properties marked as featured. It then makes a GET request to the home route and asserts that the response status is 200 and the view contains the mocked featured properties.testIndexMethodView
: This test makes a GET request to the home route and asserts that the response status is 200 and the correct view is returned.HomeController
'sindex
method inroutes/web.php
, ensuring it is correctly set up and named for easier testing.These changes help ensure the reliability of the application by testing new business logic introduced in the
HomeController
.