tyler43636's avatar

Codeception - Integration testing a package with eloquent

Anyone have any tips for integration testing a package with Eloquent models? I am using codeception with an SQLite database. I'm bootstrapping Eloquent in the codeception _bootstrap file and just pointing it to the same sqlite database I setup in the codeception Db module.

Here is the issue: Codeception and Eloquent are using different PDO connections. This causes an issue where I migrate the database, but the codeception Db module complains that the schema was changed. Anyone know how to get the codeception Db module's PDO connection to pass to eloquent?

0 likes
1 reply
tyler43636's avatar
tyler43636
OP
Best Answer
Level 3

Figured it out!

If anyone else is trying this, I used the Dbh module instead of the Db module. The Dbh module allows you to set the PDO instance for codeception in your bootstrap file.

First, build up the capsule and set the connection.

$capsule->addConnection($dbSettings);
\Codeception\Module\Dbh::$dbh = $capsule->connection('default')->getPdo();

Please or to participate in this conversation.