"All new business logic should have corresponding unit tests."
Description
This PR introduces unit tests for the BookingController. The tests cover the store, update, and index methods of the controller. Each method is tested under normal conditions as well as edge cases to ensure robustness. The tests leverage Laravel's built-in support for testing with PHPUnit and the RefreshDatabase trait to ensure a fresh database state for each test.
Summary of Changes
Created a new test file tests/Feature/BookingControllerTest.php.
In BookingControllerTest.php, imported the necessary classes and declared the BookingControllerTest class.
Wrote a test method for the store action in the BookingController. The method simulates a POST request to the /bookings route with valid and invalid data, asserting the correct behavior in each case.
Wrote a test method for the update action in the BookingController. The method creates a booking entry, simulates a PUT request to the /bookings/{booking} route with changes, and asserts the correct behavior.
Wrote a test method for the index action in the BookingController. The method simulates a GET request to a route that lists bookings and asserts the correct behavior.
Each test method includes assertions for both the HTTP response status and the database state.
These changes ensure that the BookingController's methods function as expected and provide a safety net for future development.
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
BookingController
. The tests cover thestore
,update
, andindex
methods of the controller. Each method is tested under normal conditions as well as edge cases to ensure robustness. The tests leverage Laravel's built-in support for testing with PHPUnit and theRefreshDatabase
trait to ensure a fresh database state for each test.Summary of Changes
tests/Feature/BookingControllerTest.php
.BookingControllerTest.php
, imported the necessary classes and declared theBookingControllerTest
class.store
action in theBookingController
. The method simulates a POST request to the/bookings
route with valid and invalid data, asserting the correct behavior in each case.update
action in theBookingController
. The method creates a booking entry, simulates a PUT request to the/bookings/{booking}
route with changes, and asserts the correct behavior.index
action in theBookingController
. The method simulates a GET request to a route that lists bookings and asserts the correct behavior.These changes ensure that the
BookingController
's methods function as expected and provide a safety net for future development.