Skip to content

Instantly share code, notes, and snippets.

@jkovacs618
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkovacs618/31041c41a455374cddc8 to your computer and use it in GitHub Desktop.
Save jkovacs618/31041c41a455374cddc8 to your computer and use it in GitHub Desktop.
Extension of Codeception\Lib\Connector\Yii2, used by CodeceptionYii2Module gist, for Multiple DBs and Shared Transactions.
<?php
namespace tests\codeception\common\Lib\Connector;
use Yii;
/**
* Extended Codeception Yii2 Client:
*
* This custom class extends the original Codeception\Lib\Connector\Yii2 to
* support Multiple DBs and Shared Transactions.
* Used by tests\codeception\common\Module\Yii2.
*/
class Yii2 extends \Codeception\Lib\Connector\Yii2
{
/**
* Array of DB Connection objects indexed by App DB component id string.
* Set by tests\codeception\common\Module\Yii2->_before($test) after creating DB Transactions.
*
* @var Array[string => \yii\db\Connection]
*/
public $dbs = array();
/**
* Create an Application object and set the DB Connection components to this->dbs objects.
*
* @return \yii\web\Application $app
*/
public function startApp()
{
$config = require($this->configFile);
if (!isset($config['class'])) {
$config['class'] = 'yii\web\Application';
}
/** @var \yii\web\Application $app */
$app = Yii::createObject($config);
if(sizeof($this->dbs) > 0) {
foreach($this->dbs as $db_id => $db) {
$app->set($db_id, $db);
}
}
return $app;
}
}
@priyasubramaniyam
Copy link

In yii2-advanced where i have to give the cleanup:false while accessing database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment