Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
0ba6b4bd
Commit
0ba6b4bd
authored
Jan 30, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
376dd0d4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
39 deletions
+55
-39
ActiveQuery.php
framework/db/ar/ActiveQuery.php
+39
-26
ActiveRecordTest.php
tests/unit/framework/db/ar/ActiveRecordTest.php
+16
-13
No files found.
framework/db/ar/ActiveQuery.php
View file @
0ba6b4bd
This diff is collapsed.
Click to expand it.
tests/unit/framework/db/ar/ActiveRecordTest.php
View file @
0ba6b4bd
...
@@ -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
Active
Query
;
$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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment