mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-04 22:44:53 +01:00
* php-cs-fixer: PSR2 rule. * php-cs-fixer: PSR2 rule - fix views. * Travis setup refactoring. * Add php-cs-fixer to travis cs tests. * Fix tests on hhvm-3.12 * improve travis config * composer update * revert composer update * improve travis config * Fix CS. * Extract config to separate classes. * Extract config to separate classes. * Add file header. * Force short array syntax. * binary_operator_spaces fixer * Fix broken tests * cast_spaces fixer * concat_space fixer * dir_constant fixer * ereg_to_preg fixer * function_typehint_space fixer * hash_to_slash_comment fixer * is_null fixer * linebreak_after_opening_tag fixer * lowercase_cast fixer * magic_constant_casing fixer * modernize_types_casting fixer * native_function_casing fixer * new_with_braces fixer * no_alias_functions fixer * no_blank_lines_after_class_opening fixer * no_blank_lines_after_phpdoc fixer * no_empty_comment fixer * no_empty_phpdoc fixer * no_empty_statement fixer * no_extra_consecutive_blank_lines fixer * no_leading_import_slash fixer * no_leading_namespace_whitespace fixer * no_mixed_echo_print fixer * no_multiline_whitespace_around_double_arrow fixer * no_multiline_whitespace_before_semicolons fixer * no_php4_constructor fixer * no_short_bool_cast fixer * no_singleline_whitespace_before_semicolons fixer * no_spaces_around_offset fixer * no_trailing_comma_in_list_call fixer * no_trailing_comma_in_singleline_array fixer * no_unneeded_control_parentheses fixer * no_unused_imports fixer * no_useless_return fixer * no_whitespace_before_comma_in_array fixer * no_whitespace_in_blank_line fixer * not_operator_with_successor_space fixer * object_operator_without_whitespace fixer * ordered_imports fixer * php_unit_construct fixer * php_unit_dedicate_assert fixer * php_unit_fqcn_annotation fixer * phpdoc_indent fixer * phpdoc_no_access fixer * phpdoc_no_empty_return fixer * phpdoc_no_package fixer * phpdoc_no_useless_inheritdoc fixer * Fix broken tests * phpdoc_return_self_reference fixer * phpdoc_single_line_var_spacing fixer * phpdoc_single_line_var_spacing fixer * phpdoc_to_comment fixer * phpdoc_trim fixer * phpdoc_var_without_name fixer * psr4 fixer * self_accessor fixer * short_scalar_cast fixer * single_blank_line_before_namespace fixer * single_quote fixer * standardize_not_equals fixer * ternary_operator_spaces fixer * trailing_comma_in_multiline_array fixer * trim_array_spaces fixer * protected_to_private fixer * unary_operator_spaces fixer * whitespace_after_comma_in_array fixer * `parent::setRules()` -> `$this->setRules()` * blank_line_after_opening_tag fixer * Update finder config. * Revert changes for YiiRequirementChecker. * Fix array formatting. * Add missing import. * Fix CS for new code merged from master. * Fix some indentation issues.
223 lines
7.6 KiB
PHP
223 lines
7.6 KiB
PHP
<?php
|
|
/**
|
|
* @link http://www.yiiframework.com/
|
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
|
* @license http://www.yiiframework.com/license/
|
|
*/
|
|
|
|
namespace yiiunit\framework\db\pgsql;
|
|
|
|
use yii\db\Expression;
|
|
use yii\db\pgsql\Schema;
|
|
use yiiunit\data\ar\ActiveRecord;
|
|
use yiiunit\data\ar\Type;
|
|
|
|
/**
|
|
* @group db
|
|
* @group pgsql
|
|
*/
|
|
class SchemaTest extends \yiiunit\framework\db\SchemaTest
|
|
{
|
|
public $driverName = 'pgsql';
|
|
|
|
public function getExpectedColumns()
|
|
{
|
|
$columns = parent::getExpectedColumns();
|
|
unset($columns['enum_col']);
|
|
$columns['int_col']['dbType'] = 'int4';
|
|
$columns['int_col']['size'] = null;
|
|
$columns['int_col']['precision'] = 32;
|
|
$columns['int_col']['scale'] = 0;
|
|
$columns['int_col2']['dbType'] = 'int4';
|
|
$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';
|
|
$columns['char_col2']['precision'] = null;
|
|
$columns['float_col']['dbType'] = 'float8';
|
|
$columns['float_col']['precision'] = 53;
|
|
$columns['float_col']['scale'] = null;
|
|
$columns['float_col']['size'] = null;
|
|
$columns['float_col2']['dbType'] = 'float8';
|
|
$columns['float_col2']['precision'] = 53;
|
|
$columns['float_col2']['scale'] = null;
|
|
$columns['float_col2']['size'] = null;
|
|
$columns['blob_col']['dbType'] = 'bytea';
|
|
$columns['blob_col']['phpType'] = 'resource';
|
|
$columns['blob_col']['type'] = 'binary';
|
|
$columns['numeric_col']['dbType'] = 'numeric';
|
|
$columns['numeric_col']['size'] = null;
|
|
$columns['bool_col']['type'] = 'boolean';
|
|
$columns['bool_col']['phpType'] = 'boolean';
|
|
$columns['bool_col']['dbType'] = 'bool';
|
|
$columns['bool_col']['size'] = null;
|
|
$columns['bool_col']['precision'] = null;
|
|
$columns['bool_col']['scale'] = null;
|
|
$columns['bool_col2']['type'] = 'boolean';
|
|
$columns['bool_col2']['phpType'] = 'boolean';
|
|
$columns['bool_col2']['dbType'] = 'bool';
|
|
$columns['bool_col2']['size'] = null;
|
|
$columns['bool_col2']['precision'] = null;
|
|
$columns['bool_col2']['scale'] = null;
|
|
$columns['bool_col2']['defaultValue'] = true;
|
|
$columns['ts_default']['defaultValue'] = new Expression('now()');
|
|
$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;
|
|
}
|
|
|
|
public function testCompositeFk()
|
|
{
|
|
/* @var $schema Schema */
|
|
$schema = $this->getConnection()->schema;
|
|
|
|
$table = $schema->getTableSchema('composite_fk');
|
|
|
|
$this->assertCount(1, $table->foreignKeys);
|
|
$this->assertTrue(isset($table->foreignKeys['fk_composite_fk_order_item']));
|
|
$this->assertEquals('order_item', $table->foreignKeys['fk_composite_fk_order_item'][0]);
|
|
$this->assertEquals('order_id', $table->foreignKeys['fk_composite_fk_order_item']['order_id']);
|
|
$this->assertEquals('item_id', $table->foreignKeys['fk_composite_fk_order_item']['item_id']);
|
|
}
|
|
|
|
public function testGetPDOType()
|
|
{
|
|
$values = [
|
|
[null, \PDO::PARAM_NULL],
|
|
['', \PDO::PARAM_STR],
|
|
['hello', \PDO::PARAM_STR],
|
|
[0, \PDO::PARAM_INT],
|
|
[1, \PDO::PARAM_INT],
|
|
[1337, \PDO::PARAM_INT],
|
|
[true, \PDO::PARAM_BOOL],
|
|
[false, \PDO::PARAM_BOOL],
|
|
[$fp = fopen(__FILE__, 'rb'), \PDO::PARAM_LOB],
|
|
];
|
|
|
|
/* @var $schema Schema */
|
|
$schema = $this->getConnection()->schema;
|
|
|
|
foreach ($values as $value) {
|
|
$this->assertEquals($value[1], $schema->getPdoType($value[0]));
|
|
}
|
|
fclose($fp);
|
|
}
|
|
|
|
public function testBooleanDefaultValues()
|
|
{
|
|
/* @var $schema Schema */
|
|
$schema = $this->getConnection()->schema;
|
|
|
|
$table = $schema->getTableSchema('bool_values');
|
|
$this->assertTrue($table->getColumn('default_true')->defaultValue);
|
|
$this->assertFalse($table->getColumn('default_false')->defaultValue);
|
|
}
|
|
|
|
public function testFindSchemaNames()
|
|
{
|
|
$schema = $this->getConnection()->schema;
|
|
|
|
$this->assertCount(3, $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);
|
|
}
|
|
|
|
/**
|
|
* https://github.com/yiisoft/yii2/issues/12483
|
|
*/
|
|
public function testParenthesisDefaultValue()
|
|
{
|
|
$db = $this->getConnection(false);
|
|
if ($db->schema->getTableSchema('test_default_parenthesis') !== null) {
|
|
$db->createCommand()->dropTable('test_default_parenthesis')->execute();
|
|
}
|
|
|
|
$db->createCommand()->createTable('test_default_parenthesis', [
|
|
'id' => 'pk',
|
|
'user_timezone' => 'numeric(5,2) DEFAULT (0)::numeric NOT NULL',
|
|
])->execute();
|
|
|
|
$db->schema->refreshTableSchema('test_default_parenthesis');
|
|
$tableSchema = $db->schema->getTableSchema('test_default_parenthesis');
|
|
$this->assertNotNull($tableSchema);
|
|
$column = $tableSchema->getColumn('user_timezone');
|
|
$this->assertNotNull($column);
|
|
$this->assertFalse($column->allowNull);
|
|
$this->assertEquals('numeric', $column->dbType);
|
|
$this->assertEquals(0, $column->defaultValue);
|
|
}
|
|
|
|
/**
|
|
* https://github.com/yiisoft/yii2/issues/14192
|
|
*/
|
|
public function testTimestampNullDefaultValue()
|
|
{
|
|
$db = $this->getConnection(false);
|
|
if ($db->schema->getTableSchema('test_timestamp_default_null') !== null) {
|
|
$db->createCommand()->dropTable('test_timestamp_default_null')->execute();
|
|
}
|
|
|
|
$db->createCommand()->createTable('test_timestamp_default_null', [
|
|
'id' => 'pk',
|
|
'timestamp' => 'timestamp DEFAULT NULL',
|
|
])->execute();
|
|
|
|
$db->schema->refreshTableSchema('test_timestamp_default_null');
|
|
$tableSchema = $db->schema->getTableSchema('test_timestamp_default_null');
|
|
$this->assertNull($tableSchema->getColumn('timestamp')->defaultValue);
|
|
}
|
|
}
|