Commit c4dc9470 by Carsten Brandt

created a test case to verify #4682

parent 7ad76857
......@@ -7,6 +7,7 @@ namespace yiiunit\data\ar;
*
* @property int $int_col
* @property int $int_col2 DEFAULT 1
* @property int $smallint_col DEFAULT 1
* @property string $char_col
* @property string $char_col2 DEFAULT 'something'
* @property string $char_col3
......
......@@ -100,6 +100,7 @@ CREATE TABLE null_values (
CREATE TABLE "type" (
"int_col" int(11) NOT NULL,
"int_col2" int(11) DEFAULT '1',
"smallint_col" smallint(1) DEFAULT '1',
"char_col" char(100) NOT NULL,
"char_col2" varchar(100) DEFAULT 'something',
"char_col3" string,
......
......@@ -92,6 +92,7 @@ CREATE TABLE [dbo].[null_values] (
CREATE TABLE [dbo].[type] (
[int_col] [int] NOT NULL,
[int_col2] [int] DEFAULT '1',
[smallint_col] [smallint] DEFAULT '1',
[char_col] [char](100) NOT NULL,
[char_col2] [varchar](100) DEFAULT 'something',
[char_col3] [text],
......
......@@ -110,6 +110,7 @@ CREATE TABLE null_values (
CREATE TABLE `type` (
`int_col` integer NOT NULL,
`int_col2` integer DEFAULT '1',
`smallint_col` smallint(1) DEFAULT '1',
`char_col` char(100) NOT NULL,
`char_col2` varchar(100) DEFAULT 'something',
`char_col3` text,
......
......@@ -100,6 +100,7 @@ CREATE TABLE "null_values" (
CREATE TABLE "type" (
int_col integer NOT NULL,
int_col2 integer DEFAULT '1',
smallint_col smallint DEFAULT '1',
char_col char(100) NOT NULL,
char_col2 varchar(100) DEFAULT 'something',
char_col3 text,
......
......@@ -94,6 +94,7 @@ CREATE TABLE "null_values" (
CREATE TABLE "type" (
int_col INTEGER NOT NULL,
int_col2 INTEGER DEFAULT '1',
smallint_col SMALLINT(1) DEFAULT '1',
char_col char(100) NOT NULL,
char_col2 varchar(100) DEFAULT 'something',
char_col3 text,
......
......@@ -573,4 +573,33 @@ class ActiveRecordTest extends DatabaseTestCase
$this->assertEquals($orderItemCount, $orderItemsWithNullFKClass::find()->count());
$this->assertEquals(5, $itemClass::find()->count());
}
public function testCastValues()
{
$model = new Type();
$model->int_col = 123;
$model->int_col2 = 456;
$model->smallint_col = 42;
$model->char_col = '1337';
$model->char_col2 = 'test';
$model->char_col3 = 'test123';
$model->float_col = 1337.42;
$model->float_col2 = 42.1337;
$model->bool_col = true;
$model->bool_col2 = false;
$model->save(false);
/* @var $model Type */
$model = Type::find()->one();
$this->assertSame(123, $model->int_col);
$this->assertSame(456, $model->int_col2);
$this->assertSame(42, $model->smallint_col);
$this->assertSame('1337', trim($model->char_col));
$this->assertSame('test', $model->char_col2);
$this->assertSame('test123', $model->char_col3);
// $this->assertSame(1337.42, $model->float_col);
// $this->assertSame(42.1337, $model->float_col2);
// $this->assertSame(true, $model->bool_col);
// $this->assertSame(false, $model->bool_col2);
}
}
......@@ -119,6 +119,18 @@ class SchemaTest extends DatabaseTestCase
'scale' => null,
'defaultValue' => 1,
],
'smallint_col' => [
'type' => 'smallint',
'dbType' => 'smallint(1)',
'phpType' => 'integer',
'allowNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => 1,
'precision' => 1,
'scale' => null,
'defaultValue' => 1,
],
'char_col' => [
'type' => 'string',
'dbType' => 'char(100)',
......
......@@ -45,6 +45,9 @@ class CubridSchemaTest extends SchemaTest
$columns['int_col2']['dbType'] = 'integer';
$columns['int_col2']['size'] = null;
$columns['int_col2']['precision'] = null;
$columns['smallint_col']['dbType'] = 'integer';
$columns['smallint_col']['size'] = null;
$columns['smallint_col']['precision'] = null;
$columns['char_col3']['type'] = 'string';
$columns['char_col3']['dbType'] = 'varchar(1073741823)';
$columns['char_col3']['size'] = 1073741823;
......
......@@ -26,6 +26,10 @@ class PostgreSQLSchemaTest extends SchemaTest
$columns['int_col2']['size'] = null;
$columns['int_col2']['precision'] = 32;
$columns['int_col2']['scale'] = 0;
$columns['smallint_col']['dbType'] = 'int2';
$columns['smallint_col']['size'] = null;
$columns['smallint_col']['precision'] = 16;
$columns['smallint_col']['scale'] = 0;
$columns['char_col']['dbType'] = 'bpchar';
$columns['char_col']['precision'] = null;
$columns['char_col2']['dbType'] = 'varchar';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment