Browse Source

Added test for PgSQL BIGINT column to ensure typecasting works OK

Closes #11286
ar-bug
SilverFire - Dmitry Naumenko 8 years ago
parent
commit
b976f638d8
No known key found for this signature in database
GPG Key ID: 39DD917A92B270A
  1. 3
      tests/data/postgres.sql
  2. 50
      tests/framework/db/pgsql/PostgreSQLSchemaTest.php

3
tests/data/postgres.sql

@ -128,7 +128,8 @@ CREATE TABLE "type" (
bool_col boolean NOT NULL,
bool_col2 boolean DEFAULT TRUE,
ts_default TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
bit_col BIT(8) NOT NULL DEFAULT B'10000010'
bit_col BIT(8) NOT NULL DEFAULT B'10000010',
bigint_col BIGINT
);
CREATE TABLE "bool_values" (

50
tests/framework/db/pgsql/PostgreSQLSchemaTest.php

@ -4,6 +4,8 @@ namespace yiiunit\framework\db\pgsql;
use yii\db\Expression;
use yii\db\pgsql\Schema;
use yiiunit\data\ar\ActiveRecord;
use yiiunit\data\ar\Type;
use yiiunit\framework\db\SchemaTest;
/**
@ -64,6 +66,19 @@ class PostgreSQLSchemaTest extends SchemaTest
$columns['bit_col']['dbType'] = 'bit';
$columns['bit_col']['size'] = 8;
$columns['bit_col']['precision'] = null;
$columns['bigint_col'] = [
'type' => 'bigint',
'dbType' => 'int8',
'phpType' => 'integer',
'allowNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => null,
'precision' => 64,
'scale' => 0,
'defaultValue' => null,
];
return $columns;
}
@ -106,4 +121,39 @@ class PostgreSQLSchemaTest extends SchemaTest
$this->assertEquals(3, count($schema->getSchemaNames()));
}
public function bigintValueProvider()
{
return [
[8817806877],
[3797444208],
[3199585540],
[1389831585],
[922337203685477580],
[9223372036854775807],
[-9223372036854775808]
];
}
/**
* @dataProvider bigintValueProvider
*/
public function testBigintValue($bigint)
{
$this->mockApplication();
ActiveRecord::$db = $this->getConnection();
Type::deleteAll();
$type = new Type();
$type->setAttributes([
'bigint_col' => $bigint,
// whatever just to satisfy NOT NULL columns
'int_col' => 1, 'char_col' => 'a', 'float_col' => 0.1, 'bool_col' => true,
], false);
$type->save(false);
$actual = Type::find()->one();
$this->assertEquals($bigint, $actual->bigint_col);
}
}

Loading…
Cancel
Save