mrcrmn's avatar

How to test against an existing Database?

If you need to create an application that interacts with an existing database. What would be the best way to test your application?

I was thinking about:

  1. Creating migrations for the existing tables which only run in the testing environment.
  2. Override the connection to the "default" one in the boot method of the Models

Or is there a better way to do it?

0 likes
4 replies
tykus's avatar

A test database can be easily created from the existing schema; we have a schema:dump command which can facilitate this!

mrcrmn's avatar

That sounds like a great idea! Unfortunately I don't think it would work in this case since we are using an existing sqlrsv database and we want to test against an in memory sqlite database.

1 like
tykus's avatar
tykus
Best Answer
Level 104

@mrcrmn off the top of my head, I don't know what will be different between sqlsrv and sqlite syntax for creating tables etc, but assume there will be issues!

The alternative is a Laravel Migrations Generator package which will generate migrations files instead.

mrcrmn's avatar

@tykus That looks interesting. Thanks, I will check it out 👍

Please or to participate in this conversation.