| Total Complexity | 44 |
| Total Lines | 717 |
| Duplicated Lines | 0 % |
| Changes | 13 | ||
| Bugs | 0 | Features | 0 |
Complex classes like SchemaAttributeTest 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 SchemaAttributeTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 14 | |||
| 15 | class SchemaAttributeTest extends TestCase |
||
| 16 | { |
||
| 17 | public function testItSchemaAttributeWithInvalidNamePropertiesThrowException(): void |
||
| 18 | { |
||
| 19 | $this->expectException(\FlexPHP\Schema\Exception\InvalidSchemaAttributeException::class); |
||
| 20 | $this->expectExceptionMessage('Name:'); |
||
| 21 | |||
| 22 | new SchemaAttribute('', 'string'); |
||
| 23 | } |
||
| 24 | |||
| 25 | public function testItSchemaAttributeWithInvalidDataTypePropertiesThrowException(): void |
||
| 26 | { |
||
| 27 | $this->expectException(\FlexPHP\Schema\Exception\InvalidSchemaAttributeException::class); |
||
| 28 | $this->expectExceptionMessage('DataType:'); |
||
| 29 | |||
| 30 | new SchemaAttribute('foo', 'bar'); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @dataProvider getConstraintLogicError |
||
| 35 | */ |
||
| 36 | public function testItSchemaAttributeConstraintLogicError(string $dataType, string $constraints): void |
||
| 37 | { |
||
| 38 | $this->expectException(\FlexPHP\Schema\Exception\InvalidSchemaAttributeException::class); |
||
| 39 | $this->expectExceptionMessage('Logic:'); |
||
| 40 | |||
| 41 | new SchemaAttribute('foo', $dataType, $constraints); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function testItSchemaAttributeWithRequiredPropertiesSetValues(): void |
||
| 45 | { |
||
| 46 | $name = 'foo'; |
||
| 47 | $dataType = 'string'; |
||
| 48 | |||
| 49 | $schemaAttribute = new SchemaAttribute($name, $dataType); |
||
| 50 | |||
| 51 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 52 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @dataProvider getRequiredConstraint |
||
| 57 | * |
||
| 58 | * @param mixed $constraint |
||
| 59 | * @param mixed $expected |
||
| 60 | */ |
||
| 61 | public function testItSchemaAttributeRequiredConstraints($constraint, $expected): void |
||
| 62 | { |
||
| 63 | $name = 'foo'; |
||
| 64 | $dataType = 'string'; |
||
| 65 | |||
| 66 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 67 | |||
| 68 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 69 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 70 | $this->assertSame($expected, $schemaAttribute->isRequired()); |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @dataProvider getMinLengthConstraint |
||
| 75 | * |
||
| 76 | * @param mixed $constraint |
||
| 77 | * @param mixed $expected |
||
| 78 | */ |
||
| 79 | public function testItSchemaAttributeMinLengthConstraints($constraint, $expected): void |
||
| 80 | { |
||
| 81 | $name = 'foo'; |
||
| 82 | $dataType = 'string'; |
||
| 83 | |||
| 84 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 85 | |||
| 86 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 87 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 88 | $this->assertSame($expected, $schemaAttribute->minLength()); |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @dataProvider getMinConstraint |
||
| 93 | * |
||
| 94 | * @param mixed $constraint |
||
| 95 | * @param mixed $expected |
||
| 96 | */ |
||
| 97 | public function testItSchemaAttributeMinConstraints($constraint, $expected): void |
||
| 98 | { |
||
| 99 | $name = 'min'; |
||
| 100 | $dataType = 'integer'; |
||
| 101 | |||
| 102 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 103 | |||
| 104 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 105 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 106 | $this->assertSame($expected, $schemaAttribute->min()); |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @dataProvider getMaxLengthConstraint |
||
| 111 | * |
||
| 112 | * @param mixed $constraint |
||
| 113 | * @param mixed $expected |
||
| 114 | */ |
||
| 115 | public function testItSchemaAttributeMaxLengthConstraints($constraint, $expected): void |
||
| 116 | { |
||
| 117 | $name = 'minLength'; |
||
| 118 | $dataType = 'string'; |
||
| 119 | |||
| 120 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 121 | |||
| 122 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 123 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 124 | $this->assertSame($expected, $schemaAttribute->maxLength()); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @dataProvider getMaxConstraint |
||
| 129 | * |
||
| 130 | * @param mixed $constraint |
||
| 131 | * @param mixed $expected |
||
| 132 | */ |
||
| 133 | public function testItSchemaAttributeMaxConstraints($constraint, $expected): void |
||
| 134 | { |
||
| 135 | $name = 'max'; |
||
| 136 | $dataType = 'integer'; |
||
| 137 | |||
| 138 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 139 | |||
| 140 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 141 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 142 | $this->assertSame($expected, $schemaAttribute->max()); |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @dataProvider getMinCheckConstraint |
||
| 147 | * |
||
| 148 | * @param mixed $constraint |
||
| 149 | * @param mixed $expected |
||
| 150 | */ |
||
| 151 | public function testItSchemaAttributeMinCheckConstraints($constraint, $expected): void |
||
| 152 | { |
||
| 153 | $name = 'minCheck'; |
||
| 154 | $dataType = 'integer'; |
||
| 155 | |||
| 156 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 157 | |||
| 158 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 159 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 160 | $this->assertSame($expected, $schemaAttribute->minCheck()); |
||
| 161 | } |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @dataProvider getMaxCheckConstraint |
||
| 165 | * |
||
| 166 | * @param mixed $constraint |
||
| 167 | * @param mixed $expected |
||
| 168 | */ |
||
| 169 | public function testItSchemaAttributeMaxCheckConstraints($constraint, $expected): void |
||
| 170 | { |
||
| 171 | $name = 'maxCheck'; |
||
| 172 | $dataType = 'integer'; |
||
| 173 | |||
| 174 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 175 | |||
| 176 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 177 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 178 | $this->assertSame($expected, $schemaAttribute->maxCheck()); |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @dataProvider getCheckConstraint |
||
| 183 | * |
||
| 184 | * @param mixed $constraint |
||
| 185 | * @param mixed $expectedMin |
||
| 186 | * @param mixed $expectedMax |
||
| 187 | */ |
||
| 188 | public function testItSchemaAttributeCheckConstraints($constraint, $expectedMin, $expectedMax): void |
||
| 189 | { |
||
| 190 | $name = 'check'; |
||
| 191 | $dataType = 'integer'; |
||
| 192 | |||
| 193 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 194 | |||
| 195 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 196 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 197 | $this->assertSame($expectedMin, $schemaAttribute->minCheck()); |
||
| 198 | $this->assertSame($expectedMax, $schemaAttribute->maxCheck()); |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @dataProvider getLengthConstraint |
||
| 203 | * |
||
| 204 | * @param mixed $constraint |
||
| 205 | * @param mixed $expectedMin |
||
| 206 | * @param mixed $expectedMax |
||
| 207 | */ |
||
| 208 | public function testItSchemaAttributeLengthConstraints($constraint, $expectedMin, $expectedMax): void |
||
| 209 | { |
||
| 210 | $name = 'length'; |
||
| 211 | $dataType = 'string'; |
||
| 212 | |||
| 213 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 214 | |||
| 215 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 216 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 217 | $this->assertSame($expectedMin, $schemaAttribute->minLength()); |
||
| 218 | $this->assertSame($expectedMax, $schemaAttribute->maxLength()); |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @dataProvider getEqualToConstraint |
||
| 223 | * |
||
| 224 | * @param mixed $constraint |
||
| 225 | * @param mixed $expected |
||
| 226 | */ |
||
| 227 | public function testItSchemaAttributeEqualToConstraints($constraint, $expected): void |
||
| 228 | { |
||
| 229 | $name = 'equalTo'; |
||
| 230 | $dataType = 'string'; |
||
| 231 | |||
| 232 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 233 | |||
| 234 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 235 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 236 | $this->assertSame($expected, $schemaAttribute->equalTo()); |
||
| 237 | } |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @dataProvider getTypeConstraint |
||
| 241 | * |
||
| 242 | * @param mixed $constraint |
||
| 243 | * @param mixed $expected |
||
| 244 | */ |
||
| 245 | public function testItSchemaAttributeTypeConstraints($constraint, $expected): void |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @dataProvider getPkConstraint |
||
| 259 | * |
||
| 260 | * @param mixed $constraint |
||
| 261 | * @param mixed $expected |
||
| 262 | */ |
||
| 263 | public function testItSchemaAttributePkConstraints($constraint, $expected): void |
||
| 264 | { |
||
| 265 | $name = 'foo'; |
||
| 266 | $dataType = 'string'; |
||
| 267 | |||
| 268 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 269 | |||
| 270 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 271 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 272 | $this->assertSame($expected, $schemaAttribute->isPk()); |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @dataProvider getAiConstraint |
||
| 277 | * |
||
| 278 | * @param mixed $constraint |
||
| 279 | * @param mixed $expected |
||
| 280 | */ |
||
| 281 | public function testItSchemaAttributeAiConstraints($constraint, $expected): void |
||
| 282 | { |
||
| 283 | $name = 'foo'; |
||
| 284 | $dataType = 'integer'; |
||
| 285 | |||
| 286 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 287 | |||
| 288 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 289 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 290 | $this->assertSame($expected, $schemaAttribute->isAi()); |
||
| 291 | } |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @dataProvider getCaConstraint |
||
| 295 | * |
||
| 296 | * @param mixed $constraint |
||
| 297 | * @param mixed $expected |
||
| 298 | */ |
||
| 299 | public function testItSchemaAttributeCaConstraints($constraint, $expected): void |
||
| 300 | { |
||
| 301 | $name = 'foo'; |
||
| 302 | $dataType = 'datetime'; |
||
| 303 | |||
| 304 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 305 | |||
| 306 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 307 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 308 | $this->assertSame($expected, $schemaAttribute->isCa()); |
||
| 309 | $this->assertSame($expected, $schemaAttribute->isBlame()); |
||
| 310 | $this->assertSame($expected, $schemaAttribute->isBlameAt()); |
||
| 311 | $this->assertSame(false, $schemaAttribute->isBlameBy()); |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @dataProvider getUaConstraint |
||
| 316 | * |
||
| 317 | * @param mixed $constraint |
||
| 318 | * @param mixed $expected |
||
| 319 | */ |
||
| 320 | public function testItSchemaAttributeUaConstraints($constraint, $expected): void |
||
| 321 | { |
||
| 322 | $name = 'foo'; |
||
| 323 | $dataType = 'datetime'; |
||
| 324 | |||
| 325 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 326 | |||
| 327 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 328 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 329 | $this->assertSame($expected, $schemaAttribute->isUa()); |
||
| 330 | $this->assertSame($expected, $schemaAttribute->isBlame()); |
||
| 331 | $this->assertSame($expected, $schemaAttribute->isBlameAt()); |
||
| 332 | $this->assertSame(false, $schemaAttribute->isBlameBy()); |
||
| 333 | } |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @dataProvider getCbConstraint |
||
| 337 | * |
||
| 338 | * @param mixed $constraint |
||
| 339 | * @param mixed $expected |
||
| 340 | */ |
||
| 341 | public function testItSchemaAttributeCbConstraints($constraint, $expected): void |
||
| 342 | { |
||
| 343 | $name = 'foo'; |
||
| 344 | $dataType = 'integer'; |
||
| 345 | |||
| 346 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 347 | |||
| 348 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 349 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 350 | $this->assertSame($expected, $schemaAttribute->isCb()); |
||
| 351 | $this->assertSame($expected, $schemaAttribute->isBlame()); |
||
| 352 | $this->assertSame(false, $schemaAttribute->isBlameAt()); |
||
| 353 | $this->assertSame($expected, $schemaAttribute->isBlameBy()); |
||
| 354 | } |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @dataProvider getUbConstraint |
||
| 358 | * |
||
| 359 | * @param mixed $constraint |
||
| 360 | * @param mixed $expected |
||
| 361 | */ |
||
| 362 | public function testItSchemaAttributeUbConstraints($constraint, $expected): void |
||
| 363 | { |
||
| 364 | $name = 'foo'; |
||
| 365 | $dataType = 'integer'; |
||
| 366 | |||
| 367 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 368 | |||
| 369 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 370 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 371 | $this->assertSame($expected, $schemaAttribute->isUb()); |
||
| 372 | $this->assertSame($expected, $schemaAttribute->isBlame()); |
||
| 373 | $this->assertSame(false, $schemaAttribute->isBlameAt()); |
||
| 374 | $this->assertSame($expected, $schemaAttribute->isBlameBy()); |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @dataProvider getFkConstraint |
||
| 379 | * |
||
| 380 | * @param mixed $constraint |
||
| 381 | * @param mixed $fkTable |
||
| 382 | * @param mixed $fkId |
||
| 383 | * @param mixed $fkName |
||
| 384 | */ |
||
| 385 | public function testItSchemaAttributeFkConstraints($constraint, $fkTable, $fkId, $fkName): void |
||
| 386 | { |
||
| 387 | $name = 'foreing'; |
||
| 388 | $dataType = 'integer'; |
||
| 389 | |||
| 390 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint); |
||
| 391 | |||
| 392 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 393 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 394 | $this->assertEquals('int', $schemaAttribute->typeHint()); |
||
| 395 | $this->assertTrue($schemaAttribute->isFk()); |
||
| 396 | $this->assertSame($fkTable, $schemaAttribute->fkTable()); |
||
| 397 | $this->assertSame($fkId, $schemaAttribute->fkId()); |
||
| 398 | $this->assertSame($fkName, $schemaAttribute->fkName()); |
||
| 399 | } |
||
| 400 | |||
| 401 | public function testItSchemaAttributeConstraintsAsString(): void |
||
| 402 | { |
||
| 403 | $name = 'foo'; |
||
| 404 | $dataType = 'string'; |
||
| 405 | $constraints = 'required|minlength:8|maxlength:10|mincheck:3|maxcheck:4|equalto:#bar|type:number'; |
||
| 406 | |||
| 407 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints); |
||
| 408 | |||
| 409 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 410 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 411 | $this->assertEquals('string', $schemaAttribute->typeHint()); |
||
| 412 | $this->assertIsArray($schemaAttribute->constraints()); |
||
| 413 | $this->assertSame(true, $schemaAttribute->isRequired()); |
||
| 414 | $this->assertNull($schemaAttribute->min()); |
||
| 415 | $this->assertSame(8, $schemaAttribute->minLength()); |
||
| 416 | $this->assertSame(3, $schemaAttribute->minCheck()); |
||
| 417 | $this->assertNull($schemaAttribute->max()); |
||
| 418 | $this->assertSame(10, $schemaAttribute->maxLength()); |
||
| 419 | $this->assertSame(4, $schemaAttribute->maxCheck()); |
||
| 420 | $this->assertSame('#bar', $schemaAttribute->equalTo()); |
||
| 421 | $this->assertSame('number', $schemaAttribute->type()); |
||
| 422 | $this->assertFalse($schemaAttribute->isPk()); |
||
| 423 | $this->assertFalse($schemaAttribute->isAi()); |
||
| 424 | $this->assertFalse($schemaAttribute->isFk()); |
||
| 425 | $this->assertNull($schemaAttribute->fkTable()); |
||
| 426 | $this->assertNull($schemaAttribute->fkId()); |
||
| 427 | $this->assertNull($schemaAttribute->fkName()); |
||
| 428 | } |
||
| 429 | |||
| 430 | public function testItSchemaAttributeConstraintsAsArray(): void |
||
| 431 | { |
||
| 432 | $name = 'foo'; |
||
| 433 | $dataType = 'integer'; |
||
| 434 | $constraints = [ |
||
| 435 | 'required', |
||
| 436 | 'equalto' => '#id', |
||
| 437 | 'type' => 'text', |
||
| 438 | 'pk' => true, |
||
| 439 | 'ai' => true, |
||
| 440 | ]; |
||
| 441 | |||
| 442 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints); |
||
| 443 | |||
| 444 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 445 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 446 | $this->assertEquals('int', $schemaAttribute->typeHint()); |
||
| 447 | $this->assertIsArray($schemaAttribute->constraints()); |
||
| 448 | $this->assertSame(true, $schemaAttribute->isRequired()); |
||
| 449 | $this->assertNull($schemaAttribute->min()); |
||
| 450 | $this->assertNull($schemaAttribute->minLength()); |
||
| 451 | $this->assertNull($schemaAttribute->minCheck()); |
||
| 452 | $this->assertNull($schemaAttribute->max()); |
||
| 453 | $this->assertNull($schemaAttribute->maxLength()); |
||
| 454 | $this->assertNull($schemaAttribute->maxCheck()); |
||
| 455 | $this->assertSame('#id', $schemaAttribute->equalTo()); |
||
| 456 | $this->assertSame('text', $schemaAttribute->type()); |
||
| 457 | $this->assertTrue($schemaAttribute->isPk()); |
||
| 458 | $this->assertTrue($schemaAttribute->isAi()); |
||
| 459 | $this->assertFalse($schemaAttribute->isFk()); |
||
| 460 | } |
||
| 461 | |||
| 462 | public function testItSchemaAttributeConstraintsAsArrayCast(): void |
||
| 463 | { |
||
| 464 | $name = 'foo'; |
||
| 465 | $dataType = 'datetime'; |
||
| 466 | $constraints = [ |
||
| 467 | 'required', |
||
| 468 | 'equalto' => '#bar', |
||
| 469 | 'type' => 'number', |
||
| 470 | ]; |
||
| 471 | |||
| 472 | $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints); |
||
| 473 | |||
| 474 | $this->assertEquals($name, $schemaAttribute->name()); |
||
| 475 | $this->assertEquals($dataType, $schemaAttribute->dataType()); |
||
| 476 | $this->assertEquals('\DateTime', $schemaAttribute->typeHint()); |
||
| 477 | $this->assertIsArray($schemaAttribute->constraints()); |
||
| 478 | $this->assertSame(true, $schemaAttribute->isRequired()); |
||
| 479 | $this->assertNull($schemaAttribute->min()); |
||
| 480 | $this->assertNull($schemaAttribute->minLength()); |
||
| 481 | $this->assertNull($schemaAttribute->minCheck()); |
||
| 482 | $this->assertNull($schemaAttribute->max()); |
||
| 483 | $this->assertNull($schemaAttribute->maxLength()); |
||
| 484 | $this->assertNull($schemaAttribute->maxCheck()); |
||
| 485 | $this->assertSame('#bar', $schemaAttribute->equalTo()); |
||
| 486 | $this->assertSame('number', $schemaAttribute->type()); |
||
| 487 | } |
||
| 488 | |||
| 489 | public function getRequiredConstraint(): array |
||
| 490 | { |
||
| 491 | return [ |
||
| 492 | ['', false], |
||
| 493 | ['required', true], |
||
| 494 | ['required:true', true], |
||
| 495 | ['required:false', false], |
||
| 496 | [['required'], true], |
||
| 497 | [['required' => true], true], |
||
| 498 | [['required' => false], false], |
||
| 499 | ]; |
||
| 500 | } |
||
| 501 | |||
| 502 | public function getMinLengthConstraint(): array |
||
| 503 | { |
||
| 504 | return [ |
||
| 505 | ['', null], |
||
| 506 | ['minlength:8', 8], |
||
| 507 | [['minlength' => 8], 8], |
||
| 508 | [['minlength' => '8'], 8], |
||
| 509 | ]; |
||
| 510 | } |
||
| 511 | |||
| 512 | public function getMinConstraint(): array |
||
| 513 | { |
||
| 514 | return [ |
||
| 515 | ['', null], |
||
| 516 | ['min:8', 8], |
||
| 517 | [['min' => 8], 8], |
||
| 518 | [['min' => '8'], 8], |
||
| 519 | ]; |
||
| 520 | } |
||
| 521 | |||
| 522 | public function getMaxLengthConstraint(): array |
||
| 523 | { |
||
| 524 | return [ |
||
| 525 | ['', null], |
||
| 526 | ['maxlength:10', 10], |
||
| 527 | [['maxlength' => 10], 10], |
||
| 528 | [['maxlength' => '10'], 10], |
||
| 529 | ]; |
||
| 530 | } |
||
| 531 | |||
| 532 | public function getMaxConstraint(): array |
||
| 533 | { |
||
| 534 | return [ |
||
| 535 | ['', null], |
||
| 536 | ['max:100', 100], |
||
| 537 | [['max' => 100], 100], |
||
| 538 | [['max' => '100'], 100], |
||
| 539 | ]; |
||
| 540 | } |
||
| 541 | |||
| 542 | public function getMinCheckConstraint(): array |
||
| 543 | { |
||
| 544 | return [ |
||
| 545 | ['', null], |
||
| 546 | ['mincheck:3', 3], |
||
| 547 | [['mincheck' => 3], 3], |
||
| 548 | [['mincheck' => '3'], 3], |
||
| 549 | ]; |
||
| 550 | } |
||
| 551 | |||
| 552 | public function getMaxCheckConstraint(): array |
||
| 553 | { |
||
| 554 | return [ |
||
| 555 | ['', null], |
||
| 556 | ['maxcheck:4', 4], |
||
| 557 | [['maxcheck' => 4], 4], |
||
| 558 | [['maxcheck' => '4'], 4], |
||
| 559 | ]; |
||
| 560 | } |
||
| 561 | |||
| 562 | public function getCheckConstraint(): array |
||
| 571 | ]; |
||
| 572 | } |
||
| 573 | |||
| 574 | public function getLengthConstraint(): array |
||
| 575 | { |
||
| 576 | return [ |
||
| 577 | ['', null, null], |
||
| 578 | ['length:30,40', 30, 40], |
||
| 579 | [['length' => [ |
||
| 580 | 'min' => 5, |
||
| 581 | 'max' => 60, |
||
| 582 | ]], 5, 60], |
||
| 583 | ]; |
||
| 584 | } |
||
| 585 | |||
| 586 | public function getEqualToConstraint(): array |
||
| 587 | { |
||
| 588 | return [ |
||
| 589 | ['', null], |
||
| 590 | ['equalto:#foo', '#foo'], |
||
| 591 | [['equalto' => '.foo'], '.foo'], |
||
| 592 | ]; |
||
| 593 | } |
||
| 594 | |||
| 595 | public function getTypeConstraint(): array |
||
| 596 | { |
||
| 597 | return [ |
||
| 598 | ['', null], |
||
| 599 | ['type:number', 'number'], |
||
| 600 | [['type' => 'text'], 'text'], |
||
| 601 | ]; |
||
| 602 | } |
||
| 603 | |||
| 604 | public function getPkConstraint(): array |
||
| 605 | { |
||
| 606 | return [ |
||
| 607 | ['', false], |
||
| 608 | ['required|pk', true], |
||
| 609 | ['required|pk:true', true], |
||
| 610 | ['required|pk:false', false], |
||
| 611 | [['required', 'pk'], true], |
||
| 612 | [['required', 'pk' => true], true], |
||
| 613 | [['required', 'pk' => false], false], |
||
| 614 | ]; |
||
| 615 | } |
||
| 616 | |||
| 617 | public function getAiConstraint(): array |
||
| 618 | { |
||
| 619 | return [ |
||
| 620 | ['', false], |
||
| 621 | ['required|pk|ai', true], |
||
| 622 | ['required|pk|ai:true', true], |
||
| 623 | // ['required|pk|ai:false', false], |
||
| 624 | [['required', 'pk', 'ai'], true], |
||
| 625 | [['required', 'pk', 'ai' => true], true], |
||
| 626 | // [['required', 'pk', 'ai' => false], false], |
||
| 627 | ]; |
||
| 628 | } |
||
| 629 | |||
| 630 | public function getCaConstraint(): array |
||
| 640 | ]; |
||
| 641 | } |
||
| 642 | |||
| 643 | public function getUaConstraint(): array |
||
| 644 | { |
||
| 645 | return [ |
||
| 646 | ['', false], |
||
| 647 | ['ua', true], |
||
| 648 | ['ua:true', true], |
||
| 649 | ['ua:false', false], |
||
| 650 | [['ua'], true], |
||
| 651 | [['ua' => true], true], |
||
| 652 | [['ua' => false], false], |
||
| 653 | ]; |
||
| 654 | } |
||
| 655 | |||
| 656 | public function getFkConstraint(): array |
||
| 657 | { |
||
| 658 | return [ |
||
| 659 | ['fk:table', 'table', 'id', 'name'], |
||
| 660 | ['fk:table2,username', 'table2', 'id', 'username'], |
||
| 661 | ['fk:table3,description,uuid', 'table3', 'uuid', 'description'], |
||
| 662 | [['fk' => 'table5'], 'table5', 'id', 'name'], |
||
| 663 | [['fk' => 'table6,username'], 'table6', 'id', 'username'], |
||
| 664 | [['fk' => 'table7,description,uuid'], 'table7', 'uuid', 'description'], |
||
| 665 | ]; |
||
| 666 | } |
||
| 667 | |||
| 668 | public function getCbConstraint(): array |
||
| 678 | ]; |
||
| 679 | } |
||
| 680 | |||
| 681 | public function getUbConstraint(): array |
||
| 682 | { |
||
| 683 | return [ |
||
| 684 | ['', false], |
||
| 685 | ['ub', true], |
||
| 686 | ['ub:true', true], |
||
| 687 | ['ub:false', false], |
||
| 688 | [['ub'], true], |
||
| 689 | [['ub' => true], true], |
||
| 690 | [['ub' => false], false], |
||
| 691 | ]; |
||
| 692 | } |
||
| 693 | |||
| 694 | public function getConstraintLogicError(): array |
||
| 695 | { |
||
| 696 | return [ |
||
| 697 | ['integer', 'pk|ai|required|min:10'], |
||
| 698 | ['integer', 'pk|ai|required|fk:table'], |
||
| 699 | ['integer', 'pk|required'], |
||
| 700 | ['integer', 'ai'], |
||
| 701 | ['integer', 'ai|pk'], |
||
| 702 | ['string', 'ai|pk|required'], |
||
| 703 | ['string', 'ca'], |
||
| 704 | ['integer', 'ua'], |
||
| 705 | ['datetime', 'ca|ua'], |
||
| 706 | ['integer', 'fk:table|ai|pk|required'], |
||
| 707 | ['integer', 'required:false|ai|pk'], |
||
| 708 | ['integer', 'required:false|pk'], |
||
| 709 | ['smallint', 'maxlength:100'], |
||
| 710 | ['integer', 'maxlength:100'], |
||
| 711 | ['bigint', 'maxlength:100'], |
||
| 712 | ['double', 'maxlength:100'], |
||
| 713 | ['float', 'maxlength:100'], |
||
| 714 | ['smallint', 'minlength:10'], |
||
| 715 | ['integer', 'minlength:10'], |
||
| 716 | ['bigint', 'minlength:10'], |
||
| 717 | ['double', 'minlength:10'], |
||
| 718 | ['float', 'minlength:10'], |
||
| 719 | ['string', 'min:100'], |
||
| 720 | ['text', 'max:10'], |
||
| 721 | ['guid', 'min:10'], |
||
| 722 | ['binary', 'max:10'], |
||
| 723 | ['blob', 'maxlength:1'], |
||
| 724 | ['datetimetz', 'maxlength:1'], |
||
| 725 | ['time', 'mincheck:1'], |
||
| 726 | ['datetime', 'maxcheck:1'], |
||
| 727 | ['datetime', 'cb'], |
||
| 728 | ['bool', 'ub'], |
||
| 729 | ['binary', 'cb'], |
||
| 730 | ['blob', 'ub'], |
||
| 731 | ['integer', 'cb|ub'], |
||
| 735 |