yiiapi/tests/framework/db/ar/CActiveRecord2Test.php
(开头部分) 21KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
Yii::import('system.db.CDbConnection');
Yii::import('system.db.ar.CActiveRecord');
require_once(dirname(__FILE__).'/../data/models2.php');
class CActiveRecord2Test extends CTestCase
{
/**
* @var CDbConnection
*/
private $db;
public function setUp()
{
if(!extension_loaded('pdo') || !extension_loaded('pdo_pgsql'))
$this->markTestSkipped('PDO and PostgreSQL extensions are required.');
$this->db=new CDbConnection('pgsql:host=127.0.0.1;dbname=yii','test','test');
try
{
$this->db->active=true;
}
catch(Exception $e)
{
$schemaFile=realpath(dirname(__FILE__).'/../data/postgres.sql');
$this->markTestSkipped("Please read $schemaFile for details on setting up the test environment for PostgreSQL test case.");
}
try { $this->db->createCommand('DROP SCHEMA test CASCADE')->execute(); } catch(Exception $e) { }
try { $this->db->createCommand('DROP TABLE yii_types CASCADE')->execute(); } catch(Exception $e) { }
$sqls=file_get_contents(dirname(__FILE__).'/../data/postgres.sql');
foreach(explode(';',$sqls) as $sql)
{
if(trim($sql)!=='')
$this->db->createCommand($sql)->execute();
}
$this->db->active=false;
$config=array(
'basePath'=>dirname(__FILE__),
'components'=>array(
'db'=>array(
'class'=>'system.db.CDbConnection',
'connectionString'=>'pgsql:host=127.0.0.1;dbname=yii',
'username'=>'test',
'password'=>'test',
),
),
);
$app=new TestApplication($config);
$app->db->active=true;
CActiveRecord::$db=$this->db=$app->db;
}
public function tearDown()
{
$this->db->active=false;
}
后面还有 566 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
