| Total Complexity | 61 |
| Total Lines | 613 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like TestSchemaTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TestSchemaTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | trait TestSchemaTrait |
||
| 30 | { |
||
| 31 | public function testGetTableSchemasWithAttrCase(): void |
||
| 32 | { |
||
| 33 | $db = $this->getConnection(false); |
||
|
|
|||
| 34 | |||
| 35 | $db->getActivePDO()->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); |
||
| 36 | |||
| 37 | $this->assertCount(count($db->getSchema()->getTableNames()), $db->getSchema()->getTableSchemas()); |
||
| 38 | |||
| 39 | $db->getActivePDO()->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER); |
||
| 40 | |||
| 41 | $this->assertCount(count($db->getSchema()->getTableNames()), $db->getSchema()->getTableSchemas()); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function testGetSchemaPrimaryKeys(): void |
||
| 45 | { |
||
| 46 | $db = $this->getConnection(false); |
||
| 47 | |||
| 48 | $tablePks = $db->getSchema()->getSchemaPrimaryKeys(); |
||
| 49 | |||
| 50 | /** @psalm-suppress RedundantCondition */ |
||
| 51 | $this->assertIsArray($tablePks); |
||
| 52 | $this->assertContainsOnlyInstancesOf(Constraint::class, $tablePks); |
||
| 53 | } |
||
| 54 | |||
| 55 | public function testGetSchemaChecks(): void |
||
| 56 | { |
||
| 57 | $db = $this->getConnection(false); |
||
| 58 | |||
| 59 | $tableChecks = $db->getSchema()->getSchemaChecks(); |
||
| 60 | |||
| 61 | /** @psalm-suppress RedundantCondition */ |
||
| 62 | $this->assertIsArray($tableChecks); |
||
| 63 | |||
| 64 | foreach ($tableChecks as $checks) { |
||
| 65 | $this->assertIsArray($checks); |
||
| 66 | $this->assertContainsOnlyInstancesOf(CheckConstraint::class, $checks); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | public function testGetSchemaDefaultValues(): void |
||
| 71 | { |
||
| 72 | $db = $this->getConnection(false); |
||
| 73 | |||
| 74 | $tableDefaultValues = $db->getSchema()->getSchemaDefaultValues(); |
||
| 75 | |||
| 76 | /** @psalm-suppress RedundantCondition */ |
||
| 77 | $this->assertIsArray($tableDefaultValues); |
||
| 78 | |||
| 79 | foreach ($tableDefaultValues as $defaultValues) { |
||
| 80 | $this->assertIsArray($defaultValues); |
||
| 81 | $this->assertContainsOnlyInstancesOf(DefaultValueConstraint::class, $defaultValues); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | public function testGetSchemaForeignKeys(): void |
||
| 86 | { |
||
| 87 | $db = $this->getConnection(false); |
||
| 88 | |||
| 89 | $tableForeignKeys = $db->getSchema()->getSchemaForeignKeys(); |
||
| 90 | |||
| 91 | /** @psalm-suppress RedundantCondition */ |
||
| 92 | $this->assertIsArray($tableForeignKeys); |
||
| 93 | |||
| 94 | foreach ($tableForeignKeys as $foreignKeys) { |
||
| 95 | $this->assertIsArray($foreignKeys); |
||
| 96 | $this->assertContainsOnlyInstancesOf(ForeignKeyConstraint::class, $foreignKeys); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | public function testGetSchemaIndexes(): void |
||
| 101 | { |
||
| 102 | $db = $this->getConnection(false); |
||
| 103 | |||
| 104 | $tableIndexes = $db->getSchema()->getSchemaIndexes(); |
||
| 105 | |||
| 106 | /** @psalm-suppress RedundantCondition */ |
||
| 107 | $this->assertIsArray($tableIndexes); |
||
| 108 | |||
| 109 | foreach ($tableIndexes as $indexes) { |
||
| 110 | $this->assertIsArray($indexes); |
||
| 111 | $this->assertContainsOnlyInstancesOf(IndexConstraint::class, $indexes); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | public function testGetSchemaUniques(): void |
||
| 116 | { |
||
| 117 | $db = $this->getConnection(false); |
||
| 118 | |||
| 119 | $tableUniques = $db->getSchema()->getSchemaUniques(); |
||
| 120 | |||
| 121 | /** @psalm-suppress RedundantCondition */ |
||
| 122 | $this->assertIsArray($tableUniques); |
||
| 123 | |||
| 124 | foreach ($tableUniques as $uniques) { |
||
| 125 | $this->assertIsArray($uniques); |
||
| 126 | $this->assertContainsOnlyInstancesOf(Constraint::class, $uniques); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | public function testGetNonExistingTableSchema(): void |
||
| 131 | { |
||
| 132 | $this->assertNull($this->getConnection()->getSchema()->getTableSchema('nonexisting_table')); |
||
| 133 | } |
||
| 134 | |||
| 135 | public function testSchemaCache(): void |
||
| 136 | { |
||
| 137 | $db = $this->getConnection(); |
||
| 138 | |||
| 139 | $schema = $db->getSchema(); |
||
| 140 | |||
| 141 | $this->assertNotNull($this->schemaCache); |
||
| 142 | $this->schemaCache->setEnable(true); |
||
| 143 | |||
| 144 | $noCacheTable = $schema->getTableSchema('type', true); |
||
| 145 | $cachedTable = $schema->getTableSchema('type', false); |
||
| 146 | |||
| 147 | $this->assertEquals($noCacheTable, $cachedTable); |
||
| 148 | |||
| 149 | $db->createCommand()->renameTable('type', 'type_test'); |
||
| 150 | |||
| 151 | $noCacheTable = $schema->getTableSchema('type', true); |
||
| 152 | |||
| 153 | $this->assertNotSame($noCacheTable, $cachedTable); |
||
| 154 | |||
| 155 | $db->createCommand()->renameTable('type_test', 'type'); |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @depends testSchemaCache |
||
| 160 | */ |
||
| 161 | public function testRefreshTableSchema(): void |
||
| 162 | { |
||
| 163 | $schema = $this->getConnection()->getSchema(); |
||
| 164 | |||
| 165 | $this->assertNotNull($this->schemaCache); |
||
| 166 | |||
| 167 | $this->schemaCache->setEnable(true); |
||
| 168 | |||
| 169 | $noCacheTable = $schema->getTableSchema('type', true); |
||
| 170 | |||
| 171 | $schema->refreshTableSchema('type'); |
||
| 172 | |||
| 173 | $refreshedTable = $schema->getTableSchema('type', false); |
||
| 174 | |||
| 175 | $this->assertNotSame($noCacheTable, $refreshedTable); |
||
| 176 | } |
||
| 177 | |||
| 178 | public function testCompositeFk(): void |
||
| 179 | { |
||
| 180 | $schema = $this->getConnection()->getSchema(); |
||
| 181 | |||
| 182 | $table = $schema->getTableSchema('composite_fk'); |
||
| 183 | |||
| 184 | $this->assertNotNull($table); |
||
| 185 | |||
| 186 | $fk = $table->getForeignKeys(); |
||
| 187 | |||
| 188 | $this->assertCount(1, $fk); |
||
| 189 | $this->assertTrue(isset($fk['FK_composite_fk_order_item'])); |
||
| 190 | $this->assertEquals('order_item', $fk['FK_composite_fk_order_item'][0]); |
||
| 191 | $this->assertEquals('order_id', $fk['FK_composite_fk_order_item']['order_id']); |
||
| 192 | $this->assertEquals('item_id', $fk['FK_composite_fk_order_item']['item_id']); |
||
| 193 | } |
||
| 194 | |||
| 195 | public function testGetPDOType(): void |
||
| 196 | { |
||
| 197 | $values = [ |
||
| 198 | [null, PDO::PARAM_NULL], |
||
| 199 | ['', PDO::PARAM_STR], |
||
| 200 | ['hello', PDO::PARAM_STR], |
||
| 201 | [0, PDO::PARAM_INT], |
||
| 202 | [1, PDO::PARAM_INT], |
||
| 203 | [1337, PDO::PARAM_INT], |
||
| 204 | [true, PDO::PARAM_BOOL], |
||
| 205 | [false, PDO::PARAM_BOOL], |
||
| 206 | [$fp = fopen(__FILE__, 'rb'), PDO::PARAM_LOB], |
||
| 207 | ]; |
||
| 208 | |||
| 209 | $schema = $this->getConnection()->getSchema(); |
||
| 210 | |||
| 211 | foreach ($values as $value) { |
||
| 212 | $this->assertEquals($value[1], $schema->getPdoType($value[0]), 'type for value ' . print_r($value[0], true) . ' does not match.'); |
||
| 213 | } |
||
| 214 | |||
| 215 | fclose($fp); |
||
| 216 | } |
||
| 217 | |||
| 218 | public function testColumnSchema(): void |
||
| 219 | { |
||
| 220 | $columns = $this->getExpectedColumns(); |
||
| 221 | |||
| 222 | $table = $this->getConnection(false)->getSchema()->getTableSchema('type', true); |
||
| 223 | $this->assertNotNull($table); |
||
| 224 | |||
| 225 | $expectedColNames = array_keys($columns); |
||
| 226 | |||
| 227 | sort($expectedColNames); |
||
| 228 | |||
| 229 | $colNames = $table->getColumnNames(); |
||
| 230 | |||
| 231 | sort($colNames); |
||
| 232 | |||
| 233 | $this->assertEquals($expectedColNames, $colNames); |
||
| 234 | |||
| 235 | foreach ($table->getColumns() as $name => $column) { |
||
| 236 | $expected = $columns[$name]; |
||
| 237 | $this->assertSame( |
||
| 238 | $expected['dbType'], |
||
| 239 | $column->getDbType(), |
||
| 240 | "dbType of column $name does not match. type is {$column->getType()}, dbType is {$column->getDbType()}." |
||
| 241 | ); |
||
| 242 | $this->assertSame( |
||
| 243 | $expected['phpType'], |
||
| 244 | $column->getPhpType(), |
||
| 245 | "phpType of column $name does not match. type is {$column->getType()}, dbType is {$column->getDbType()}." |
||
| 246 | ); |
||
| 247 | $this->assertSame($expected['type'], $column->getType(), "type of column $name does not match."); |
||
| 248 | $this->assertSame( |
||
| 249 | $expected['allowNull'], |
||
| 250 | $column->isAllowNull(), |
||
| 251 | "allowNull of column $name does not match." |
||
| 252 | ); |
||
| 253 | $this->assertSame( |
||
| 254 | $expected['autoIncrement'], |
||
| 255 | $column->isAutoIncrement(), |
||
| 256 | "autoIncrement of column $name does not match." |
||
| 257 | ); |
||
| 258 | $this->assertSame( |
||
| 259 | $expected['enumValues'], |
||
| 260 | $column->getEnumValues(), |
||
| 261 | "enumValues of column $name does not match." |
||
| 262 | ); |
||
| 263 | $this->assertSame($expected['size'], $column->getSize(), "size of column $name does not match."); |
||
| 264 | $this->assertSame( |
||
| 265 | $expected['precision'], |
||
| 266 | $column->getPrecision(), |
||
| 267 | "precision of column $name does not match." |
||
| 268 | ); |
||
| 269 | $this->assertSame($expected['scale'], $column->getScale(), "scale of column $name does not match."); |
||
| 270 | if (\is_object($expected['defaultValue'])) { |
||
| 271 | $this->assertIsObject( |
||
| 272 | $column->getDefaultValue(), |
||
| 273 | "defaultValue of column $name is expected to be an object but it is not." |
||
| 274 | ); |
||
| 275 | $this->assertEquals( |
||
| 276 | (string) $expected['defaultValue'], |
||
| 277 | (string) $column->getDefaultValue(), |
||
| 278 | "defaultValue of column $name does not match." |
||
| 279 | ); |
||
| 280 | } else { |
||
| 281 | $this->assertEquals( |
||
| 282 | $expected['defaultValue'], |
||
| 283 | $column->getDefaultValue(), |
||
| 284 | "defaultValue of column $name does not match." |
||
| 285 | ); |
||
| 286 | } |
||
| 287 | /* Pgsql only */ |
||
| 288 | if (isset($expected['dimension'])) { |
||
| 289 | /** @psalm-suppress UndefinedMethod */ |
||
| 290 | $this->assertSame( |
||
| 291 | $expected['dimension'], |
||
| 292 | $column->getDimension(), |
||
| 293 | "dimension of column $name does not match" |
||
| 294 | ); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | } |
||
| 298 | |||
| 299 | public function testColumnSchemaDbTypecastWithEmptyCharType(): void |
||
| 300 | { |
||
| 301 | $columnSchema = new ColumnSchema(); |
||
| 302 | |||
| 303 | $columnSchema->setType(Schema::TYPE_CHAR); |
||
| 304 | |||
| 305 | $this->assertSame('', $columnSchema->dbTypecast('')); |
||
| 306 | } |
||
| 307 | |||
| 308 | public function testNegativeDefaultValues(): void |
||
| 309 | { |
||
| 310 | $schema = $this->getConnection()->getSchema(); |
||
| 311 | |||
| 312 | $table = $schema->getTableSchema('negative_default_values'); |
||
| 313 | |||
| 314 | $this->assertNotNull($table); |
||
| 315 | $this->assertEquals(-123, $table->getColumn('tinyint_col')?->getDefaultValue()); |
||
| 316 | $this->assertEquals(-123, $table->getColumn('smallint_col')?->getDefaultValue()); |
||
| 317 | $this->assertEquals(-123, $table->getColumn('int_col')?->getDefaultValue()); |
||
| 318 | $this->assertEquals(-123, $table->getColumn('bigint_col')?->getDefaultValue()); |
||
| 319 | $this->assertEquals(-12345.6789, $table->getColumn('float_col')?->getDefaultValue()); |
||
| 320 | $this->assertEquals(-33.22, $table->getColumn('numeric_col')?->getDefaultValue()); |
||
| 321 | } |
||
| 322 | |||
| 323 | public function testContraintTablesExistance(): void |
||
| 324 | { |
||
| 325 | $tableNames = [ |
||
| 326 | 'T_constraints_1', |
||
| 327 | 'T_constraints_2', |
||
| 328 | 'T_constraints_3', |
||
| 329 | 'T_constraints_4', |
||
| 330 | ]; |
||
| 331 | |||
| 332 | $schema = $this->getConnection()->getSchema(); |
||
| 333 | |||
| 334 | foreach ($tableNames as $tableName) { |
||
| 335 | $tableSchema = $schema->getTableSchema($tableName); |
||
| 336 | $this->assertInstanceOf(TableSchemaInterface::class, $tableSchema, $tableName); |
||
| 337 | } |
||
| 338 | } |
||
| 339 | |||
| 340 | public function testGetColumnNoExist(): void |
||
| 341 | { |
||
| 342 | $schema = $this->getConnection()->getSchema(); |
||
| 343 | $table = $schema->getTableSchema('negative_default_values'); |
||
| 344 | |||
| 345 | $this->assertNotNull($table); |
||
| 346 | $this->assertNull($table->getColumn('no_exist')); |
||
| 347 | } |
||
| 348 | |||
| 349 | private function assertMetadataEquals($expected, $actual): void |
||
| 350 | { |
||
| 351 | switch (strtolower(gettype($expected))) { |
||
| 352 | case 'object': |
||
| 353 | $this->assertIsObject($actual); |
||
| 354 | break; |
||
| 355 | case 'array': |
||
| 356 | $this->assertIsArray($actual); |
||
| 357 | break; |
||
| 358 | case 'null': |
||
| 359 | $this->assertNull($actual); |
||
| 360 | break; |
||
| 361 | } |
||
| 362 | |||
| 363 | if (is_array($expected)) { |
||
| 364 | $this->normalizeArrayKeys($expected, false); |
||
| 365 | /** @psalm-suppress PossiblyInvalidArgument */ |
||
| 366 | $this->normalizeArrayKeys($actual, false); |
||
| 367 | } |
||
| 368 | |||
| 369 | $this->normalizeConstraints($expected, $actual); |
||
| 370 | |||
| 371 | if (is_array($expected)) { |
||
| 372 | $this->normalizeArrayKeys($expected, true); |
||
| 373 | $this->normalizeArrayKeys($actual, true); |
||
| 374 | } |
||
| 375 | |||
| 376 | $this->assertEquals($expected, $actual); |
||
| 377 | } |
||
| 378 | |||
| 379 | private function normalizeArrayKeys(array &$array, bool $caseSensitive): void |
||
| 380 | { |
||
| 381 | $newArray = []; |
||
| 382 | |||
| 383 | foreach ($array as $value) { |
||
| 384 | if ($value instanceof Constraint) { |
||
| 385 | $key = (array) $value; |
||
| 386 | unset( |
||
| 387 | $key["\000Yiisoft\Db\Constraint\Constraint\000name"], |
||
| 388 | $key["\u0000Yiisoft\\Db\\Constraint\\ForeignKeyConstraint\u0000foreignSchemaName"] |
||
| 389 | ); |
||
| 390 | |||
| 391 | foreach ($key as $keyName => $keyValue) { |
||
| 392 | if ($keyValue instanceof AnyCaseValue) { |
||
| 393 | $key[$keyName] = $keyValue->value; |
||
| 394 | } elseif ($keyValue instanceof AnyValue) { |
||
| 395 | $key[$keyName] = '[AnyValue]'; |
||
| 396 | } |
||
| 397 | } |
||
| 398 | |||
| 399 | ksort($key, SORT_STRING); |
||
| 400 | |||
| 401 | $newArray[$caseSensitive |
||
| 402 | ? json_encode($key, JSON_THROW_ON_ERROR) |
||
| 403 | : strtolower(json_encode($key, JSON_THROW_ON_ERROR))] = $value; |
||
| 404 | } else { |
||
| 405 | $newArray[] = $value; |
||
| 406 | } |
||
| 407 | } |
||
| 408 | |||
| 409 | ksort($newArray, SORT_STRING); |
||
| 410 | |||
| 411 | $array = $newArray; |
||
| 412 | } |
||
| 413 | |||
| 414 | private function normalizeConstraints(&$expected, &$actual): void |
||
| 426 | } |
||
| 427 | } |
||
| 428 | |||
| 429 | private function normalizeConstraintPair(Constraint $expectedConstraint, Constraint $actualConstraint): void |
||
| 430 | { |
||
| 431 | if (get_class($expectedConstraint) !== get_class($actualConstraint)) { |
||
| 432 | return; |
||
| 433 | } |
||
| 434 | |||
| 435 | foreach (array_keys((array) $expectedConstraint) as $name) { |
||
| 436 | if ($expectedConstraint->getName() instanceof AnyValue) { |
||
| 437 | $actualConstraint->name($expectedConstraint->getName()); |
||
| 438 | } elseif ($expectedConstraint->getName() instanceof AnyCaseValue) { |
||
| 439 | $actualConstraintName = $actualConstraint->getName(); |
||
| 440 | $this->assertIsString($actualConstraintName); |
||
| 441 | $actualConstraint->name(new AnyCaseValue($actualConstraintName)); |
||
| 442 | } |
||
| 443 | } |
||
| 444 | } |
||
| 445 | |||
| 446 | public function constraintsProviderTrait(): array |
||
| 447 | { |
||
| 448 | return [ |
||
| 449 | '1: primary key' => [ |
||
| 450 | 'T_constraints_1', |
||
| 451 | Schema::PRIMARY_KEY, |
||
| 452 | (new Constraint()) |
||
| 453 | ->name(AnyValue::getInstance()) |
||
| 454 | ->columnNames(['C_id']), |
||
| 455 | ], |
||
| 456 | '1: check' => [ |
||
| 457 | 'T_constraints_1', |
||
| 458 | Schema::CHECKS, |
||
| 459 | [ |
||
| 460 | (new CheckConstraint()) |
||
| 461 | ->name(AnyValue::getInstance()) |
||
| 462 | ->columnNames(['C_check']) |
||
| 463 | ->expression("C_check <> ''"), |
||
| 464 | ], |
||
| 465 | ], |
||
| 466 | '1: unique' => [ |
||
| 467 | 'T_constraints_1', |
||
| 468 | Schema::UNIQUES, |
||
| 469 | [ |
||
| 470 | (new Constraint()) |
||
| 471 | ->name('CN_unique') |
||
| 472 | ->columnNames(['C_unique']), |
||
| 473 | ], |
||
| 474 | ], |
||
| 475 | '1: index' => [ |
||
| 476 | 'T_constraints_1', |
||
| 477 | Schema::INDEXES, |
||
| 478 | [ |
||
| 479 | (new IndexConstraint()) |
||
| 480 | ->name(AnyValue::getInstance()) |
||
| 481 | ->columnNames(['C_id']) |
||
| 482 | ->unique(true) |
||
| 483 | ->primary(true), |
||
| 484 | (new IndexConstraint()) |
||
| 485 | ->name('CN_unique') |
||
| 486 | ->columnNames(['C_unique']) |
||
| 487 | ->primary(false) |
||
| 488 | ->unique(true), |
||
| 489 | ], |
||
| 490 | ], |
||
| 491 | '1: default' => ['T_constraints_1', Schema::DEFAULT_VALUES, false], |
||
| 492 | |||
| 493 | '2: primary key' => [ |
||
| 494 | 'T_constraints_2', |
||
| 495 | Schema::PRIMARY_KEY, |
||
| 496 | (new Constraint()) |
||
| 497 | ->name('CN_pk') |
||
| 498 | ->columnNames(['C_id_1', 'C_id_2']), |
||
| 499 | ], |
||
| 500 | '2: unique' => [ |
||
| 501 | 'T_constraints_2', |
||
| 502 | Schema::UNIQUES, |
||
| 503 | [ |
||
| 504 | (new Constraint()) |
||
| 505 | ->name('CN_constraints_2_multi') |
||
| 506 | ->columnNames(['C_index_2_1', 'C_index_2_2']), |
||
| 507 | ], |
||
| 508 | ], |
||
| 509 | '2: index' => [ |
||
| 510 | 'T_constraints_2', |
||
| 511 | Schema::INDEXES, |
||
| 512 | [ |
||
| 513 | (new IndexConstraint()) |
||
| 514 | ->name(AnyValue::getInstance()) |
||
| 515 | ->columnNames(['C_id_1', 'C_id_2']) |
||
| 516 | ->unique(true) |
||
| 517 | ->primary(true), |
||
| 518 | (new IndexConstraint()) |
||
| 519 | ->name('CN_constraints_2_single') |
||
| 520 | ->columnNames(['C_index_1']) |
||
| 521 | ->primary(false) |
||
| 522 | ->unique(false), |
||
| 523 | (new IndexConstraint()) |
||
| 524 | ->name('CN_constraints_2_multi') |
||
| 525 | ->columnNames(['C_index_2_1', 'C_index_2_2']) |
||
| 526 | ->primary(false) |
||
| 527 | ->unique(true), |
||
| 528 | ], |
||
| 529 | ], |
||
| 530 | '2: check' => ['T_constraints_2', Schema::CHECKS, []], |
||
| 531 | '2: default' => ['T_constraints_2', Schema::DEFAULT_VALUES, false], |
||
| 532 | |||
| 533 | '3: primary key' => ['T_constraints_3', Schema::PRIMARY_KEY, null], |
||
| 534 | '3: foreign key' => [ |
||
| 535 | 'T_constraints_3', |
||
| 536 | Schema::FOREIGN_KEYS, |
||
| 537 | [ |
||
| 538 | (new ForeignKeyConstraint()) |
||
| 539 | ->name('CN_constraints_3') |
||
| 540 | ->columnNames(['C_fk_id_1', 'C_fk_id_2']) |
||
| 541 | ->foreignTableName('T_constraints_2') |
||
| 542 | ->foreignColumnNames(['C_id_1', 'C_id_2']) |
||
| 543 | ->onDelete('CASCADE') |
||
| 544 | ->onUpdate('CASCADE'), |
||
| 545 | ], |
||
| 546 | ], |
||
| 547 | '3: unique' => ['T_constraints_3', Schema::UNIQUES, []], |
||
| 548 | '3: index' => [ |
||
| 549 | 'T_constraints_3', |
||
| 550 | Schema::INDEXES, |
||
| 551 | [ |
||
| 552 | (new IndexConstraint()) |
||
| 553 | ->name('CN_constraints_3') |
||
| 554 | ->columnNames(['C_fk_id_1', 'C_fk_id_2']) |
||
| 555 | ->unique(false) |
||
| 556 | ->primary(false), |
||
| 557 | ], |
||
| 558 | ], |
||
| 559 | '3: check' => ['T_constraints_3', Schema::CHECKS, []], |
||
| 560 | '3: default' => ['T_constraints_3', Schema::DEFAULT_VALUES, false], |
||
| 561 | |||
| 562 | '4: primary key' => [ |
||
| 563 | 'T_constraints_4', |
||
| 564 | Schema::PRIMARY_KEY, |
||
| 565 | (new Constraint()) |
||
| 566 | ->name(AnyValue::getInstance()) |
||
| 567 | ->columnNames(['C_id']), |
||
| 568 | ], |
||
| 569 | '4: unique' => [ |
||
| 570 | 'T_constraints_4', |
||
| 571 | Schema::UNIQUES, |
||
| 572 | [ |
||
| 573 | (new Constraint()) |
||
| 574 | ->name('CN_constraints_4') |
||
| 575 | ->columnNames(['C_col_1', 'C_col_2']), |
||
| 576 | ], |
||
| 577 | ], |
||
| 578 | '4: check' => ['T_constraints_4', Schema::CHECKS, []], |
||
| 579 | '4: default' => ['T_constraints_4', Schema::DEFAULT_VALUES, false], |
||
| 580 | ]; |
||
| 581 | } |
||
| 582 | |||
| 583 | public function pdoAttributesProviderTrait(): array |
||
| 584 | { |
||
| 585 | return [ |
||
| 586 | [[PDO::ATTR_EMULATE_PREPARES => true]], |
||
| 587 | [[PDO::ATTR_EMULATE_PREPARES => false]], |
||
| 588 | ]; |
||
| 589 | } |
||
| 590 | |||
| 591 | public function tableSchemaCachePrefixesProviderTrait(): array |
||
| 592 | { |
||
| 593 | $configs = [ |
||
| 594 | [ |
||
| 595 | 'prefix' => '', |
||
| 596 | 'name' => 'type', |
||
| 597 | ], |
||
| 598 | [ |
||
| 599 | 'prefix' => '', |
||
| 600 | 'name' => '{{%type}}', |
||
| 601 | ], |
||
| 602 | [ |
||
| 603 | 'prefix' => 'ty', |
||
| 604 | 'name' => '{{%pe}}', |
||
| 605 | ], |
||
| 606 | ]; |
||
| 607 | |||
| 608 | $data = []; |
||
| 609 | foreach ($configs as $config) { |
||
| 610 | foreach ($configs as $testConfig) { |
||
| 611 | if ($config === $testConfig) { |
||
| 612 | continue; |
||
| 613 | } |
||
| 614 | |||
| 615 | $description = sprintf( |
||
| 616 | "%s (with '%s' prefix) against %s (with '%s' prefix)", |
||
| 617 | $config['name'], |
||
| 618 | $config['prefix'], |
||
| 619 | $testConfig['name'], |
||
| 620 | $testConfig['prefix'] |
||
| 621 | ); |
||
| 622 | $data[$description] = [ |
||
| 623 | $config['prefix'], |
||
| 624 | $config['name'], |
||
| 625 | $testConfig['prefix'], |
||
| 626 | $testConfig['name'], |
||
| 627 | ]; |
||
| 628 | } |
||
| 629 | } |
||
| 630 | |||
| 631 | return $data; |
||
| 632 | } |
||
| 633 | |||
| 634 | public function lowercaseConstraintsProviderTrait(): array |
||
| 635 | { |
||
| 636 | return $this->constraintsProvider(); |
||
| 637 | } |
||
| 638 | |||
| 639 | public function uppercaseConstraintsProviderTrait(): array |
||
| 642 | } |
||
| 643 | } |
||
| 644 |