Carsten Brandt 11 years ago
parent
commit
34945b0b69
  1. 20
      tests/unit/data/ar/NullValues.php
  2. 11
      tests/unit/data/cubrid.sql
  3. 10
      tests/unit/data/mssql.sql
  4. 10
      tests/unit/data/mysql.sql
  5. 10
      tests/unit/data/postgres.sql
  6. 9
      tests/unit/data/sqlite.sql
  7. 51
      tests/unit/framework/db/ActiveRecordTest.php

20
tests/unit/data/ar/NullValues.php

@ -0,0 +1,20 @@
<?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';
}
}

11
tests/unit/data/cubrid.sql

@ -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` (
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',

10
tests/unit/data/mssql.sql

@ -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] (
) 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',

10
tests/unit/data/mysql.sql

@ -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` (
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',

10
tests/unit/data/postgres.sql

@ -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 (
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',

9
tests/unit/data/sqlite.sql

@ -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` (
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',

51
tests/unit/framework/db/ActiveRecordTest.php

@ -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
$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);
}
} }

Loading…
Cancel
Save