testItSchemaAttributeCbConstraints()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\Schema\Tests\Unit;
11
12
use FlexPHP\Schema\Constants\Action;
13
use FlexPHP\Schema\SchemaAttribute;
14
use FlexPHP\Schema\Tests\TestCase;
15
16
class SchemaAttributeTest extends TestCase
17
{
18
    public function testItSchemaAttributeWithInvalidNamePropertiesThrowException(): void
19
    {
20
        $this->expectException(\FlexPHP\Schema\Exception\InvalidSchemaAttributeException::class);
21
        $this->expectExceptionMessage('Name:');
22
23
        new SchemaAttribute('', 'string');
24
    }
25
26
    public function testItSchemaAttributeWithInvalidDataTypePropertiesThrowException(): void
27
    {
28
        $this->expectException(\FlexPHP\Schema\Exception\InvalidSchemaAttributeException::class);
29
        $this->expectExceptionMessage('DataType:');
30
31
        new SchemaAttribute('foo', 'bar');
32
    }
33
34
    /**
35
     * @dataProvider getConstraintLogicError
36
     */
37
    public function testItSchemaAttributeConstraintLogicError(string $dataType, string $constraints): void
38
    {
39
        $this->expectException(\FlexPHP\Schema\Exception\InvalidSchemaAttributeException::class);
40
        $this->expectExceptionMessage('Logic:');
41
42
        new SchemaAttribute('foo', $dataType, $constraints);
43
    }
44
45
    public function testItSchemaAttributeWithRequiredPropertiesSetValues(): void
46
    {
47
        $name = 'foo';
48
        $dataType = 'string';
49
50
        $schemaAttribute = new SchemaAttribute($name, $dataType);
51
52
        $this->assertEquals($name, $schemaAttribute->name());
53
        $this->assertEquals($dataType, $schemaAttribute->dataType());
54
    }
55
56
    /**
57
     * @dataProvider getRequiredConstraint
58
     *
59
     * @param mixed $constraint
60
     * @param mixed $expected
61
     */
62
    public function testItSchemaAttributeRequiredConstraints($constraint, $expected): void
63
    {
64
        $name = 'foo';
65
        $dataType = 'string';
66
67
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
68
69
        $this->assertEquals($name, $schemaAttribute->name());
70
        $this->assertEquals($dataType, $schemaAttribute->dataType());
71
        $this->assertSame($expected, $schemaAttribute->isRequired());
72
    }
73
74
    /**
75
     * @dataProvider getMinLengthConstraint
76
     *
77
     * @param mixed $constraint
78
     * @param mixed $expected
79
     */
80
    public function testItSchemaAttributeMinLengthConstraints($constraint, $expected): void
81
    {
82
        $name = 'foo';
83
        $dataType = 'string';
84
85
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
86
87
        $this->assertEquals($name, $schemaAttribute->name());
88
        $this->assertEquals($dataType, $schemaAttribute->dataType());
89
        $this->assertSame($expected, $schemaAttribute->minLength());
90
    }
91
92
    /**
93
     * @dataProvider getMinConstraint
94
     *
95
     * @param mixed $constraint
96
     * @param mixed $expected
97
     */
98
    public function testItSchemaAttributeMinConstraints($constraint, $expected): void
99
    {
100
        $name = 'min';
101
        $dataType = 'integer';
102
103
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
104
105
        $this->assertEquals($name, $schemaAttribute->name());
106
        $this->assertEquals($dataType, $schemaAttribute->dataType());
107
        $this->assertSame($expected, $schemaAttribute->min());
108
    }
109
110
    /**
111
     * @dataProvider getMaxLengthConstraint
112
     *
113
     * @param mixed $constraint
114
     * @param mixed $expected
115
     */
116
    public function testItSchemaAttributeMaxLengthConstraints($constraint, $expected): void
117
    {
118
        $name = 'minLength';
119
        $dataType = 'string';
120
121
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
122
123
        $this->assertEquals($name, $schemaAttribute->name());
124
        $this->assertEquals($dataType, $schemaAttribute->dataType());
125
        $this->assertSame($expected, $schemaAttribute->maxLength());
126
    }
127
128
    /**
129
     * @dataProvider getMaxConstraint
130
     *
131
     * @param mixed $constraint
132
     * @param mixed $expected
133
     */
134
    public function testItSchemaAttributeMaxConstraints($constraint, $expected): void
135
    {
136
        $name = 'max';
137
        $dataType = 'integer';
138
139
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
140
141
        $this->assertEquals($name, $schemaAttribute->name());
142
        $this->assertEquals($dataType, $schemaAttribute->dataType());
143
        $this->assertSame($expected, $schemaAttribute->max());
144
    }
145
146
    /**
147
     * @dataProvider getMinCheckConstraint
148
     *
149
     * @param mixed $constraint
150
     * @param mixed $expected
151
     */
152
    public function testItSchemaAttributeMinCheckConstraints($constraint, $expected): void
153
    {
154
        $name = 'minCheck';
155
        $dataType = 'integer';
156
157
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
158
159
        $this->assertEquals($name, $schemaAttribute->name());
160
        $this->assertEquals($dataType, $schemaAttribute->dataType());
161
        $this->assertSame($expected, $schemaAttribute->minCheck());
162
    }
163
164
    /**
165
     * @dataProvider getMaxCheckConstraint
166
     *
167
     * @param mixed $constraint
168
     * @param mixed $expected
169
     */
170
    public function testItSchemaAttributeMaxCheckConstraints($constraint, $expected): void
171
    {
172
        $name = 'maxCheck';
173
        $dataType = 'integer';
174
175
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
176
177
        $this->assertEquals($name, $schemaAttribute->name());
178
        $this->assertEquals($dataType, $schemaAttribute->dataType());
179
        $this->assertSame($expected, $schemaAttribute->maxCheck());
180
    }
181
182
    /**
183
     * @dataProvider getCheckConstraint
184
     *
185
     * @param mixed $constraint
186
     * @param mixed $expectedMin
187
     * @param mixed $expectedMax
188
     */
189
    public function testItSchemaAttributeCheckConstraints($constraint, $expectedMin, $expectedMax): void
190
    {
191
        $name = 'check';
192
        $dataType = 'integer';
193
194
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
195
196
        $this->assertEquals($name, $schemaAttribute->name());
197
        $this->assertEquals($dataType, $schemaAttribute->dataType());
198
        $this->assertSame($expectedMin, $schemaAttribute->minCheck());
199
        $this->assertSame($expectedMax, $schemaAttribute->maxCheck());
200
    }
201
202
    /**
203
     * @dataProvider getLengthConstraint
204
     *
205
     * @param mixed $constraint
206
     * @param mixed $expectedMin
207
     * @param mixed $expectedMax
208
     */
209
    public function testItSchemaAttributeLengthConstraints($constraint, $expectedMin, $expectedMax): void
210
    {
211
        $name = 'length';
212
        $dataType = 'string';
213
214
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
215
216
        $this->assertEquals($name, $schemaAttribute->name());
217
        $this->assertEquals($dataType, $schemaAttribute->dataType());
218
        $this->assertSame($expectedMin, $schemaAttribute->minLength());
219
        $this->assertSame($expectedMax, $schemaAttribute->maxLength());
220
    }
221
222
    /**
223
     * @dataProvider getEqualToConstraint
224
     *
225
     * @param mixed $constraint
226
     * @param mixed $expected
227
     */
228
    public function testItSchemaAttributeEqualToConstraints($constraint, $expected): void
229
    {
230
        $name = 'equalTo';
231
        $dataType = 'string';
232
233
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
234
235
        $this->assertEquals($name, $schemaAttribute->name());
236
        $this->assertEquals($dataType, $schemaAttribute->dataType());
237
        $this->assertSame($expected, $schemaAttribute->equalTo());
238
    }
239
240
    /**
241
     * @dataProvider getTypeConstraint
242
     *
243
     * @param mixed $constraint
244
     * @param mixed $expected
245
     */
246
    public function testItSchemaAttributeTypeConstraints($constraint, $expected): void
247
    {
248
        $name = 'equalTo';
249
        $dataType = 'string';
250
251
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
252
253
        $this->assertEquals($name, $schemaAttribute->name());
254
        $this->assertEquals($dataType, $schemaAttribute->dataType());
255
        $this->assertSame($expected, $schemaAttribute->type());
256
    }
257
258
    /**
259
     * @dataProvider getPkConstraint
260
     *
261
     * @param mixed $constraint
262
     * @param mixed $expected
263
     */
264
    public function testItSchemaAttributePkConstraints($constraint, $expected): void
265
    {
266
        $name = 'foo';
267
        $dataType = 'string';
268
269
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
270
271
        $this->assertEquals($name, $schemaAttribute->name());
272
        $this->assertEquals($dataType, $schemaAttribute->dataType());
273
        $this->assertSame($expected, $schemaAttribute->isPk());
274
    }
275
276
    /**
277
     * @dataProvider getAiConstraint
278
     *
279
     * @param mixed $constraint
280
     * @param mixed $expected
281
     */
282
    public function testItSchemaAttributeAiConstraints($constraint, $expected): void
283
    {
284
        $name = 'foo';
285
        $dataType = 'integer';
286
287
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
288
289
        $this->assertEquals($name, $schemaAttribute->name());
290
        $this->assertEquals($dataType, $schemaAttribute->dataType());
291
        $this->assertSame($expected, $schemaAttribute->isAi());
292
    }
293
294
    /**
295
     * @dataProvider getCaConstraint
296
     *
297
     * @param mixed $constraint
298
     * @param mixed $expected
299
     */
300
    public function testItSchemaAttributeCaConstraints($constraint, $expected): void
301
    {
302
        $name = 'foo';
303
        $dataType = 'datetime';
304
305
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
306
307
        $this->assertEquals($name, $schemaAttribute->name());
308
        $this->assertEquals($dataType, $schemaAttribute->dataType());
309
        $this->assertSame($expected, $schemaAttribute->isCa());
310
        $this->assertSame($expected, $schemaAttribute->isBlame());
311
        $this->assertSame($expected, $schemaAttribute->isBlameAt());
312
        $this->assertSame(false, $schemaAttribute->isBlameBy());
313
    }
314
315
    /**
316
     * @dataProvider getUaConstraint
317
     *
318
     * @param mixed $constraint
319
     * @param mixed $expected
320
     */
321
    public function testItSchemaAttributeUaConstraints($constraint, $expected): void
322
    {
323
        $name = 'foo';
324
        $dataType = 'datetime';
325
326
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
327
328
        $this->assertEquals($name, $schemaAttribute->name());
329
        $this->assertEquals($dataType, $schemaAttribute->dataType());
330
        $this->assertSame($expected, $schemaAttribute->isUa());
331
        $this->assertSame($expected, $schemaAttribute->isBlame());
332
        $this->assertSame($expected, $schemaAttribute->isBlameAt());
333
        $this->assertSame(false, $schemaAttribute->isBlameBy());
334
    }
335
336
    /**
337
     * @dataProvider getCbConstraint
338
     *
339
     * @param mixed $constraint
340
     * @param mixed $expected
341
     */
342
    public function testItSchemaAttributeCbConstraints($constraint, $expected): void
343
    {
344
        $name = 'foo';
345
        $dataType = 'integer';
346
347
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
348
349
        $this->assertEquals($name, $schemaAttribute->name());
350
        $this->assertEquals($dataType, $schemaAttribute->dataType());
351
        $this->assertSame($expected, $schemaAttribute->isCb());
352
        $this->assertSame($expected, $schemaAttribute->isBlame());
353
        $this->assertSame(false, $schemaAttribute->isBlameAt());
354
        $this->assertSame($expected, $schemaAttribute->isBlameBy());
355
    }
356
357
    /**
358
     * @dataProvider getUbConstraint
359
     *
360
     * @param mixed $constraint
361
     * @param mixed $expected
362
     */
363
    public function testItSchemaAttributeUbConstraints($constraint, $expected): void
364
    {
365
        $name = 'foo';
366
        $dataType = 'integer';
367
368
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
369
370
        $this->assertEquals($name, $schemaAttribute->name());
371
        $this->assertEquals($dataType, $schemaAttribute->dataType());
372
        $this->assertSame($expected, $schemaAttribute->isUb());
373
        $this->assertSame($expected, $schemaAttribute->isBlame());
374
        $this->assertSame(false, $schemaAttribute->isBlameAt());
375
        $this->assertSame($expected, $schemaAttribute->isBlameBy());
376
    }
377
378
    /**
379
     * @dataProvider getFilterConstraint
380
     *
381
     * @param mixed $constraint
382
     * @param mixed $expected
383
     */
384
    public function testItSchemaAttributeFilterConstraints($constraint, $expected): void
385
    {
386
        $name = 'foo';
387
        $dataType = 'integer';
388
389
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
390
391
        $this->assertEquals($name, $schemaAttribute->name());
392
        $this->assertEquals($dataType, $schemaAttribute->dataType());
393
        $this->assertSame($expected, $schemaAttribute->filter());
394
    }
395
396
    /**
397
     * @dataProvider getFormatConstraint
398
     */
399
    public function testItSchemaAttributeFormatConstraints(
400
        string $dataType,
401
        string $constraint,
402
        ?string $expected
403
    ): void {
404
        $name = 'foo';
405
406
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
407
408
        $this->assertEquals($name, $schemaAttribute->name());
409
        $this->assertEquals($dataType, $schemaAttribute->dataType());
410
        $this->assertSame($expected, $schemaAttribute->format());
411
    }
412
413
    /**
414
     * @dataProvider getTrimConstraint
415
     *
416
     * @param mixed $constraint
417
     */
418
    public function testItSchemaAttributeTrimConstraints($constraint, bool $expected): void
419
    {
420
        $name = 'foo';
421
        $dataType = 'string';
422
423
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
424
425
        $this->assertEquals($name, $schemaAttribute->name());
426
        $this->assertEquals($dataType, $schemaAttribute->dataType());
427
        $this->assertSame($expected, $schemaAttribute->trim());
428
    }
429
430
    /**
431
     * @dataProvider getFcharsConstraint
432
     */
433
    public function testItSchemaAttributeFcharsConstraints(string $constraint, ?int $expected): void
434
    {
435
        $name = 'foo';
436
        $dataType = 'string';
437
438
        if (!empty($constraint)) {
439
            $constraint = 'fk:fkTable,fkName|' . $constraint;
440
        }
441
442
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
443
444
        $this->assertEquals($name, $schemaAttribute->name());
445
        $this->assertEquals($dataType, $schemaAttribute->dataType());
446
        $this->assertSame($expected, $schemaAttribute->fchars());
447
    }
448
449
    /**
450
     * @dataProvider getLinkConstraint
451
     *
452
     * @param mixed $constraint
453
     */
454
    public function testItSchemaAttributeLinkConstraints($constraint, ?bool $expected): void
455
    {
456
        $name = 'foo';
457
        $dataType = 'string';
458
459
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
460
461
        $this->assertEquals($name, $schemaAttribute->name());
462
        $this->assertEquals($dataType, $schemaAttribute->dataType());
463
        $this->assertSame($expected, $schemaAttribute->link());
464
    }
465
466
    /**
467
     * @dataProvider getFkCheckConstraint
468
     *
469
     * @param mixed $constraint
470
     */
471
    public function testItSchemaAttributeFkCheckConstraints($constraint, ?bool $expected): void
472
    {
473
        $name = 'foo';
474
        $dataType = 'string';
475
476
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
477
478
        $this->assertEquals($name, $schemaAttribute->name());
479
        $this->assertEquals($dataType, $schemaAttribute->dataType());
480
        $this->assertSame($expected, $schemaAttribute->fkcheck());
481
    }
482
483
    /**
484
     * @dataProvider getShowConstraint
485
     */
486
    public function testItSchemaAttributeShowConstraints(string $dataType, string $constraint, string $expected): void
487
    {
488
        $name = 'foo';
489
490
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
491
492
        $this->assertEquals($name, $schemaAttribute->name());
493
        $this->assertEquals($dataType, $schemaAttribute->dataType());
494
        $this->assertTrue($schemaAttribute->usedIn($expected));
495
    }
496
497
    /**
498
     * @dataProvider getDefaultConstraint
499
     *
500
     * @param mixed $constraint
501
     * @param mixed $expected
502
     */
503
    public function testItSchemaAttributeDefaultConstraints(string $dataType, $constraint, $expected): void
504
    {
505
        $name = 'foo';
506
507
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
508
509
        $this->assertEquals($name, $schemaAttribute->name());
510
        $this->assertEquals($dataType, $schemaAttribute->dataType());
511
        $this->assertSame($expected, $schemaAttribute->default());
512
    }
513
514
    /**
515
     * @dataProvider getHideConstraint
516
     */
517
    public function testItSchemaAttributeHideConstraints(
518
        string $dataType,
519
        string $constraint,
520
        string $action,
521
        bool $expected
522
    ): void {
523
        $name = 'foo';
524
525
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
526
527
        $this->assertEquals($name, $schemaAttribute->name());
528
        $this->assertEquals($dataType, $schemaAttribute->dataType());
529
        $this->assertSame($expected, $schemaAttribute->usedIn($action));
530
    }
531
532
    /**
533
     * @dataProvider getFkConstraint
534
     *
535
     * @param mixed $constraint
536
     * @param mixed $fkTable
537
     * @param mixed $fkId
538
     * @param mixed $fkName
539
     */
540
    public function testItSchemaAttributeFkConstraints($constraint, $fkTable, $fkId, $fkName): void
541
    {
542
        $name = 'foreing';
543
        $dataType = 'integer';
544
545
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
546
547
        $this->assertEquals($name, $schemaAttribute->name());
548
        $this->assertEquals($dataType, $schemaAttribute->dataType());
549
        $this->assertEquals('int', $schemaAttribute->typeHint());
550
        $this->assertTrue($schemaAttribute->isFk());
551
        $this->assertSame($fkTable, $schemaAttribute->fkTable());
552
        $this->assertSame($fkId, $schemaAttribute->fkId());
553
        $this->assertSame($fkName, $schemaAttribute->fkName());
554
    }
555
556
    public function testItSchemaAttributeConstraintsAsString(): void
557
    {
558
        $name = 'foo';
559
        $dataType = 'string';
560
        $constraints = 'required|minlength:8|maxlength:10|mincheck:3|maxcheck:4|equalto:#bar|type:number';
561
562
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints);
563
564
        $this->assertEquals($name, $schemaAttribute->name());
565
        $this->assertEquals($dataType, $schemaAttribute->dataType());
566
        $this->assertEquals('string', $schemaAttribute->typeHint());
567
        $this->assertIsArray($schemaAttribute->constraints());
568
        $this->assertSame(true, $schemaAttribute->isRequired());
569
        $this->assertNull($schemaAttribute->min());
570
        $this->assertSame(8, $schemaAttribute->minLength());
571
        $this->assertSame(3, $schemaAttribute->minCheck());
572
        $this->assertNull($schemaAttribute->max());
573
        $this->assertSame(10, $schemaAttribute->maxLength());
574
        $this->assertSame(4, $schemaAttribute->maxCheck());
575
        $this->assertSame('#bar', $schemaAttribute->equalTo());
576
        $this->assertSame('number', $schemaAttribute->type());
577
        $this->assertFalse($schemaAttribute->isPk());
578
        $this->assertFalse($schemaAttribute->isAi());
579
        $this->assertFalse($schemaAttribute->isFk());
580
        $this->assertNull($schemaAttribute->fkTable());
581
        $this->assertNull($schemaAttribute->fkId());
582
        $this->assertNull($schemaAttribute->fkName());
583
    }
584
585
    public function testItSchemaAttributeConstraintsAsArray(): void
586
    {
587
        $name = 'foo';
588
        $dataType = 'integer';
589
        $constraints = [
590
            'required',
591
            'equalto' => '#id',
592
            'type' => 'text',
593
            'pk' => true,
594
            'ai' => true,
595
        ];
596
597
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints);
598
599
        $this->assertEquals($name, $schemaAttribute->name());
600
        $this->assertEquals($dataType, $schemaAttribute->dataType());
601
        $this->assertEquals('int', $schemaAttribute->typeHint());
602
        $this->assertIsArray($schemaAttribute->constraints());
603
        $this->assertSame(true, $schemaAttribute->isRequired());
604
        $this->assertNull($schemaAttribute->min());
605
        $this->assertNull($schemaAttribute->minLength());
606
        $this->assertNull($schemaAttribute->minCheck());
607
        $this->assertNull($schemaAttribute->max());
608
        $this->assertNull($schemaAttribute->maxLength());
609
        $this->assertNull($schemaAttribute->maxCheck());
610
        $this->assertSame('#id', $schemaAttribute->equalTo());
611
        $this->assertSame('text', $schemaAttribute->type());
612
        $this->assertTrue($schemaAttribute->isPk());
613
        $this->assertTrue($schemaAttribute->isAi());
614
        $this->assertFalse($schemaAttribute->isFk());
615
    }
616
617
    public function testItSchemaAttributeConstraintsAsArrayCast(): void
618
    {
619
        $name = 'foo';
620
        $dataType = 'datetime';
621
        $constraints = [
622
            'required',
623
            'equalto' => '#bar',
624
            'type' => 'number',
625
        ];
626
627
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints);
628
629
        $this->assertEquals($name, $schemaAttribute->name());
630
        $this->assertEquals($dataType, $schemaAttribute->dataType());
631
        $this->assertEquals('\DateTime', $schemaAttribute->typeHint());
632
        $this->assertIsArray($schemaAttribute->constraints());
633
        $this->assertSame(true, $schemaAttribute->isRequired());
634
        $this->assertNull($schemaAttribute->min());
635
        $this->assertNull($schemaAttribute->minLength());
636
        $this->assertNull($schemaAttribute->minCheck());
637
        $this->assertNull($schemaAttribute->max());
638
        $this->assertNull($schemaAttribute->maxLength());
639
        $this->assertNull($schemaAttribute->maxCheck());
640
        $this->assertSame('#bar', $schemaAttribute->equalTo());
641
        $this->assertSame('number', $schemaAttribute->type());
642
    }
643
644
    public function getRequiredConstraint(): array
645
    {
646
        return [
647
            ['', false],
648
            ['required', true],
649
            ['required:true', true],
650
            ['required:false', false],
651
            [['required'], true],
652
            [['required' => true], true],
653
            [['required' => false], false],
654
        ];
655
    }
656
657
    public function getMinLengthConstraint(): array
658
    {
659
        return [
660
            ['', null],
661
            ['minlength:8', 8],
662
            [['minlength' => 8], 8],
663
            [['minlength' => '8'], 8],
664
        ];
665
    }
666
667
    public function getMinConstraint(): array
668
    {
669
        return [
670
            ['', null],
671
            ['min:8', 8],
672
            [['min' => 8], 8],
673
            [['min' => '8'], 8],
674
        ];
675
    }
676
677
    public function getMaxLengthConstraint(): array
678
    {
679
        return [
680
            ['', null],
681
            ['maxlength:10', 10],
682
            [['maxlength' => 10], 10],
683
            [['maxlength' => '10'], 10],
684
        ];
685
    }
686
687
    public function getMaxConstraint(): array
688
    {
689
        return [
690
            ['', null],
691
            ['max:100', 100],
692
            [['max' => 100], 100],
693
            [['max' => '100'], 100],
694
        ];
695
    }
696
697
    public function getMinCheckConstraint(): array
698
    {
699
        return [
700
            ['', null],
701
            ['mincheck:3', 3],
702
            [['mincheck' => 3], 3],
703
            [['mincheck' => '3'], 3],
704
        ];
705
    }
706
707
    public function getMaxCheckConstraint(): array
708
    {
709
        return [
710
            ['', null],
711
            ['maxcheck:4', 4],
712
            [['maxcheck' => 4], 4],
713
            [['maxcheck' => '4'], 4],
714
        ];
715
    }
716
717
    public function getCheckConstraint(): array
718
    {
719
        return [
720
            ['', null, null],
721
            ['check:3,4', 3, 4],
722
            [['check' => [
723
                'min' => 5,
724
                'max' => 6,
725
            ]], 5, 6],
726
        ];
727
    }
728
729
    public function getLengthConstraint(): array
730
    {
731
        return [
732
            ['', null, null],
733
            ['length:30,40', 30, 40],
734
            [['length' => [
735
                'min' => 5,
736
                'max' => 60,
737
            ]], 5, 60],
738
        ];
739
    }
740
741
    public function getEqualToConstraint(): array
742
    {
743
        return [
744
            ['', null],
745
            ['equalto:#foo', '#foo'],
746
            [['equalto' => '.foo'], '.foo'],
747
        ];
748
    }
749
750
    public function getTypeConstraint(): array
751
    {
752
        return [
753
            ['', null],
754
            ['type:number', 'number'],
755
            [['type' => 'text'], 'text'],
756
        ];
757
    }
758
759
    public function getPkConstraint(): array
760
    {
761
        return [
762
            ['', false],
763
            ['required|pk', true],
764
            ['required|pk:true', true],
765
            ['required|pk:false', false],
766
            [['required', 'pk'], true],
767
            [['required', 'pk' => true], true],
768
            [['required', 'pk' => false], false],
769
        ];
770
    }
771
772
    public function getAiConstraint(): array
773
    {
774
        return [
775
            ['', false],
776
            ['required|pk|ai', true],
777
            ['required|pk|ai:true', true],
778
            [['required', 'pk', 'ai'], true],
779
            [['required', 'pk', 'ai' => true], true],
780
        ];
781
    }
782
783
    public function getCaConstraint(): array
784
    {
785
        return [
786
            ['', false],
787
            ['ca', true],
788
            ['ca:true', true],
789
            ['ca:false', false],
790
            [['ca'], true],
791
            [['ca' => true], true],
792
            [['ca' => false], false],
793
        ];
794
    }
795
796
    public function getUaConstraint(): array
797
    {
798
        return [
799
            ['', false],
800
            ['ua', true],
801
            ['ua:true', true],
802
            ['ua:false', false],
803
            [['ua'], true],
804
            [['ua' => true], true],
805
            [['ua' => false], false],
806
        ];
807
    }
808
809
    public function getFkConstraint(): array
810
    {
811
        return [
812
            ['fk:table', 'table', 'id', 'name'],
813
            ['fk:table2,username', 'table2', 'id', 'username'],
814
            ['fk:table3,description,uuid', 'table3', 'uuid', 'description'],
815
            [['fk' => 'table5'], 'table5', 'id', 'name'],
816
            [['fk' => 'table6,username'], 'table6', 'id', 'username'],
817
            [['fk' => 'table7,description,uuid'], 'table7', 'uuid', 'description'],
818
        ];
819
    }
820
821
    public function getCbConstraint(): array
822
    {
823
        return [
824
            ['', false],
825
            ['cb', true],
826
            ['cb:true', true],
827
            ['cb:false', false],
828
            [['cb'], true],
829
            [['cb' => true], true],
830
            [['cb' => false], false],
831
        ];
832
    }
833
834
    public function getUbConstraint(): array
835
    {
836
        return [
837
            ['', false],
838
            ['ub', true],
839
            ['ub:true', true],
840
            ['ub:false', false],
841
            [['ub'], true],
842
            [['ub' => true], true],
843
            [['ub' => false], false],
844
        ];
845
    }
846
847
    public function getFilterConstraint(): array
848
    {
849
        return [
850
            ['', null],
851
            ['filter:eq', 'eq'],
852
            ['filter:nn', 'nn'],
853
        ];
854
    }
855
856
    public function getFormatConstraint(): array
857
    {
858
        return [
859
            ['string', '', null],
860
            ['datetime', 'format:timeago', 'timeago'],
861
            ['datetime', 'format:datetime', 'datetime'],
862
            ['integer', 'format:money', 'money'],
863
        ];
864
    }
865
866
    public function getTrimConstraint(): array
867
    {
868
        return [
869
            ['', false],
870
            ['trim', true],
871
            ['trim:true', true],
872
            ['trim:false', false],
873
            [['trim'], true],
874
            [['trim' => true], true],
875
            [['trim' => false], false],
876
        ];
877
    }
878
879
    public function getFcharsConstraint(): array
880
    {
881
        return [
882
            ['', null],
883
            ['fchars:0', 0],
884
            ['fchars:1', 1],
885
            ['fchars:2', 2],
886
            ['fchars:90', 90],
887
        ];
888
    }
889
890
    public function getLinkConstraint(): array
891
    {
892
        return [
893
            ['', false],
894
            ['link', true],
895
            ['link:true', true],
896
            ['link:false', false],
897
            [['link'], true],
898
            [['link' => true], true],
899
            [['link' => false], false],
900
        ];
901
    }
902
903
    public function getFkCheckConstraint(): array
904
    {
905
        return [
906
            ['', false],
907
            ['fk:fkTable,fkName|fkcheck', true],
908
            ['fk:fkTable,fkName|fkcheck:true', true],
909
            ['fk:fkTable,fkName|fkcheck:false', false],
910
            [['fk' => 'fkTable,fkName', 'fkcheck'], true],
911
            [['fk' => 'fkTable,fkName', 'fkcheck' => true], true],
912
            [['fk' => 'fkTable,fkName', 'fkcheck' => false], false],
913
        ];
914
    }
915
916
    public function getShowConstraint(): array
917
    {
918
        return [
919
            ['string', '', Action::ALL],
920
            ['datetime', 'ca', Action::READ],
921
            ['integer', 'cb', Action::READ],
922
            ['datetime', 'ua', Action::READ],
923
            ['integer', 'ub', Action::READ],
924
            ['string', 'show:a', Action::ALL],
925
            ['string', 'show:i', Action::INDEX],
926
            ['string', 'show:c', Action::CREATE],
927
            ['string', 'show:r', Action::READ],
928
            ['string', 'show:u', Action::UPDATE],
929
            ['string', 'show:p', Action::PATCH],
930
            ['string', 'show:d', Action::DELETE],
931
            ['datetime', 'ca|show:a', Action::ALL],
932
            ['integer', 'cb|show:i', Action::INDEX],
933
            ['datetime', 'ua|show:c', Action::CREATE],
934
            ['integer', 'ub|show:r', Action::READ],
935
        ];
936
    }
937
938
    public function getHideConstraint(): array
939
    {
940
        return [
941
            ['string', '', '', false],
942
            ['datetime', 'ca', Action::ALL, false],
943
            ['datetime', 'ca', Action::INDEX, false],
944
            ['datetime', 'ca', Action::CREATE, false],
945
            ['datetime', 'ca', Action::READ, true],
946
            ['datetime', 'ca', Action::UPDATE, false],
947
            ['datetime', 'ca', Action::PATCH, false],
948
            ['datetime', 'ca', Action::DELETE, false],
949
            ['integer', 'cb', Action::ALL, false],
950
            ['integer', 'cb', Action::INDEX, false],
951
            ['integer', 'cb', Action::CREATE, false],
952
            ['integer', 'cb', Action::READ, true],
953
            ['integer', 'cb', Action::UPDATE, false],
954
            ['integer', 'cb', Action::PATCH, false],
955
            ['integer', 'cb', Action::DELETE, false],
956
            ['string', 'hide:a', Action::ALL, false],
957
            ['string', 'hide:i', Action::INDEX, false],
958
            ['string', 'hide:c', Action::CREATE, false],
959
            ['string', 'hide:r', Action::READ, false],
960
            ['string', 'hide:u', Action::UPDATE, false],
961
            ['string', 'hide:p', Action::PATCH, false],
962
            ['string', 'hide:d', Action::DELETE, false],
963
            ['datetime', 'ca|hide:r', Action::READ, false],
964
            ['integer', 'cb|hide:r', Action::READ, false],
965
            ['datetime', 'ua|hide:r', Action::READ, false],
966
            ['integer', 'ub|hide:r', Action::READ, false],
967
        ];
968
    }
969
970
    public function getDefaultConstraint(): array
971
    {
972
        return [
973
            ['string', '', null],
974
            ['string', ['default' => null], null],
975
            ['string', 'default:', ''],
976
            ['string', 'default:A', 'A'],
977
            ['integer', 'default:-1', -1],
978
            ['double', 'default:0.0', 0.0],
979
            ['float', 'default:0.1', 0.1],
980
            ['datetime', 'default:NOW', 'NOW'],
981
        ];
982
    }
983
984
    public function getConstraintLogicError(): array
985
    {
986
        return [
987
            ['integer', 'pk|ai|required|min:10'],
988
            ['integer', 'pk|ai|required|fk:table'],
989
            ['integer', 'pk|required'],
990
            ['integer', 'ai'],
991
            ['integer', 'ai|pk'],
992
            ['string', 'ai|pk|required'],
993
            ['string', 'ca'],
994
            ['integer', 'ua'],
995
            ['datetime', 'ca|ua'],
996
            ['integer', 'fk:table|ai|pk|required'],
997
            ['integer', 'required:false|ai|pk'],
998
            ['integer', 'required:false|pk'],
999
            ['smallint', 'maxlength:100'],
1000
            ['integer', 'maxlength:100'],
1001
            ['bigint', 'maxlength:100'],
1002
            ['double', 'maxlength:100'],
1003
            ['float', 'maxlength:100'],
1004
            ['smallint', 'minlength:10'],
1005
            ['integer', 'minlength:10'],
1006
            ['bigint', 'minlength:10'],
1007
            ['double', 'minlength:10'],
1008
            ['float', 'minlength:10'],
1009
            ['string', 'min:100'],
1010
            ['text', 'max:10'],
1011
            ['guid', 'min:10'],
1012
            ['binary', 'max:10'],
1013
            ['blob', 'maxlength:1'],
1014
            ['datetimetz', 'maxlength:1'],
1015
            ['time', 'mincheck:1'],
1016
            ['datetime', 'maxcheck:1'],
1017
            ['datetime', 'cb'],
1018
            ['bool', 'ub'],
1019
            ['binary', 'cb'],
1020
            ['blob', 'ub'],
1021
            ['integer', 'cb|ub'],
1022
            ['smallint', 'format:datetime'],
1023
            ['integer', 'format:datetime'],
1024
            ['float', 'format:datetime'],
1025
            ['double', 'format:datetime'],
1026
            ['blob', 'format:datetime'],
1027
            ['blob', 'format:money'],
1028
            ['blob', 'format:timeago'],
1029
            ['boolean', 'format:datetime'],
1030
            ['boolean', 'format:money'],
1031
            ['boolean', 'format:timeago'],
1032
            ['bool', 'format:datetime'],
1033
            ['bool', 'format:money'],
1034
            ['bool', 'format:timeago'],
1035
            ['datetime', 'format:money'],
1036
            ['datetime_immutable', 'format:money'],
1037
            ['datetimetz', 'format:money'],
1038
            ['datetimetz_immutable', 'format:money'],
1039
            ['time', 'format:money'],
1040
            ['time_immutable', 'format:money'],
1041
            ['array', 'format:money'],
1042
            ['array', 'format:datetime'],
1043
            ['array', 'format:timeago'],
1044
            ['simple_array', 'format:money'],
1045
            ['simple_array', 'format:datetime'],
1046
            ['simple_array', 'format:timeago'],
1047
            ['json', 'format:money'],
1048
            ['json', 'format:datetime'],
1049
            ['json', 'format:timeago'],
1050
            ['string', 'format:datetime'],
1051
            ['string', 'format:timeago'],
1052
            ['object', 'format:timeago'],
1053
            ['text', 'format:timeago'],
1054
            ['string', 'fchars:1'],
1055
            ['integer', 'fchars:2'],
1056
            ['datetime', 'fchars:3'],
1057
            ['bool', 'fchars:4'],
1058
            ['array', 'fchars:5'],
1059
            ['string', 'show|hide'],
1060
            ['string', 'show:a|hide'],
1061
            ['string', 'show|hide:a'],
1062
            ['string', 'show:a|hide:a'],
1063
            ['string', 'show:i|hide:i'],
1064
            ['string', 'show:c|hide:c'],
1065
            ['string', 'show:r|hide:r'],
1066
            ['string', 'show:u|hide:u'],
1067
            ['string', 'show:d|hide:d'],
1068
            ['string', 'show:i,d|hide:i,c'],
1069
            ['string', 'fkcheck'],
1070
            ['string', 'default:false'],
1071
            ['string', 'default:true'],
1072
            ['bool', 'default:ERROR'],
1073
            ['integer', 'default:ERROR'],
1074
            ['double', 'default:ERROR'],
1075
            ['date', 'default:ERROR'],
1076
            ['datetime', 'default:ERROR'],
1077
            ['text', 'default:ERROR'],
1078
            ['binary', 'default:ERROR'],
1079
            ['array', 'default:ERROR'],
1080
            ['simple_array', 'default:ERROR'],
1081
            ['json', 'default:ERROR'],
1082
            ['object', 'default:ERROR'],
1083
        ];
1084
    }
1085
}
1086