Commit 0ba6b4bd by Qiang Xue

...

parent 376dd0d4
...@@ -32,13 +32,14 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase ...@@ -32,13 +32,14 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase
$this->assertTrue($customers[1] instanceof Customer); $this->assertTrue($customers[1] instanceof Customer);
$this->assertTrue($customers[2] instanceof Customer); $this->assertTrue($customers[2] instanceof Customer);
$this->assertEquals(3, $result->count); $this->assertEquals(3, $result->count);
$this->assertEquals(3, count($result));
// check count first // check count first
$result = Customer::find(); $result = Customer::find();
$this->assertEquals(3, $result->count); $this->assertEquals(3, $result->count);
$customer = $result->one(); $customer = $result->one();
$this->assertTrue($customer instanceof Customer); $this->assertTrue($customer instanceof Customer);
$this->assertEquals(1, $result->count); $this->assertEquals(3, $result->count);
// iterator // iterator
$result = Customer::find(); $result = Customer::find();
...@@ -66,11 +67,14 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase ...@@ -66,11 +67,14 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase
$this->assertEquals(2, $customer->id); $this->assertEquals(2, $customer->id);
// find by Query // find by Query
$query = new ActiveQuery; $query = new Query;
$query->where('id=:id', array(':id'=>2)); $query->where('id=:id', array(':id'=>2));
$customer = Customer::find($query)->one(); $customer = Customer::find($query)->one();
$this->assertTrue($customer instanceof Customer); $this->assertTrue($customer instanceof Customer);
$this->assertEquals('user2', $customer->name); $this->assertEquals('user2', $customer->name);
// find count
$this->assertEquals(3, Customer::find()->count(true));
} }
public function testFindBySql() public function testFindBySql()
...@@ -92,10 +96,9 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase ...@@ -92,10 +96,9 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase
// count // count
$finder = Customer::findBySql('SELECT * FROM tbl_customer ORDER BY id DESC'); $finder = Customer::findBySql('SELECT * FROM tbl_customer ORDER BY id DESC');
$finder->one(); $finder->one();
$this->assertEquals(1, $finder->count); $this->assertEquals(3, $finder->count);
$finder = Customer::findBySql('SELECT * FROM tbl_customer ORDER BY id DESC'); $finder = Customer::findBySql('SELECT * FROM tbl_customer ORDER BY id DESC');
// todo $this->assertEquals(3, $finder->count);
// $this->assertEquals(3, $finder->count);
} }
public function testQueryMethods() public function testQueryMethods()
...@@ -113,12 +116,12 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase ...@@ -113,12 +116,12 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase
$this->assertEquals(3, $customer->id); $this->assertEquals(3, $customer->id);
$this->assertEquals(null, $customer->name); $this->assertEquals(null, $customer->name);
} }
/*
public function testGetSql() public function testGetSql()
{ {
// sql for all // sql for all
$sql = Customer::find()->sql; $sql = Customer::find()->sql;
$this->assertEquals('SELECT * FROM tbl_customer', $sql); $this->assertEquals('SELECT * FROM `tbl_customer`', $sql);
// sql for one row // sql for one row
$sql = Customer::find()->oneSql; $sql = Customer::find()->oneSql;
...@@ -137,12 +140,10 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase ...@@ -137,12 +140,10 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase
public function testMisc() public function testMisc()
{ {
/* // Customer::exists()
* Customer::exists() // Customer::updateAll()
* Customer::updateAll() // Customer::updateCounters()
* Customer::updateCounters() // Customer::deleteAll()
* Customer::deleteAll()
*/
} }
public function testInsert() public function testInsert()
...@@ -170,4 +171,5 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase ...@@ -170,4 +171,5 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase
{ {
} }
*/
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment