module-db
module-db copied to clipboard
feat: allow developer to define own connection
Allow user to create connection outside of module-db, or even use connection from different module;
You could define class MyDb
with method getConnection
which will return instance of \Codeception\Lib\Driver\Db
class
class MyDB
{
protected static $connection;
public static function setConnection($connection)
{
self::$connection = $connection;
}
public static function getConnection($databaseKey, $databaseConfig, $dbModule)
{
return new class (self::$connection) extends \Codeception\Lib\Driver\Db {
public function __construct(protected $connection)
{
}
public function getDbh(): \PDO
{
return $this->connection->getNativeConnection();
}
};
}
}