I have to create phpunit tests for a laravel project. As of now, I have to test the repository classes which contain database queries. The project has no tests folder and no phpunit.xml file so I've just copied those files from laravel's github. The project is using oracle database and it is deployed on AWS. When running the feature test, which bootstraps the laravel app, do I need to be connected to the project's database?
do I need to be connected to the project's database
No, connecting to the project's database will have the side-effect of adding, modifying and/or deleting records in the project's database; which would be inconvenient in local development, but chaotic in production! You should have a separate test database which will allow you to work independently of the real data.
You can use Database Seeders and/or Model Factories to populate the database with the data necessary to run each test example. The RefreshDatabase trait will automatically handle any migrations/transactions necessary to ensure each test runs independently; ensuring data from previous test example(s) do not affect the currently running test.
Thank you. I have already configured the phpunit.xml to use sqlite for testing but when running a test that extends Tests\Testcase would result to this error:
Yajra\Pdo\Oci8\Exceptions\Oci8Exception: ORA-12170: TNS:Connect timeout occurred
So I'm confused why am I getting an oracle error when I have already set the testing db to sqlite. dump(getenv('DB_CONNECTION')); would even show "sqlite"
@GJV okay; that should be enough to use the SQLite database.
Is there anywhere in your application code that expressly uses the Oracle connection; e.g. your Model sets a $connection property; or a query that fully qualifies the table name using the Oracle connection?
@tykus I guess it is needed. I don't have the rights to change anything in the code though. All I have to do is to create the tests. Is there a workaround for this?