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
0ec5643c
Commit
0ec5643c
authored
Jan 19, 2014
by
Alexander Kochetov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit tests updated
parent
6051253e
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
56 additions
and
60 deletions
+56
-60
Order.php
tests/unit/data/ar/Order.php
+2
-2
Customer.php
tests/unit/data/ar/elasticsearch/Customer.php
+1
-1
Order.php
tests/unit/data/ar/elasticsearch/Order.php
+4
-4
Order.php
tests/unit/data/ar/redis/Order.php
+3
-4
cubrid.sql
tests/unit/data/cubrid.sql
+4
-4
mssql.sql
tests/unit/data/mssql.sql
+4
-4
mysql.sql
tests/unit/data/mysql.sql
+4
-4
postgres.sql
tests/unit/data/postgres.sql
+5
-6
sqlite.sql
tests/unit/data/sqlite.sql
+4
-4
ActiveRecordTest.php
tests/unit/extensions/elasticsearch/ActiveRecordTest.php
+6
-7
ActiveRecordTest.php
tests/unit/extensions/redis/ActiveRecordTest.php
+4
-5
ActiveRecordTestTrait.php
tests/unit/framework/ar/ActiveRecordTestTrait.php
+3
-3
AutoTimestampTest.php
tests/unit/framework/behaviors/AutoTimestampTest.php
+12
-12
No files found.
tests/unit/data/ar/Order.php
View file @
0ec5643c
...
@@ -7,7 +7,7 @@ namespace yiiunit\data\ar;
...
@@ -7,7 +7,7 @@ namespace yiiunit\data\ar;
*
*
* @property integer $id
* @property integer $id
* @property integer $customer_id
* @property integer $customer_id
* @property integer $create
_time
* @property integer $create
d_at
* @property string $total
* @property string $total
*/
*/
class
Order
extends
ActiveRecord
class
Order
extends
ActiveRecord
...
@@ -68,7 +68,7 @@ class Order extends ActiveRecord
...
@@ -68,7 +68,7 @@ class Order extends ActiveRecord
public
function
beforeSave
(
$insert
)
public
function
beforeSave
(
$insert
)
{
{
if
(
parent
::
beforeSave
(
$insert
))
{
if
(
parent
::
beforeSave
(
$insert
))
{
$this
->
create
_time
=
time
();
$this
->
create
d_at
=
time
();
return
true
;
return
true
;
}
else
{
}
else
{
return
false
;
return
false
;
...
...
tests/unit/data/ar/elasticsearch/Customer.php
View file @
0ec5643c
...
@@ -32,7 +32,7 @@ class Customer extends ActiveRecord
...
@@ -32,7 +32,7 @@ class Customer extends ActiveRecord
public
function
getOrders
()
public
function
getOrders
()
{
{
return
$this
->
hasMany
(
Order
::
className
(),
array
(
'customer_id'
=>
'id'
))
->
orderBy
(
'create
_time
'
);
return
$this
->
hasMany
(
Order
::
className
(),
array
(
'customer_id'
=>
'id'
))
->
orderBy
(
'create
d_at
'
);
}
}
public
static
function
active
(
$query
)
public
static
function
active
(
$query
)
...
...
tests/unit/data/ar/elasticsearch/Order.php
View file @
0ec5643c
...
@@ -8,7 +8,7 @@ use yii\elasticsearch\Command;
...
@@ -8,7 +8,7 @@ use yii\elasticsearch\Command;
*
*
* @property integer $id
* @property integer $id
* @property integer $customer_id
* @property integer $customer_id
* @property integer $create
_time
* @property integer $create
d_at
* @property string $total
* @property string $total
*/
*/
class
Order
extends
ActiveRecord
class
Order
extends
ActiveRecord
...
@@ -20,7 +20,7 @@ class Order extends ActiveRecord
...
@@ -20,7 +20,7 @@ class Order extends ActiveRecord
public
function
attributes
()
public
function
attributes
()
{
{
return
[
'id'
,
'customer_id'
,
'create
_time
'
,
'total'
];
return
[
'id'
,
'customer_id'
,
'create
d_at
'
,
'total'
];
}
}
public
function
getCustomer
()
public
function
getCustomer
()
...
@@ -65,7 +65,7 @@ class Order extends ActiveRecord
...
@@ -65,7 +65,7 @@ class Order extends ActiveRecord
public
function
beforeSave
(
$insert
)
public
function
beforeSave
(
$insert
)
{
{
if
(
parent
::
beforeSave
(
$insert
))
{
if
(
parent
::
beforeSave
(
$insert
))
{
// $this->create
_time
= time();
// $this->create
d_at
= time();
return
true
;
return
true
;
}
else
{
}
else
{
return
false
;
return
false
;
...
@@ -84,7 +84,7 @@ class Order extends ActiveRecord
...
@@ -84,7 +84,7 @@ class Order extends ActiveRecord
"_id"
=>
[
"path"
=>
"id"
,
"index"
=>
"not_analyzed"
,
"store"
=>
"yes"
],
"_id"
=>
[
"path"
=>
"id"
,
"index"
=>
"not_analyzed"
,
"store"
=>
"yes"
],
"properties"
=>
[
"properties"
=>
[
"customer_id"
=>
[
"type"
=>
"integer"
],
"customer_id"
=>
[
"type"
=>
"integer"
],
// "create
_time
" => ["type" => "string", "index" => "not_analyzed"],
// "create
d_at
" => ["type" => "string", "index" => "not_analyzed"],
"total"
=>
[
"type"
=>
"integer"
],
"total"
=>
[
"type"
=>
"integer"
],
]
]
]
]
...
...
tests/unit/data/ar/redis/Order.php
View file @
0ec5643c
...
@@ -6,7 +6,7 @@ class Order extends ActiveRecord
...
@@ -6,7 +6,7 @@ class Order extends ActiveRecord
{
{
public
function
attributes
()
public
function
attributes
()
{
{
return
[
'id'
,
'customer_id'
,
'create
_time
'
,
'total'
];
return
[
'id'
,
'customer_id'
,
'create
d_at
'
,
'total'
];
}
}
public
function
getCustomer
()
public
function
getCustomer
()
...
@@ -53,10 +53,10 @@ class Order extends ActiveRecord
...
@@ -53,10 +53,10 @@ class Order extends ActiveRecord
public
function
beforeSave
(
$insert
)
public
function
beforeSave
(
$insert
)
{
{
if
(
parent
::
beforeSave
(
$insert
))
{
if
(
parent
::
beforeSave
(
$insert
))
{
$this
->
create
_time
=
time
();
$this
->
create
d_at
=
time
();
return
true
;
return
true
;
}
else
{
}
else
{
return
false
;
return
false
;
}
}
}
}
}
}
\ No newline at end of file
tests/unit/data/cubrid.sql
View file @
0ec5643c
...
@@ -46,7 +46,7 @@ CREATE TABLE `tbl_item` (
...
@@ -46,7 +46,7 @@ CREATE TABLE `tbl_item` (
CREATE
TABLE
`tbl_order`
(
CREATE
TABLE
`tbl_order`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`customer_id`
int
(
11
)
NOT
NULL
,
`customer_id`
int
(
11
)
NOT
NULL
,
`create
_time
`
int
(
11
)
NOT
NULL
,
`create
d_at
`
int
(
11
)
NOT
NULL
,
`total`
decimal
(
10
,
0
)
NOT
NULL
,
`total`
decimal
(
10
,
0
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_order_customer_id`
FOREIGN
KEY
(
`customer_id`
)
REFERENCES
`tbl_customer`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_order_customer_id`
FOREIGN
KEY
(
`customer_id`
)
REFERENCES
`tbl_customer`
(
`id`
)
ON
DELETE
CASCADE
...
@@ -107,9 +107,9 @@ INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
...
@@ -107,9 +107,9 @@ INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
...
...
tests/unit/data/mssql.sql
View file @
0ec5643c
...
@@ -37,7 +37,7 @@ CREATE TABLE [dbo].[tbl_item] (
...
@@ -37,7 +37,7 @@ CREATE TABLE [dbo].[tbl_item] (
CREATE
TABLE
[
dbo
].[
tbl_order
]
(
CREATE
TABLE
[
dbo
].[
tbl_order
]
(
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
customer_id
]
[
int
]
NOT
NULL
,
[
customer_id
]
[
int
]
NOT
NULL
,
[
create
_time
]
[
int
]
NOT
NULL
,
[
create
d_at
]
[
int
]
NOT
NULL
,
[
total
]
[
decimal
](
10
,
0
)
NOT
NULL
,
[
total
]
[
decimal
](
10
,
0
)
NOT
NULL
,
CONSTRAINT
[
PK_order
]
PRIMARY
KEY
CLUSTERED
(
CONSTRAINT
[
PK_order
]
PRIMARY
KEY
CLUSTERED
(
[
id
]
ASC
[
id
]
ASC
...
@@ -92,9 +92,9 @@ INSERT INTO [dbo].[tbl_item] ([name], [category_id]) VALUES ('Ice Age', 2);
...
@@ -92,9 +92,9 @@ INSERT INTO [dbo].[tbl_item] ([name], [category_id]) VALUES ('Ice Age', 2);
INSERT
INTO
[
dbo
].[
tbl_item
]
([
name
],
[
category_id
])
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
[
dbo
].[
tbl_item
]
([
name
],
[
category_id
])
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
[
dbo
].[
tbl_item
]
([
name
],
[
category_id
])
VALUES
(
'Cars'
,
2
);
INSERT
INTO
[
dbo
].[
tbl_item
]
([
name
],
[
category_id
])
VALUES
(
'Cars'
,
2
);
INSERT
INTO
[
dbo
].[
tbl_order
]
([
customer_id
],
[
create
_time
],
[
total
])
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
[
dbo
].[
tbl_order
]
([
customer_id
],
[
create
d_at
],
[
total
])
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
[
dbo
].[
tbl_order
]
([
customer_id
],
[
create
_time
],
[
total
])
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
[
dbo
].[
tbl_order
]
([
customer_id
],
[
create
d_at
],
[
total
])
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
[
dbo
].[
tbl_order
]
([
customer_id
],
[
create
_time
],
[
total
])
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
[
dbo
].[
tbl_order
]
([
customer_id
],
[
create
d_at
],
[
total
])
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
[
dbo
].[
tbl_order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
[
dbo
].[
tbl_order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
[
dbo
].[
tbl_order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
[
dbo
].[
tbl_order_item
]
([
order_id
],
[
item_id
],
[
quantity
],
[
subtotal
])
VALUES
(
1
,
2
,
2
,
40
.
0
);
...
...
tests/unit/data/mysql.sql
View file @
0ec5643c
...
@@ -47,7 +47,7 @@ CREATE TABLE `tbl_item` (
...
@@ -47,7 +47,7 @@ CREATE TABLE `tbl_item` (
CREATE
TABLE
`tbl_order`
(
CREATE
TABLE
`tbl_order`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`customer_id`
int
(
11
)
NOT
NULL
,
`customer_id`
int
(
11
)
NOT
NULL
,
`create
_time
`
int
(
11
)
NOT
NULL
,
`create
d_at
`
int
(
11
)
NOT
NULL
,
`total`
decimal
(
10
,
0
)
NOT
NULL
,
`total`
decimal
(
10
,
0
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`FK_order_customer_id`
FOREIGN
KEY
(
`customer_id`
)
REFERENCES
`tbl_customer`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_order_customer_id`
FOREIGN
KEY
(
`customer_id`
)
REFERENCES
`tbl_customer`
(
`id`
)
ON
DELETE
CASCADE
...
@@ -109,9 +109,9 @@ INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
...
@@ -109,9 +109,9 @@ INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
...
...
tests/unit/data/postgres.sql
View file @
0ec5643c
...
@@ -43,7 +43,7 @@ CREATE TABLE tbl_item (
...
@@ -43,7 +43,7 @@ CREATE TABLE tbl_item (
CREATE
TABLE
tbl_order
(
CREATE
TABLE
tbl_order
(
id
serial
not
null
primary
key
,
id
serial
not
null
primary
key
,
customer_id
integer
NOT
NULL
references
tbl_customer
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
,
customer_id
integer
NOT
NULL
references
tbl_customer
(
id
)
on
UPDATE
CASCADE
on
DELETE
CASCADE
,
create
_time
integer
NOT
NULL
,
create
d_at
integer
NOT
NULL
,
total
decimal
(
10
,
0
)
NOT
NULL
total
decimal
(
10
,
0
)
NOT
NULL
);
);
...
@@ -92,9 +92,9 @@ INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
...
@@ -92,9 +92,9 @@ INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
...
@@ -130,4 +130,4 @@ INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
...
@@ -130,4 +130,4 @@ INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
3
,
'ref_to_3'
,
3
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
4
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
5
,
'ref_to_4'
,
4
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
INSERT
INTO
tbl_validator_ref
(
id
,
a_field
,
ref
)
VALUES
(
6
,
'ref_to_5'
,
5
);
\ No newline at end of file
tests/unit/data/sqlite.sql
View file @
0ec5643c
...
@@ -37,7 +37,7 @@ CREATE TABLE tbl_item (
...
@@ -37,7 +37,7 @@ CREATE TABLE tbl_item (
CREATE
TABLE
tbl_order
(
CREATE
TABLE
tbl_order
(
id
INTEGER
NOT
NULL
,
id
INTEGER
NOT
NULL
,
customer_id
INTEGER
NOT
NULL
,
customer_id
INTEGER
NOT
NULL
,
create
_time
INTEGER
NOT
NULL
,
create
d_at
INTEGER
NOT
NULL
,
total
decimal
(
10
,
0
)
NOT
NULL
,
total
decimal
(
10
,
0
)
NOT
NULL
,
PRIMARY
KEY
(
id
)
PRIMARY
KEY
(
id
)
);
);
...
@@ -94,9 +94,9 @@ INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
...
@@ -94,9 +94,9 @@ INSERT INTO tbl_item (name, category_id) VALUES ('Ice Age', 2);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Toy Story'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_item
(
name
,
category_id
)
VALUES
(
'Cars'
,
2
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
1
,
1325282384
,
110
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
2
,
1325334482
,
33
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
_time
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_order
(
customer_id
,
create
d_at
,
total
)
VALUES
(
2
,
1325502201
,
40
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
1
,
1
,
30
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
INSERT
INTO
tbl_order_item
(
order_id
,
item_id
,
quantity
,
subtotal
)
VALUES
(
1
,
2
,
2
,
40
.
0
);
...
...
tests/unit/extensions/elasticsearch/ActiveRecordTest.php
View file @
0ec5643c
...
@@ -100,15 +100,15 @@ class ActiveRecordTest extends ElasticSearchTestCase
...
@@ -100,15 +100,15 @@ class ActiveRecordTest extends ElasticSearchTestCase
$order
=
new
Order
();
$order
=
new
Order
();
$order
->
id
=
1
;
$order
->
id
=
1
;
$order
->
setAttributes
([
'customer_id'
=>
1
,
'create
_time
'
=>
1325282384
,
'total'
=>
110.0
],
false
);
$order
->
setAttributes
([
'customer_id'
=>
1
,
'create
d_at
'
=>
1325282384
,
'total'
=>
110.0
],
false
);
$order
->
save
(
false
);
$order
->
save
(
false
);
$order
=
new
Order
();
$order
=
new
Order
();
$order
->
id
=
2
;
$order
->
id
=
2
;
$order
->
setAttributes
([
'customer_id'
=>
2
,
'create
_time
'
=>
1325334482
,
'total'
=>
33.0
],
false
);
$order
->
setAttributes
([
'customer_id'
=>
2
,
'create
d_at
'
=>
1325334482
,
'total'
=>
33.0
],
false
);
$order
->
save
(
false
);
$order
->
save
(
false
);
$order
=
new
Order
();
$order
=
new
Order
();
$order
->
id
=
3
;
$order
->
id
=
3
;
$order
->
setAttributes
([
'customer_id'
=>
2
,
'create
_time
'
=>
1325502201
,
'total'
=>
40.0
],
false
);
$order
->
setAttributes
([
'customer_id'
=>
2
,
'create
d_at
'
=>
1325502201
,
'total'
=>
40.0
],
false
);
$order
->
save
(
false
);
$order
->
save
(
false
);
$orderItem
=
new
OrderItem
();
$orderItem
=
new
OrderItem
();
...
@@ -239,14 +239,14 @@ class ActiveRecordTest extends ElasticSearchTestCase
...
@@ -239,14 +239,14 @@ class ActiveRecordTest extends ElasticSearchTestCase
$orders
=
$customer
->
orders
;
$orders
=
$customer
->
orders
;
$this
->
assertEquals
(
2
,
count
(
$orders
));
$this
->
assertEquals
(
2
,
count
(
$orders
));
$orders
=
$customer
->
getOrders
()
->
where
([
'between'
,
'create
_time
'
,
1325334000
,
1325400000
])
->
all
();
$orders
=
$customer
->
getOrders
()
->
where
([
'between'
,
'create
d_at
'
,
1325334000
,
1325400000
])
->
all
();
$this
->
assertEquals
(
1
,
count
(
$orders
));
$this
->
assertEquals
(
1
,
count
(
$orders
));
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
id
);
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
id
);
}
}
public
function
testFindEagerViaRelation
()
public
function
testFindEagerViaRelation
()
{
{
$orders
=
Order
::
find
()
->
with
(
'items'
)
->
orderBy
(
'create
_time
'
)
->
all
();
$orders
=
Order
::
find
()
->
with
(
'items'
)
->
orderBy
(
'create
d_at
'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertEquals
(
3
,
count
(
$orders
));
$order
=
$orders
[
0
];
$order
=
$orders
[
0
];
$this
->
assertEquals
(
1
,
$order
->
id
);
$this
->
assertEquals
(
1
,
$order
->
id
);
...
@@ -529,4 +529,4 @@ class ActiveRecordTest extends ElasticSearchTestCase
...
@@ -529,4 +529,4 @@ class ActiveRecordTest extends ElasticSearchTestCase
// TODO test AR with not mapped PK
// TODO test AR with not mapped PK
}
}
\ No newline at end of file
tests/unit/extensions/redis/ActiveRecordTest.php
View file @
0ec5643c
...
@@ -63,13 +63,13 @@ class ActiveRecordTest extends RedisTestCase
...
@@ -63,13 +63,13 @@ class ActiveRecordTest extends RedisTestCase
$item
->
save
(
false
);
$item
->
save
(
false
);
$order
=
new
Order
();
$order
=
new
Order
();
$order
->
setAttributes
([
'customer_id'
=>
1
,
'create
_time
'
=>
1325282384
,
'total'
=>
110.0
],
false
);
$order
->
setAttributes
([
'customer_id'
=>
1
,
'create
d_at
'
=>
1325282384
,
'total'
=>
110.0
],
false
);
$order
->
save
(
false
);
$order
->
save
(
false
);
$order
=
new
Order
();
$order
=
new
Order
();
$order
->
setAttributes
([
'customer_id'
=>
2
,
'create
_time
'
=>
1325334482
,
'total'
=>
33.0
],
false
);
$order
->
setAttributes
([
'customer_id'
=>
2
,
'create
d_at
'
=>
1325334482
,
'total'
=>
33.0
],
false
);
$order
->
save
(
false
);
$order
->
save
(
false
);
$order
=
new
Order
();
$order
=
new
Order
();
$order
->
setAttributes
([
'customer_id'
=>
2
,
'create
_time
'
=>
1325502201
,
'total'
=>
40.0
],
false
);
$order
->
setAttributes
([
'customer_id'
=>
2
,
'create
d_at
'
=>
1325502201
,
'total'
=>
40.0
],
false
);
$order
->
save
(
false
);
$order
->
save
(
false
);
$orderItem
=
new
OrderItem
();
$orderItem
=
new
OrderItem
();
...
@@ -228,4 +228,4 @@ class ActiveRecordTest extends RedisTestCase
...
@@ -228,4 +228,4 @@ class ActiveRecordTest extends RedisTestCase
$this
->
assertNull
(
OrderItem
::
find
(
$pk
));
$this
->
assertNull
(
OrderItem
::
find
(
$pk
));
$this
->
assertNotNull
(
OrderItem
::
find
([
'order_id'
=>
2
,
'item_id'
=>
10
]));
$this
->
assertNotNull
(
OrderItem
::
find
([
'order_id'
=>
2
,
'item_id'
=>
10
]));
}
}
}
}
\ No newline at end of file
tests/unit/framework/ar/ActiveRecordTestTrait.php
View file @
0ec5643c
...
@@ -502,7 +502,7 @@ trait ActiveRecordTestTrait
...
@@ -502,7 +502,7 @@ trait ActiveRecordTestTrait
/*
/*
Item (name, category_id)
Item (name, category_id)
Order (customer_id, create
_time
, total)
Order (customer_id, create
d_at
, total)
OrderItem (order_id, item_id, quantity, subtotal)
OrderItem (order_id, item_id, quantity, subtotal)
Result should be the following:
Result should be the following:
...
@@ -530,7 +530,7 @@ trait ActiveRecordTestTrait
...
@@ -530,7 +530,7 @@ trait ActiveRecordTestTrait
- itemsInOrder:
- itemsInOrder:
Item 3: 'Ice Age', 2
Item 3: 'Ice Age', 2
*/
*/
$orders
=
$this
->
callOrderFind
()
->
with
(
'itemsInOrder1'
)
->
orderBy
(
'create
_time
'
)
->
all
();
$orders
=
$this
->
callOrderFind
()
->
with
(
'itemsInOrder1'
)
->
orderBy
(
'create
d_at
'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertEquals
(
3
,
count
(
$orders
));
$order
=
$orders
[
0
];
$order
=
$orders
[
0
];
...
@@ -558,7 +558,7 @@ trait ActiveRecordTestTrait
...
@@ -558,7 +558,7 @@ trait ActiveRecordTestTrait
// different order in via table
// different order in via table
public
function
testFindEagerViaRelationPreserveOrderB
()
public
function
testFindEagerViaRelationPreserveOrderB
()
{
{
$orders
=
$this
->
callOrderFind
()
->
with
(
'itemsInOrder2'
)
->
orderBy
(
'create
_time
'
)
->
all
();
$orders
=
$this
->
callOrderFind
()
->
with
(
'itemsInOrder2'
)
->
orderBy
(
'create
d_at
'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertEquals
(
3
,
count
(
$orders
));
$order
=
$orders
[
0
];
$order
=
$orders
[
0
];
...
...
tests/unit/framework/behaviors/AutoTimestampTest.php
View file @
0ec5643c
...
@@ -41,8 +41,8 @@ class AutoTimestampTest extends TestCase
...
@@ -41,8 +41,8 @@ class AutoTimestampTest extends TestCase
$columns
=
[
$columns
=
[
'id'
=>
'pk'
,
'id'
=>
'pk'
,
'create
_time
'
=>
'integer'
,
'create
d_at
'
=>
'integer'
,
'update
_time
'
=>
'integer'
,
'update
d_at
'
=>
'integer'
,
];
];
Yii
::
$app
->
getDb
()
->
createCommand
()
->
createTable
(
'test_auto_timestamp'
,
$columns
)
->
execute
();
Yii
::
$app
->
getDb
()
->
createCommand
()
->
createTable
(
'test_auto_timestamp'
,
$columns
)
->
execute
();
}
}
...
@@ -62,8 +62,8 @@ class AutoTimestampTest extends TestCase
...
@@ -62,8 +62,8 @@ class AutoTimestampTest extends TestCase
$model
=
new
ActiveRecordAutoTimestamp
();
$model
=
new
ActiveRecordAutoTimestamp
();
$model
->
save
(
false
);
$model
->
save
(
false
);
$this
->
assertTrue
(
$model
->
create
_time
>=
$currentTime
);
$this
->
assertTrue
(
$model
->
create
d_at
>=
$currentTime
);
$this
->
assertTrue
(
$model
->
update
_time
>=
$currentTime
);
$this
->
assertTrue
(
$model
->
update
d_at
>=
$currentTime
);
}
}
/**
/**
...
@@ -78,12 +78,12 @@ class AutoTimestampTest extends TestCase
...
@@ -78,12 +78,12 @@ class AutoTimestampTest extends TestCase
$enforcedTime
=
$currentTime
-
100
;
$enforcedTime
=
$currentTime
-
100
;
$model
->
create
_time
=
$enforcedTime
;
$model
->
create
d_at
=
$enforcedTime
;
$model
->
update
_time
=
$enforcedTime
;
$model
->
update
d_at
=
$enforcedTime
;
$model
->
save
(
false
);
$model
->
save
(
false
);
$this
->
assertEquals
(
$enforcedTime
,
$model
->
create
_time
,
'Create time has been set on update!'
);
$this
->
assertEquals
(
$enforcedTime
,
$model
->
create
d_at
,
'Create time has been set on update!'
);
$this
->
assertTrue
(
$model
->
update
_time
>=
$currentTime
,
'Update time has NOT been set on update!'
);
$this
->
assertTrue
(
$model
->
update
d_at
>=
$currentTime
,
'Update time has NOT been set on update!'
);
}
}
}
}
...
@@ -91,8 +91,8 @@ class AutoTimestampTest extends TestCase
...
@@ -91,8 +91,8 @@ class AutoTimestampTest extends TestCase
* Test Active Record class with [[AutoTimestamp]] behavior attached.
* Test Active Record class with [[AutoTimestamp]] behavior attached.
*
*
* @property integer $id
* @property integer $id
* @property integer $create
_time
* @property integer $create
d_at
* @property integer $update
_time
* @property integer $update
d_at
*/
*/
class
ActiveRecordAutoTimestamp
extends
ActiveRecord
class
ActiveRecordAutoTimestamp
extends
ActiveRecord
{
{
...
@@ -102,8 +102,8 @@ class ActiveRecordAutoTimestamp extends ActiveRecord
...
@@ -102,8 +102,8 @@ class ActiveRecordAutoTimestamp extends ActiveRecord
'timestamp'
=>
[
'timestamp'
=>
[
'class'
=>
AutoTimestamp
::
className
(),
'class'
=>
AutoTimestamp
::
className
(),
'attributes'
=>
[
'attributes'
=>
[
static
::
EVENT_BEFORE_INSERT
=>
[
'create
_time'
,
'update_time
'
],
static
::
EVENT_BEFORE_INSERT
=>
[
'create
d_at'
,
'updated_at
'
],
static
::
EVENT_BEFORE_UPDATE
=>
'update
_time
'
,
static
::
EVENT_BEFORE_UPDATE
=>
'update
d_at
'
,
],
],
],
],
];
];
...
...
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