A full-featured multi-tenant app with Laravel Part 5 —Automated Tests
Part 0, Part 1, Part 2, Part3, Part4, Part 5 👇, Part 6, Part 7
In this part we’ll accomplish the following tasks:
✅ Refactor our code to make it more readable and testable.
✅ Configure our test environment
✅ Add tests
Before we get too far ahead with all the crazy awesome features, for the peace of mind, lets add some automated tests first.
It’s always never too early to add tests or clean your code.
Although our app is pretty small and don’t have many tests to write, we can start laying the foundation to make it easy to add more tests in future. This also gives us an opportunity to refactor our code to make it more testable and readable. It’s always never too early to add tests or clean your code.
1. Refactor
Right now the logic for creating and deleting a tenant is sort of scattered in two classes — CreateTenant.php and DeleteTenant.php. This makes it not only hard to follow the code but also makes it hard to write tests. Let’s refactor this by creating a Tenant.php class that encapsulates the creation, retrieval, and deletion of a tenant. You will see the advantage of…