Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
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
夏彬
yii2bootstrap
Commits
f017ba35
Commit
f017ba35
authored
Nov 24, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored unit tests. put common AR tests in trait
parent
983b2286
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
801 additions
and
1035 deletions
+801
-1035
ActiveRecord.php
framework/yii/db/ActiveRecord.php
+1
-1
ActiveRelation.php
framework/yii/elasticsearch/ActiveRelation.php
+1
-5
QueryBuilder.php
framework/yii/elasticsearch/QueryBuilder.php
+6
-3
Customer.php
tests/unit/data/ar/Customer.php
+4
-5
Customer.php
tests/unit/data/ar/elasticsearch/Customer.php
+9
-0
Customer.php
tests/unit/data/ar/redis/Customer.php
+9
-0
cubrid.sql
tests/unit/data/cubrid.sql
+1
-1
mssql.sql
tests/unit/data/mssql.sql
+1
-1
mysql.sql
tests/unit/data/mysql.sql
+1
-1
postgres.sql
tests/unit/data/postgres.sql
+1
-1
sqlite.sql
tests/unit/data/sqlite.sql
+1
-1
ActiveRecordTestTrait.php
tests/unit/framework/ar/ActiveRecordTestTrait.php
+619
-0
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+32
-370
ActiveRecordTest.php
tests/unit/framework/elasticsearch/ActiveRecordTest.php
+62
-283
QueryTest.php
tests/unit/framework/elasticsearch/QueryTest.php
+3
-0
ActiveRecordTest.php
tests/unit/framework/redis/ActiveRecordTest.php
+50
-363
No files found.
framework/yii/db/ActiveRecord.php
View file @
f017ba35
...
@@ -1169,7 +1169,7 @@ class ActiveRecord extends Model
...
@@ -1169,7 +1169,7 @@ class ActiveRecord extends Model
return
false
;
return
false
;
}
}
foreach
(
$this
->
attributes
()
as
$name
)
{
foreach
(
$this
->
attributes
()
as
$name
)
{
$this
->
_attributes
[
$name
]
=
$record
->
_attributes
[
$name
]
;
$this
->
_attributes
[
$name
]
=
isset
(
$record
->
_attributes
[
$name
])
?
$record
->
_attributes
[
$name
]
:
null
;
}
}
$this
->
_oldAttributes
=
$this
->
_attributes
;
$this
->
_oldAttributes
=
$this
->
_attributes
;
$this
->
_related
=
[];
$this
->
_related
=
[];
...
...
framework/yii/elasticsearch/ActiveRelation.php
View file @
f017ba35
...
@@ -39,11 +39,7 @@ class ActiveRelation extends ActiveQuery implements ActiveRelationInterface
...
@@ -39,11 +39,7 @@ class ActiveRelation extends ActiveQuery implements ActiveRelationInterface
{
{
if
(
$this
->
primaryModel
!==
null
)
{
if
(
$this
->
primaryModel
!==
null
)
{
// lazy loading
// lazy loading
if
(
$this
->
via
instanceof
ActiveRelationInterface
)
{
if
(
is_array
(
$this
->
via
))
{
// via pivot table
$viaModels
=
$this
->
via
->
findPivotRows
([
$this
->
primaryModel
]);
$this
->
filterByModels
(
$viaModels
);
}
elseif
(
is_array
(
$this
->
via
))
{
// via relation
// via relation
/** @var ActiveRelation $viaQuery */
/** @var ActiveRelation $viaQuery */
list
(
$viaName
,
$viaQuery
)
=
$this
->
via
;
list
(
$viaName
,
$viaQuery
)
=
$this
->
via
;
...
...
framework/yii/elasticsearch/QueryBuilder.php
View file @
f017ba35
...
@@ -73,13 +73,16 @@ class QueryBuilder extends \yii\base\Object
...
@@ -73,13 +73,16 @@ class QueryBuilder extends \yii\base\Object
$parts
[
'query'
]
=
[
"match_all"
=>
(
object
)[]];
$parts
[
'query'
]
=
[
"match_all"
=>
(
object
)[]];
}
}
$options
=
[];
if
(
$query
->
timeout
!==
null
)
{
$options
[
'timeout'
]
=
$query
->
timeout
;
}
return
[
return
[
'queryParts'
=>
$parts
,
'queryParts'
=>
$parts
,
'index'
=>
$query
->
index
,
'index'
=>
$query
->
index
,
'type'
=>
$query
->
type
,
'type'
=>
$query
->
type
,
'options'
=>
[
'options'
=>
$options
,
'timeout'
=>
$query
->
timeout
],
];
];
}
}
...
...
tests/unit/data/ar/Customer.php
View file @
f017ba35
<?php
<?php
namespace
yiiunit\data\ar
;
namespace
yiiunit\data\ar
;
use
yiiunit\framework\db\ActiveRecordTest
;
/**
/**
* Class Customer
* Class Customer
*
*
...
@@ -17,9 +19,6 @@ class Customer extends ActiveRecord
...
@@ -17,9 +19,6 @@ class Customer extends ActiveRecord
public
$status2
;
public
$status2
;
public
static
$afterSaveInsert
=
null
;
public
static
$afterSaveNewRecord
=
null
;
public
static
function
tableName
()
public
static
function
tableName
()
{
{
return
'tbl_customer'
;
return
'tbl_customer'
;
...
@@ -37,8 +36,8 @@ class Customer extends ActiveRecord
...
@@ -37,8 +36,8 @@ class Customer extends ActiveRecord
public
function
afterSave
(
$insert
)
public
function
afterSave
(
$insert
)
{
{
static
::
$afterSaveInsert
=
$insert
;
ActiveRecordTest
::
$afterSaveInsert
=
$insert
;
static
::
$afterSaveNewRecord
=
$this
->
isNewRecord
;
ActiveRecordTest
::
$afterSaveNewRecord
=
$this
->
isNewRecord
;
parent
::
afterSave
(
$insert
);
parent
::
afterSave
(
$insert
);
}
}
}
}
tests/unit/data/ar/elasticsearch/Customer.php
View file @
f017ba35
<?php
<?php
namespace
yiiunit\data\ar\elasticsearch
;
namespace
yiiunit\data\ar\elasticsearch
;
use
yiiunit\framework\elasticsearch\ActiveRecordTest
;
/**
/**
* Class Customer
* Class Customer
*
*
...
@@ -31,4 +33,11 @@ class Customer extends ActiveRecord
...
@@ -31,4 +33,11 @@ class Customer extends ActiveRecord
{
{
$query
->
andWhere
(
array
(
'status'
=>
1
));
$query
->
andWhere
(
array
(
'status'
=>
1
));
}
}
public
function
afterSave
(
$insert
)
{
ActiveRecordTest
::
$afterSaveInsert
=
$insert
;
ActiveRecordTest
::
$afterSaveNewRecord
=
$this
->
isNewRecord
;
parent
::
afterSave
(
$insert
);
}
}
}
tests/unit/data/ar/redis/Customer.php
View file @
f017ba35
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
namespace
yiiunit\data\ar\redis
;
namespace
yiiunit\data\ar\redis
;
use
yiiunit\framework\redis\ActiveRecordTest
;
class
Customer
extends
ActiveRecord
class
Customer
extends
ActiveRecord
{
{
const
STATUS_ACTIVE
=
1
;
const
STATUS_ACTIVE
=
1
;
...
@@ -26,4 +28,11 @@ class Customer extends ActiveRecord
...
@@ -26,4 +28,11 @@ class Customer extends ActiveRecord
{
{
$query
->
andWhere
([
'status'
=>
1
]);
$query
->
andWhere
([
'status'
=>
1
]);
}
}
public
function
afterSave
(
$insert
)
{
ActiveRecordTest
::
$afterSaveInsert
=
$insert
;
ActiveRecordTest
::
$afterSaveNewRecord
=
$this
->
isNewRecord
;
parent
::
afterSave
(
$insert
);
}
}
}
\ No newline at end of file
tests/unit/data/cubrid.sql
View file @
f017ba35
...
@@ -23,7 +23,7 @@ CREATE TABLE `tbl_constraints`
...
@@ -23,7 +23,7 @@ CREATE TABLE `tbl_constraints`
CREATE
TABLE
`tbl_customer`
(
CREATE
TABLE
`tbl_customer`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`email`
varchar
(
128
)
NOT
NULL
,
`email`
varchar
(
128
)
NOT
NULL
,
`name`
varchar
(
128
)
NOT
NULL
,
`name`
varchar
(
128
),
`address`
string
,
`address`
string
,
`status`
int
(
11
)
DEFAULT
0
,
`status`
int
(
11
)
DEFAULT
0
,
PRIMARY
KEY
(
`id`
)
PRIMARY
KEY
(
`id`
)
...
...
tests/unit/data/mssql.sql
View file @
f017ba35
...
@@ -9,7 +9,7 @@ IF OBJECT_ID('[dbo].[tbl_null_values]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_n
...
@@ -9,7 +9,7 @@ IF OBJECT_ID('[dbo].[tbl_null_values]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_n
CREATE
TABLE
[
dbo
].[
tbl_customer
]
(
CREATE
TABLE
[
dbo
].[
tbl_customer
]
(
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
email
]
[
varchar
](
128
)
NOT
NULL
,
[
email
]
[
varchar
](
128
)
NOT
NULL
,
[
name
]
[
varchar
](
128
)
NOT
NULL
,
[
name
]
[
varchar
](
128
),
[
address
]
[
text
],
[
address
]
[
text
],
[
status
]
[
int
]
DEFAULT
0
,
[
status
]
[
int
]
DEFAULT
0
,
CONSTRAINT
[
PK_customer
]
PRIMARY
KEY
CLUSTERED
(
CONSTRAINT
[
PK_customer
]
PRIMARY
KEY
CLUSTERED
(
...
...
tests/unit/data/mysql.sql
View file @
f017ba35
...
@@ -23,7 +23,7 @@ CREATE TABLE `tbl_constraints`
...
@@ -23,7 +23,7 @@ CREATE TABLE `tbl_constraints`
CREATE
TABLE
`tbl_customer`
(
CREATE
TABLE
`tbl_customer`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`email`
varchar
(
128
)
NOT
NULL
,
`email`
varchar
(
128
)
NOT
NULL
,
`name`
varchar
(
128
)
NOT
NULL
,
`name`
varchar
(
128
),
`address`
text
,
`address`
text
,
`status`
int
(
11
)
DEFAULT
0
,
`status`
int
(
11
)
DEFAULT
0
,
PRIMARY
KEY
(
`id`
)
PRIMARY
KEY
(
`id`
)
...
...
tests/unit/data/postgres.sql
View file @
f017ba35
...
@@ -22,7 +22,7 @@ CREATE TABLE tbl_constraints
...
@@ -22,7 +22,7 @@ CREATE TABLE tbl_constraints
CREATE
TABLE
tbl_customer
(
CREATE
TABLE
tbl_customer
(
id
serial
not
null
primary
key
,
id
serial
not
null
primary
key
,
email
varchar
(
128
)
NOT
NULL
,
email
varchar
(
128
)
NOT
NULL
,
name
varchar
(
128
)
NOT
NULL
,
name
varchar
(
128
),
address
text
,
address
text
,
status
integer
DEFAULT
0
status
integer
DEFAULT
0
);
);
...
...
tests/unit/data/sqlite.sql
View file @
f017ba35
...
@@ -15,7 +15,7 @@ DROP TABLE IF EXISTS tbl_null_values;
...
@@ -15,7 +15,7 @@ DROP TABLE IF EXISTS tbl_null_values;
CREATE
TABLE
tbl_customer
(
CREATE
TABLE
tbl_customer
(
id
INTEGER
NOT
NULL
,
id
INTEGER
NOT
NULL
,
email
varchar
(
128
)
NOT
NULL
,
email
varchar
(
128
)
NOT
NULL
,
name
varchar
(
128
)
NOT
NULL
,
name
varchar
(
128
),
address
text
,
address
text
,
status
INTEGER
DEFAULT
0
,
status
INTEGER
DEFAULT
0
,
PRIMARY
KEY
(
id
)
PRIMARY
KEY
(
id
)
...
...
tests/unit/framework/ar/ActiveRecordTestTrait.php
0 → 100644
View file @
f017ba35
This diff is collapsed.
Click to expand it.
tests/unit/framework/db/ActiveRecordTest.php
View file @
f017ba35
This diff is collapsed.
Click to expand it.
tests/unit/framework/elasticsearch/ActiveRecordTest.php
View file @
f017ba35
This diff is collapsed.
Click to expand it.
tests/unit/framework/elasticsearch/QueryTest.php
View file @
f017ba35
...
@@ -146,6 +146,9 @@ class QueryTest extends ElasticSearchTestCase
...
@@ -146,6 +146,9 @@ class QueryTest extends ElasticSearchTestCase
}
}
// TODO test facets
// TODO test complex where() every edge of QueryBuilder
public
function
testOrder
()
public
function
testOrder
()
{
{
...
...
tests/unit/framework/redis/ActiveRecordTest.php
View file @
f017ba35
This diff is collapsed.
Click to expand it.
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