I am trying to test a Laravel REST API, through phpunit. While testing REST calls, I am unable to isolate REST calls test.
In Laravel, I understand a few options like using traits DatabaseMigrations
, DatabaseRefresh
, DatabaseTransactions
. But I can't use these for the following reasons:
DatabaseMigrations
: The app does not have proper migrations. Even if it had, those would be quite in-efficient.DatabaseRefresh
: Same as above.DatabaseTransactions
. The problem I see is that call to HTTP API is a completely different process. These are not within the same transaction. So a test that inserts data to setup the test case is not seen by HTTP call. Also, if data is inserted by HTTP calls like will be visible to other tests.
I can't write unit tests without calling HTTP; the app is not written in such a way. Entire code is in Routes
or in Controller
is not otherwise testable.