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
34945b0b
Commit
34945b0b
authored
Oct 29, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added unit test to verify storing of null values
http://www.yiiframework.com/forum/index.php/topic/48359-inserting-nulls/page__view__findpost__p__226019
parent
ec490dca
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
121 additions
and
0 deletions
+121
-0
NullValues.php
tests/unit/data/ar/NullValues.php
+20
-0
cubrid.sql
tests/unit/data/cubrid.sql
+11
-0
mssql.sql
tests/unit/data/mssql.sql
+10
-0
mysql.sql
tests/unit/data/mysql.sql
+10
-0
postgres.sql
tests/unit/data/postgres.sql
+10
-0
sqlite.sql
tests/unit/data/sqlite.sql
+9
-0
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+51
-0
No files found.
tests/unit/data/ar/NullValues.php
0 → 100644
View file @
34945b0b
<?php
namespace
yiiunit\data\ar
;
/**
* Class NullValues
*
* @property integer $id
* @property integer $var1
* @property integer $var2
* @property integer $var3
* @property string $stringcol
*/
class
NullValues
extends
ActiveRecord
{
public
static
function
tableName
()
{
return
'tbl_null_values'
;
}
}
tests/unit/data/cubrid.sql
View file @
34945b0b
...
@@ -9,6 +9,7 @@ DROP TABLE IF EXISTS tbl_item;
...
@@ -9,6 +9,7 @@ DROP TABLE IF EXISTS tbl_item;
DROP
TABLE
IF
EXISTS
tbl_order
;
DROP
TABLE
IF
EXISTS
tbl_order
;
DROP
TABLE
IF
EXISTS
tbl_category
;
DROP
TABLE
IF
EXISTS
tbl_category
;
DROP
TABLE
IF
EXISTS
tbl_customer
;
DROP
TABLE
IF
EXISTS
tbl_customer
;
DROP
TABLE
IF
EXISTS
tbl_null_values
;
DROP
TABLE
IF
EXISTS
tbl_type
;
DROP
TABLE
IF
EXISTS
tbl_type
;
DROP
TABLE
IF
EXISTS
tbl_constraints
;
DROP
TABLE
IF
EXISTS
tbl_constraints
;
...
@@ -61,6 +62,16 @@ CREATE TABLE `tbl_order_item` (
...
@@ -61,6 +62,16 @@ CREATE TABLE `tbl_order_item` (
CONSTRAINT
`FK_order_item_item_id`
FOREIGN
KEY
(
`item_id`
)
REFERENCES
`tbl_item`
(
`id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_order_item_item_id`
FOREIGN
KEY
(
`item_id`
)
REFERENCES
`tbl_item`
(
`id`
)
ON
DELETE
CASCADE
);
);
CREATE
TABLE
tbl_null_values
(
`id`
INT
(
11
)
UNSIGNED
NOT
NULL
AUTO_INCREMENT
,
`var1`
INT
UNSIGNED
NULL
,
`var2`
INT
NULL
,
`var3`
INT
DEFAULT
NULL
,
`stringcol`
VARCHAR
(
32
)
DEFAULT
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
`tbl_type`
(
CREATE
TABLE
`tbl_type`
(
`int_col`
int
(
11
)
NOT
NULL
,
`int_col`
int
(
11
)
NOT
NULL
,
`int_col2`
int
(
11
)
DEFAULT
'1'
,
`int_col2`
int
(
11
)
DEFAULT
'1'
,
...
...
tests/unit/data/mssql.sql
View file @
34945b0b
...
@@ -4,6 +4,7 @@ IF OBJECT_ID('[dbo].[tbl_order]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_order];
...
@@ -4,6 +4,7 @@ IF OBJECT_ID('[dbo].[tbl_order]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_order];
IF
OBJECT_ID
(
'[dbo].[tbl_category]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_category
];
IF
OBJECT_ID
(
'[dbo].[tbl_category]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_category
];
IF
OBJECT_ID
(
'[dbo].[tbl_customer]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_customer
];
IF
OBJECT_ID
(
'[dbo].[tbl_customer]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_customer
];
IF
OBJECT_ID
(
'[dbo].[tbl_type]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_type
];
IF
OBJECT_ID
(
'[dbo].[tbl_type]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_type
];
IF
OBJECT_ID
(
'[dbo].[tbl_null_values]'
,
'U'
)
IS
NOT
NULL
DROP
TABLE
[
dbo
].[
tbl_null_values
];
CREATE
TABLE
[
dbo
].[
tbl_customer
]
(
CREATE
TABLE
[
dbo
].[
tbl_customer
]
(
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
[
id
]
[
int
]
IDENTITY
(
1
,
1
)
NOT
NULL
,
...
@@ -54,6 +55,15 @@ CREATE TABLE [dbo].[tbl_order_item] (
...
@@ -54,6 +55,15 @@ CREATE TABLE [dbo].[tbl_order_item] (
)
ON
[
PRIMARY
]
)
ON
[
PRIMARY
]
);
);
CREATE
TABLE
[
dbo
].[
tbl_null_values
]
(
id
[
int
]
UNSIGNED
NOT
NULL
,
var1
[
int
]
UNSIGNED
NULL
,
var2
[
int
]
NULL
,
var3
[
int
]
DEFAULT
NULL
,
stringcol
[
varchar
](
32
)
DEFAULT
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
[
dbo
].[
tbl_type
]
(
CREATE
TABLE
[
dbo
].[
tbl_type
]
(
[
int_col
]
[
int
]
NOT
NULL
,
[
int_col
]
[
int
]
NOT
NULL
,
[
int_col2
]
[
int
]
DEFAULT
'1'
,
[
int_col2
]
[
int
]
DEFAULT
'1'
,
...
...
tests/unit/data/mysql.sql
View file @
34945b0b
...
@@ -9,6 +9,7 @@ DROP TABLE IF EXISTS tbl_item CASCADE;
...
@@ -9,6 +9,7 @@ DROP TABLE IF EXISTS tbl_item CASCADE;
DROP
TABLE
IF
EXISTS
tbl_order
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_order
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_category
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_category
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_customer
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_customer
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_null_values
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_type
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_type
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_constraints
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_constraints
CASCADE
;
...
@@ -71,6 +72,15 @@ CREATE TABLE `tbl_composite_fk` (
...
@@ -71,6 +72,15 @@ CREATE TABLE `tbl_composite_fk` (
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`tbl_order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`tbl_order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
);
);
CREATE
TABLE
tbl_null_values
(
`id`
INT
(
11
)
UNSIGNED
NOT
NULL
AUTO_INCREMENT
,
`var1`
INT
UNSIGNED
NULL
,
`var2`
INT
NULL
,
`var3`
INT
DEFAULT
NULL
,
`stringcol`
VARCHAR
(
32
)
DEFAULT
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
`tbl_type`
(
CREATE
TABLE
`tbl_type`
(
`int_col`
int
(
11
)
NOT
NULL
,
`int_col`
int
(
11
)
NOT
NULL
,
`int_col2`
int
(
11
)
DEFAULT
'1'
,
`int_col2`
int
(
11
)
DEFAULT
'1'
,
...
...
tests/unit/data/postgres.sql
View file @
34945b0b
...
@@ -10,6 +10,7 @@ DROP TABLE IF EXISTS tbl_order CASCADE;
...
@@ -10,6 +10,7 @@ DROP TABLE IF EXISTS tbl_order CASCADE;
DROP
TABLE
IF
EXISTS
tbl_category
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_category
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_customer
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_customer
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_type
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_type
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_null_values
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_constraints
CASCADE
;
DROP
TABLE
IF
EXISTS
tbl_constraints
CASCADE
;
CREATE
TABLE
tbl_constraints
CREATE
TABLE
tbl_constraints
...
@@ -54,6 +55,15 @@ CREATE TABLE tbl_order_item (
...
@@ -54,6 +55,15 @@ CREATE TABLE tbl_order_item (
PRIMARY
KEY
(
order_id
,
item_id
)
PRIMARY
KEY
(
order_id
,
item_id
)
);
);
CREATE
TABLE
tbl_null_values
(
id
INT
UNSIGNED
AUTOINCREMENT
NOT
NULL
,
var1
INT
UNSIGNED
NULL
,
var2
INT
NULL
,
var3
INT
DEFAULT
NULL
,
stringcol
VARCHAR
(
32
)
DEFAULT
NULL
,
PRIMARY
KEY
(
id
)
);
CREATE
TABLE
tbl_type
(
CREATE
TABLE
tbl_type
(
int_col
integer
NOT
NULL
,
int_col
integer
NOT
NULL
,
int_col2
integer
DEFAULT
'1'
,
int_col2
integer
DEFAULT
'1'
,
...
...
tests/unit/data/sqlite.sql
View file @
34945b0b
...
@@ -10,6 +10,7 @@ DROP TABLE IF EXISTS tbl_order;
...
@@ -10,6 +10,7 @@ DROP TABLE IF EXISTS tbl_order;
DROP
TABLE
IF
EXISTS
tbl_category
;
DROP
TABLE
IF
EXISTS
tbl_category
;
DROP
TABLE
IF
EXISTS
tbl_customer
;
DROP
TABLE
IF
EXISTS
tbl_customer
;
DROP
TABLE
IF
EXISTS
tbl_type
;
DROP
TABLE
IF
EXISTS
tbl_type
;
DROP
TABLE
IF
EXISTS
tbl_null_values
;
CREATE
TABLE
tbl_customer
(
CREATE
TABLE
tbl_customer
(
id
INTEGER
NOT
NULL
,
id
INTEGER
NOT
NULL
,
...
@@ -57,6 +58,14 @@ CREATE TABLE `tbl_composite_fk` (
...
@@ -57,6 +58,14 @@ CREATE TABLE `tbl_composite_fk` (
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`tbl_order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
CONSTRAINT
`FK_composite_fk_order_item`
FOREIGN
KEY
(
`order_id`
,
`item_id`
)
REFERENCES
`tbl_order_item`
(
`order_id`
,
`item_id`
)
ON
DELETE
CASCADE
);
);
CREATE
TABLE
tbl_null_values
(
id
INTEGER
UNSIGNED
PRIMARY
KEY
NOT
NULL
,
var1
INTEGER
UNSIGNED
,
var2
INTEGER
,
var3
INTEGER
DEFAULT
NULL
,
stringcol
VARCHAR
(
32
)
DEFAULT
NULL
);
CREATE
TABLE
tbl_type
(
CREATE
TABLE
tbl_type
(
int_col
INTEGER
NOT
NULL
,
int_col
INTEGER
NOT
NULL
,
int_col2
INTEGER
DEFAULT
'1'
,
int_col2
INTEGER
DEFAULT
'1'
,
...
...
tests/unit/framework/db/ActiveRecordTest.php
View file @
34945b0b
...
@@ -4,6 +4,7 @@ namespace yiiunit\framework\db;
...
@@ -4,6 +4,7 @@ namespace yiiunit\framework\db;
use
yii\db\ActiveQuery
;
use
yii\db\ActiveQuery
;
use
yiiunit\data\ar\ActiveRecord
;
use
yiiunit\data\ar\ActiveRecord
;
use
yiiunit\data\ar\Customer
;
use
yiiunit\data\ar\Customer
;
use
yiiunit\data\ar\NullValues
;
use
yiiunit\data\ar\OrderItem
;
use
yiiunit\data\ar\OrderItem
;
use
yiiunit\data\ar\Order
;
use
yiiunit\data\ar\Order
;
use
yiiunit\data\ar\Item
;
use
yiiunit\data\ar\Item
;
...
@@ -375,4 +376,54 @@ class ActiveRecordTest extends DatabaseTestCase
...
@@ -375,4 +376,54 @@ class ActiveRecordTest extends DatabaseTestCase
$customers
=
Customer
::
find
()
->
all
();
$customers
=
Customer
::
find
()
->
all
();
$this
->
assertEquals
(
0
,
count
(
$customers
));
$this
->
assertEquals
(
0
,
count
(
$customers
));
}
}
public
function
testStoreNull
()
{
$record
=
new
NullValues
();
$this
->
assertNull
(
$record
->
var1
);
$this
->
assertNull
(
$record
->
var2
);
$this
->
assertNull
(
$record
->
var3
);
$this
->
assertNull
(
$record
->
stringcol
);
$record
->
id
=
1
;
$record
->
var1
=
123
;
$record
->
var2
=
456
;
$record
->
var3
=
789
;
$record
->
stringcol
=
'hello!'
;
$record
->
save
(
false
);
$this
->
assertTrue
(
$record
->
refresh
());
$this
->
assertEquals
(
123
,
$record
->
var1
);
$this
->
assertEquals
(
456
,
$record
->
var2
);
$this
->
assertEquals
(
789
,
$record
->
var3
);
$this
->
assertEquals
(
'hello!'
,
$record
->
stringcol
);
$record
->
var1
=
null
;
$record
->
var2
=
null
;
$record
->
var3
=
null
;
$record
->
stringcol
=
null
;
$record
->
save
(
false
);
$this
->
assertTrue
(
$record
->
refresh
());
$this
->
assertNull
(
$record
->
var1
);
$this
->
assertNull
(
$record
->
var2
);
$this
->
assertNull
(
$record
->
var3
);
$this
->
assertNull
(
$record
->
stringcol
);
$record
->
var1
=
0
;
$record
->
var2
=
0
;
$record
->
var3
=
0
;
$record
->
stringcol
=
''
;
$record
->
save
(
false
);
$this
->
assertTrue
(
$record
->
refresh
());
$this
->
assertEquals
(
0
,
$record
->
var1
);
$this
->
assertEquals
(
0
,
$record
->
var2
);
$this
->
assertEquals
(
0
,
$record
->
var3
);
$this
->
assertEquals
(
''
,
$record
->
stringcol
);
}
}
}
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