Files
yii2/tests/unit/MysqlTestCase.php
Carsten Brandt 4d59587320 fixed constructor overriding in test classes
now use setUp() instead
2013-03-29 01:10:03 +01:00

36 lines
793 B
PHP

<?php
namespace yiiunit;
class MysqlTestCase extends TestCase
{
protected function setUp()
{
if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) {
$this->markTestSkipped('pdo and pdo_mysql extensions are required.');
}
}
/**
* @param bool $reset whether to clean up the test database
* @return \yii\db\Connection
*/
public function getConnection($reset = true)
{
$params = $this->getParam('mysql');
$db = new \yii\db\Connection;
$db->dsn = $params['dsn'];
$db->username = $params['username'];
$db->password = $params['password'];
if ($reset) {
$db->open();
$lines = explode(';', file_get_contents($params['fixture']));
foreach ($lines as $line) {
if (trim($line) !== '') {
$db->pdo->exec($line);
}
}
}
return $db;
}
}