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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
0ba6b4bd
Commit
0ba6b4bd
authored
Jan 30, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
376dd0d4
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
...
@@ -243,7 +243,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -243,7 +243,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* (which means the column contains a DB expression).
* (which means the column contains a DB expression).
* @param string $option additional option that should be appended to the 'SELECT' keyword. For example,
* @param string $option additional option that should be appended to the 'SELECT' keyword. For example,
* in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used.
* in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
select
(
$columns
=
'*'
,
$option
=
''
)
public
function
select
(
$columns
=
'*'
,
$option
=
''
)
{
{
...
@@ -254,7 +254,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -254,7 +254,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
/**
/**
* Sets the value indicating whether to SELECT DISTINCT or not.
* Sets the value indicating whether to SELECT DISTINCT or not.
* @param bool $value whether to SELECT DISTINCT or not.
* @param bool $value whether to SELECT DISTINCT or not.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
distinct
(
$value
=
true
)
public
function
distinct
(
$value
=
true
)
{
{
...
@@ -269,7 +269,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -269,7 +269,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Table names can contain schema prefixes (e.g. 'public.tbl_user') and/or table aliases (e.g. 'tbl_user u').
* Table names can contain schema prefixes (e.g. 'public.tbl_user') and/or table aliases (e.g. 'tbl_user u').
* The method will automatically quote the table names unless it contains some parenthesis
* The method will automatically quote the table names unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
* (which means the table is given as a sub-query or DB expression).
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
from
(
$tables
)
public
function
from
(
$tables
)
{
{
...
@@ -344,7 +344,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -344,7 +344,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* @param array $params the parameters (name=>value) to be bound to the query.
* @param array $params the parameters (name=>value) to be bound to the query.
* For anonymous parameters, they can alternatively be specified as separate parameters to this method.
* For anonymous parameters, they can alternatively be specified as separate parameters to this method.
* For example, `where('type=? AND status=?', 100, 1)`.
* For example, `where('type=? AND status=?', 100, 1)`.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see andWhere()
* @see andWhere()
* @see orWhere()
* @see orWhere()
*/
*/
...
@@ -365,7 +365,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -365,7 +365,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* on how to specify this parameter.
* on how to specify this parameter.
* @param array $params the parameters (name=>value) to be bound to the query.
* @param array $params the parameters (name=>value) to be bound to the query.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see where()
* @see where()
* @see orWhere()
* @see orWhere()
*/
*/
...
@@ -386,7 +386,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -386,7 +386,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* on how to specify this parameter.
* on how to specify this parameter.
* @param array $params the parameters (name=>value) to be bound to the query.
* @param array $params the parameters (name=>value) to be bound to the query.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see where()
* @see where()
* @see andWhere()
* @see andWhere()
*/
*/
...
@@ -410,7 +410,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -410,7 +410,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Please refer to [[where()]] on how to specify this parameter.
* Please refer to [[where()]] on how to specify this parameter.
* @param array $params the parameters (name=>value) to be bound to the query.
* @param array $params the parameters (name=>value) to be bound to the query.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
join
(
$table
,
$condition
,
$params
=
array
())
public
function
join
(
$table
,
$condition
,
$params
=
array
())
{
{
...
@@ -431,7 +431,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -431,7 +431,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* @param string|array $condition the join condition that should appear in the ON part.
* @param string|array $condition the join condition that should appear in the ON part.
* Please refer to [[where()]] on how to specify this parameter.
* Please refer to [[where()]] on how to specify this parameter.
* @param array $params the parameters (name=>value) to be bound to the query
* @param array $params the parameters (name=>value) to be bound to the query
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
leftJoin
(
$table
,
$condition
,
$params
=
array
())
public
function
leftJoin
(
$table
,
$condition
,
$params
=
array
())
{
{
...
@@ -452,7 +452,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -452,7 +452,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* @param string|array $condition the join condition that should appear in the ON part.
* @param string|array $condition the join condition that should appear in the ON part.
* Please refer to [[where()]] on how to specify this parameter.
* Please refer to [[where()]] on how to specify this parameter.
* @param array $params the parameters (name=>value) to be bound to the query
* @param array $params the parameters (name=>value) to be bound to the query
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
rightJoin
(
$table
,
$condition
,
$params
=
array
())
public
function
rightJoin
(
$table
,
$condition
,
$params
=
array
())
{
{
...
@@ -471,7 +471,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -471,7 +471,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
* The method will automatically quote the table name unless it contains some parenthesis
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
* (which means the table is given as a sub-query or DB expression).
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
crossJoin
(
$table
)
public
function
crossJoin
(
$table
)
{
{
...
@@ -486,7 +486,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -486,7 +486,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
* The method will automatically quote the table name unless it contains some parenthesis
* The method will automatically quote the table name unless it contains some parenthesis
* (which means the table is given as a sub-query or DB expression).
* (which means the table is given as a sub-query or DB expression).
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
naturalJoin
(
$table
)
public
function
naturalJoin
(
$table
)
{
{
...
@@ -500,7 +500,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -500,7 +500,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')).
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')).
* The method will automatically quote the column names unless a column contains some parenthesis
* The method will automatically quote the column names unless a column contains some parenthesis
* (which means the column contains a DB expression).
* (which means the column contains a DB expression).
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see addGroupBy()
* @see addGroupBy()
*/
*/
public
function
groupBy
(
$columns
)
public
function
groupBy
(
$columns
)
...
@@ -515,7 +515,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -515,7 +515,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')).
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')).
* The method will automatically quote the column names unless a column contains some parenthesis
* The method will automatically quote the column names unless a column contains some parenthesis
* (which means the column contains a DB expression).
* (which means the column contains a DB expression).
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see groupBy()
* @see groupBy()
*/
*/
public
function
addGroupBy
(
$columns
)
public
function
addGroupBy
(
$columns
)
...
@@ -530,7 +530,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -530,7 +530,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Please refer to [[where()]] on how to specify this parameter.
* Please refer to [[where()]] on how to specify this parameter.
* @param array $params the parameters (name=>value) to be bound to the query.
* @param array $params the parameters (name=>value) to be bound to the query.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see andHaving()
* @see andHaving()
* @see orHaving()
* @see orHaving()
*/
*/
...
@@ -551,7 +551,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -551,7 +551,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* on how to specify this parameter.
* on how to specify this parameter.
* @param array $params the parameters (name=>value) to be bound to the query.
* @param array $params the parameters (name=>value) to be bound to the query.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see having()
* @see having()
* @see orHaving()
* @see orHaving()
*/
*/
...
@@ -572,7 +572,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -572,7 +572,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* on how to specify this parameter.
* on how to specify this parameter.
* @param array $params the parameters (name=>value) to be bound to the query.
* @param array $params the parameters (name=>value) to be bound to the query.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see having()
* @see having()
* @see andHaving()
* @see andHaving()
*/
*/
...
@@ -592,7 +592,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -592,7 +592,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. array('id ASC', 'name DESC')).
* Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. array('id ASC', 'name DESC')).
* The method will automatically quote the column names unless a column contains some parenthesis
* The method will automatically quote the column names unless a column contains some parenthesis
* (which means the column contains a DB expression).
* (which means the column contains a DB expression).
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see addOrderBy()
* @see addOrderBy()
*/
*/
public
function
orderBy
(
$columns
)
public
function
orderBy
(
$columns
)
...
@@ -607,7 +607,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -607,7 +607,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. array('id ASC', 'name DESC')).
* Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. array('id ASC', 'name DESC')).
* The method will automatically quote the column names unless a column contains some parenthesis
* The method will automatically quote the column names unless a column contains some parenthesis
* (which means the column contains a DB expression).
* (which means the column contains a DB expression).
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see orderBy()
* @see orderBy()
*/
*/
public
function
addOrderBy
(
$columns
)
public
function
addOrderBy
(
$columns
)
...
@@ -619,7 +619,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -619,7 +619,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
/**
/**
* Sets the LIMIT part of the query.
* Sets the LIMIT part of the query.
* @param integer $limit the limit
* @param integer $limit the limit
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
limit
(
$limit
)
public
function
limit
(
$limit
)
{
{
...
@@ -630,7 +630,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -630,7 +630,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
/**
/**
* Sets the OFFSET part of the query.
* Sets the OFFSET part of the query.
* @param integer $offset the offset
* @param integer $offset the offset
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
offset
(
$offset
)
public
function
offset
(
$offset
)
{
{
...
@@ -641,7 +641,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -641,7 +641,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
/**
/**
* Appends a SQL statement using UNION operator.
* Appends a SQL statement using UNION operator.
* @param string|Query $sql the SQL statement to be appended using UNION
* @param string|Query $sql the SQL statement to be appended using UNION
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
*/
*/
public
function
union
(
$sql
)
public
function
union
(
$sql
)
{
{
...
@@ -654,7 +654,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -654,7 +654,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* @param array list of query parameter values indexed by parameter placeholders.
* @param array list of query parameter values indexed by parameter placeholders.
* For example, `array(':name'=>'Dan', ':age'=>31)`.
* For example, `array(':name'=>'Dan', ':age'=>31)`.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see addParams()
* @see addParams()
*/
*/
public
function
params
(
$params
)
public
function
params
(
$params
)
...
@@ -668,7 +668,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -668,7 +668,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
* @param array list of query parameter values indexed by parameter placeholders.
* @param array list of query parameter values indexed by parameter placeholders.
* For example, `array(':name'=>'Dan', ':age'=>31)`.
* For example, `array(':name'=>'Dan', ':age'=>31)`.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters.
* @return
Bas
eQuery the query object itself
* @return
Activ
eQuery the query object itself
* @see params()
* @see params()
*/
*/
public
function
addParams
(
$params
)
public
function
addParams
(
$params
)
...
@@ -730,9 +730,22 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
...
@@ -730,9 +730,22 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array
protected
function
performCountQuery
()
protected
function
performCountQuery
()
{
{
$this
->
query
->
select
=
'COUNT(*)'
;
if
(
$this
->
sql
===
null
)
{
$command
=
$this
->
query
->
createCommand
(
$this
->
getDbConnection
());
if
(
$this
->
query
->
from
===
null
)
{
$this
->
sql
=
$command
->
getSql
();
$modelClass
=
$this
->
modelClass
;
$tableName
=
$modelClass
::
tableName
();
if
(
$this
->
tableAlias
!==
null
)
{
$tableName
.=
' '
.
$this
->
tableAlias
;
}
$this
->
query
->
from
=
array
(
$tableName
);
}
$this
->
query
->
select
=
'COUNT(*)'
;
$command
=
$this
->
query
->
createCommand
(
$this
->
getDbConnection
());
$this
->
sql
=
$command
->
getSql
();
}
else
{
$command
=
$this
->
getDbConnection
()
->
createCommand
(
$this
->
sql
);
$command
->
bindValues
(
$this
->
query
->
params
);
}
return
$command
->
queryScalar
();
return
$command
->
queryScalar
();
}
}
}
}
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