Passed
Push — develop ( 8d04e4...f8d7bf )
by Freddie
03:08
created

SchemaAttributeTest::getDefaultConstraint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 10
rs 10
c 2
b 1
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
     * @param mixed $expected
500
     */
501
    public function testItSchemaAttributeDefaultConstraints(string $dataType, string $constraint, $expected): void
502
    {
503
        $name = 'foo';
504
505
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
506
507
        $this->assertEquals($name, $schemaAttribute->name());
508
        $this->assertEquals($dataType, $schemaAttribute->dataType());
509
        $this->assertSame($expected, $schemaAttribute->default());
510
    }
511
512
    /**
513
     * @dataProvider getHideConstraint
514
     */
515
    public function testItSchemaAttributeHideConstraints(
516
        string $dataType,
517
        string $constraint,
518
        string $action,
519
        bool $expected
520
    ): void {
521
        $name = 'foo';
522
523
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
524
525
        $this->assertEquals($name, $schemaAttribute->name());
526
        $this->assertEquals($dataType, $schemaAttribute->dataType());
527
        $this->assertSame($expected, $schemaAttribute->usedIn($action));
528
    }
529
530
    /**
531
     * @dataProvider getFkConstraint
532
     *
533
     * @param mixed $constraint
534
     * @param mixed $fkTable
535
     * @param mixed $fkId
536
     * @param mixed $fkName
537
     */
538
    public function testItSchemaAttributeFkConstraints($constraint, $fkTable, $fkId, $fkName): void
539
    {
540
        $name = 'foreing';
541
        $dataType = 'integer';
542
543
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraint);
544
545
        $this->assertEquals($name, $schemaAttribute->name());
546
        $this->assertEquals($dataType, $schemaAttribute->dataType());
547
        $this->assertEquals('int', $schemaAttribute->typeHint());
548
        $this->assertTrue($schemaAttribute->isFk());
549
        $this->assertSame($fkTable, $schemaAttribute->fkTable());
550
        $this->assertSame($fkId, $schemaAttribute->fkId());
551
        $this->assertSame($fkName, $schemaAttribute->fkName());
552
    }
553
554
    public function testItSchemaAttributeConstraintsAsString(): void
555
    {
556
        $name = 'foo';
557
        $dataType = 'string';
558
        $constraints = 'required|minlength:8|maxlength:10|mincheck:3|maxcheck:4|equalto:#bar|type:number';
559
560
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints);
561
562
        $this->assertEquals($name, $schemaAttribute->name());
563
        $this->assertEquals($dataType, $schemaAttribute->dataType());
564
        $this->assertEquals('string', $schemaAttribute->typeHint());
565
        $this->assertIsArray($schemaAttribute->constraints());
566
        $this->assertSame(true, $schemaAttribute->isRequired());
567
        $this->assertNull($schemaAttribute->min());
568
        $this->assertSame(8, $schemaAttribute->minLength());
569
        $this->assertSame(3, $schemaAttribute->minCheck());
570
        $this->assertNull($schemaAttribute->max());
571
        $this->assertSame(10, $schemaAttribute->maxLength());
572
        $this->assertSame(4, $schemaAttribute->maxCheck());
573
        $this->assertSame('#bar', $schemaAttribute->equalTo());
574
        $this->assertSame('number', $schemaAttribute->type());
575
        $this->assertFalse($schemaAttribute->isPk());
576
        $this->assertFalse($schemaAttribute->isAi());
577
        $this->assertFalse($schemaAttribute->isFk());
578
        $this->assertNull($schemaAttribute->fkTable());
579
        $this->assertNull($schemaAttribute->fkId());
580
        $this->assertNull($schemaAttribute->fkName());
581
    }
582
583
    public function testItSchemaAttributeConstraintsAsArray(): void
584
    {
585
        $name = 'foo';
586
        $dataType = 'integer';
587
        $constraints = [
588
            'required',
589
            'equalto' => '#id',
590
            'type' => 'text',
591
            'pk' => true,
592
            'ai' => true,
593
        ];
594
595
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints);
596
597
        $this->assertEquals($name, $schemaAttribute->name());
598
        $this->assertEquals($dataType, $schemaAttribute->dataType());
599
        $this->assertEquals('int', $schemaAttribute->typeHint());
600
        $this->assertIsArray($schemaAttribute->constraints());
601
        $this->assertSame(true, $schemaAttribute->isRequired());
602
        $this->assertNull($schemaAttribute->min());
603
        $this->assertNull($schemaAttribute->minLength());
604
        $this->assertNull($schemaAttribute->minCheck());
605
        $this->assertNull($schemaAttribute->max());
606
        $this->assertNull($schemaAttribute->maxLength());
607
        $this->assertNull($schemaAttribute->maxCheck());
608
        $this->assertSame('#id', $schemaAttribute->equalTo());
609
        $this->assertSame('text', $schemaAttribute->type());
610
        $this->assertTrue($schemaAttribute->isPk());
611
        $this->assertTrue($schemaAttribute->isAi());
612
        $this->assertFalse($schemaAttribute->isFk());
613
    }
614
615
    public function testItSchemaAttributeConstraintsAsArrayCast(): void
616
    {
617
        $name = 'foo';
618
        $dataType = 'datetime';
619
        $constraints = [
620
            'required',
621
            'equalto' => '#bar',
622
            'type' => 'number',
623
        ];
624
625
        $schemaAttribute = new SchemaAttribute($name, $dataType, $constraints);
626
627
        $this->assertEquals($name, $schemaAttribute->name());
628
        $this->assertEquals($dataType, $schemaAttribute->dataType());
629
        $this->assertEquals('\DateTime', $schemaAttribute->typeHint());
630
        $this->assertIsArray($schemaAttribute->constraints());
631
        $this->assertSame(true, $schemaAttribute->isRequired());
632
        $this->assertNull($schemaAttribute->min());
633
        $this->assertNull($schemaAttribute->minLength());
634
        $this->assertNull($schemaAttribute->minCheck());
635
        $this->assertNull($schemaAttribute->max());
636
        $this->assertNull($schemaAttribute->maxLength());
637
        $this->assertNull($schemaAttribute->maxCheck());
638
        $this->assertSame('#bar', $schemaAttribute->equalTo());
639
        $this->assertSame('number', $schemaAttribute->type());
640
    }
641
642
    public function getRequiredConstraint(): array
643
    {
644
        return [
645
            ['', false],
646
            ['required', true],
647
            ['required:true', true],
648
            ['required:false', false],
649
            [['required'], true],
650
            [['required' => true], true],
651
            [['required' => false], false],
652
        ];
653
    }
654
655
    public function getMinLengthConstraint(): array
656
    {
657
        return [
658
            ['', null],
659
            ['minlength:8', 8],
660
            [['minlength' => 8], 8],
661
            [['minlength' => '8'], 8],
662
        ];
663
    }
664
665
    public function getMinConstraint(): array
666
    {
667
        return [
668
            ['', null],
669
            ['min:8', 8],
670
            [['min' => 8], 8],
671
            [['min' => '8'], 8],
672
        ];
673
    }
674
675
    public function getMaxLengthConstraint(): array
676
    {
677
        return [
678
            ['', null],
679
            ['maxlength:10', 10],
680
            [['maxlength' => 10], 10],
681
            [['maxlength' => '10'], 10],
682
        ];
683
    }
684
685
    public function getMaxConstraint(): array
686
    {
687
        return [
688
            ['', null],
689
            ['max:100', 100],
690
            [['max' => 100], 100],
691
            [['max' => '100'], 100],
692
        ];
693
    }
694
695
    public function getMinCheckConstraint(): array
696
    {
697
        return [
698
            ['', null],
699
            ['mincheck:3', 3],
700
            [['mincheck' => 3], 3],
701
            [['mincheck' => '3'], 3],
702
        ];
703
    }
704
705
    public function getMaxCheckConstraint(): array
706
    {
707
        return [
708
            ['', null],
709
            ['maxcheck:4', 4],
710
            [['maxcheck' => 4], 4],
711
            [['maxcheck' => '4'], 4],
712
        ];
713
    }
714
715
    public function getCheckConstraint(): array
716
    {
717
        return [
718
            ['', null, null],
719
            ['check:3,4', 3, 4],
720
            [['check' => [
721
                'min' => 5,
722
                'max' => 6,
723
            ]], 5, 6],
724
        ];
725
    }
726
727
    public function getLengthConstraint(): array
728
    {
729
        return [
730
            ['', null, null],
731
            ['length:30,40', 30, 40],
732
            [['length' => [
733
                'min' => 5,
734
                'max' => 60,
735
            ]], 5, 60],
736
        ];
737
    }
738
739
    public function getEqualToConstraint(): array
740
    {
741
        return [
742
            ['', null],
743
            ['equalto:#foo', '#foo'],
744
            [['equalto' => '.foo'], '.foo'],
745
        ];
746
    }
747
748
    public function getTypeConstraint(): array
749
    {
750
        return [
751
            ['', null],
752
            ['type:number', 'number'],
753
            [['type' => 'text'], 'text'],
754
        ];
755
    }
756
757
    public function getPkConstraint(): array
758
    {
759
        return [
760
            ['', false],
761
            ['required|pk', true],
762
            ['required|pk:true', true],
763
            ['required|pk:false', false],
764
            [['required', 'pk'], true],
765
            [['required', 'pk' => true], true],
766
            [['required', 'pk' => false], false],
767
        ];
768
    }
769
770
    public function getAiConstraint(): array
771
    {
772
        return [
773
            ['', false],
774
            ['required|pk|ai', true],
775
            ['required|pk|ai:true', true],
776
            [['required', 'pk', 'ai'], true],
777
            [['required', 'pk', 'ai' => true], true],
778
        ];
779
    }
780
781
    public function getCaConstraint(): array
782
    {
783
        return [
784
            ['', false],
785
            ['ca', true],
786
            ['ca:true', true],
787
            ['ca:false', false],
788
            [['ca'], true],
789
            [['ca' => true], true],
790
            [['ca' => false], false],
791
        ];
792
    }
793
794
    public function getUaConstraint(): array
795
    {
796
        return [
797
            ['', false],
798
            ['ua', true],
799
            ['ua:true', true],
800
            ['ua:false', false],
801
            [['ua'], true],
802
            [['ua' => true], true],
803
            [['ua' => false], false],
804
        ];
805
    }
806
807
    public function getFkConstraint(): array
808
    {
809
        return [
810
            ['fk:table', 'table', 'id', 'name'],
811
            ['fk:table2,username', 'table2', 'id', 'username'],
812
            ['fk:table3,description,uuid', 'table3', 'uuid', 'description'],
813
            [['fk' => 'table5'], 'table5', 'id', 'name'],
814
            [['fk' => 'table6,username'], 'table6', 'id', 'username'],
815
            [['fk' => 'table7,description,uuid'], 'table7', 'uuid', 'description'],
816
        ];
817
    }
818
819
    public function getCbConstraint(): array
820
    {
821
        return [
822
            ['', false],
823
            ['cb', true],
824
            ['cb:true', true],
825
            ['cb:false', false],
826
            [['cb'], true],
827
            [['cb' => true], true],
828
            [['cb' => false], false],
829
        ];
830
    }
831
832
    public function getUbConstraint(): array
833
    {
834
        return [
835
            ['', false],
836
            ['ub', true],
837
            ['ub:true', true],
838
            ['ub:false', false],
839
            [['ub'], true],
840
            [['ub' => true], true],
841
            [['ub' => false], false],
842
        ];
843
    }
844
845
    public function getFilterConstraint(): array
846
    {
847
        return [
848
            ['', null],
849
            ['filter:eq', 'eq'],
850
            ['filter:nn', 'nn'],
851
        ];
852
    }
853
854
    public function getFormatConstraint(): array
855
    {
856
        return [
857
            ['string', '', null],
858
            ['datetime', 'format:timeago', 'timeago'],
859
            ['datetime', 'format:datetime', 'datetime'],
860
            ['integer', 'format:money', 'money'],
861
        ];
862
    }
863
864
    public function getTrimConstraint(): array
865
    {
866
        return [
867
            ['', false],
868
            ['trim', true],
869
            ['trim:true', true],
870
            ['trim:false', false],
871
            [['trim'], true],
872
            [['trim' => true], true],
873
            [['trim' => false], false],
874
        ];
875
    }
876
877
    public function getFcharsConstraint(): array
878
    {
879
        return [
880
            ['', null],
881
            ['fchars:0', 0],
882
            ['fchars:1', 1],
883
            ['fchars:2', 2],
884
            ['fchars:90', 90],
885
        ];
886
    }
887
888
    public function getLinkConstraint(): array
889
    {
890
        return [
891
            ['', false],
892
            ['link', true],
893
            ['link:true', true],
894
            ['link:false', false],
895
            [['link'], true],
896
            [['link' => true], true],
897
            [['link' => false], false],
898
        ];
899
    }
900
901
    public function getFkCheckConstraint(): array
902
    {
903
        return [
904
            ['', false],
905
            ['fk:fkTable,fkName|fkcheck', true],
906
            ['fk:fkTable,fkName|fkcheck:true', true],
907
            ['fk:fkTable,fkName|fkcheck:false', false],
908
            [['fk' => 'fkTable,fkName', 'fkcheck'], true],
909
            [['fk' => 'fkTable,fkName', 'fkcheck' => true], true],
910
            [['fk' => 'fkTable,fkName', 'fkcheck' => false], false],
911
        ];
912
    }
913
914
    public function getShowConstraint(): array
915
    {
916
        return [
917
            ['string', '', Action::ALL],
918
            ['datetime', 'ca', Action::READ],
919
            ['integer', 'cb', Action::READ],
920
            ['datetime', 'ua', Action::READ],
921
            ['integer', 'ub', Action::READ],
922
            ['string', 'show:a', Action::ALL],
923
            ['string', 'show:i', Action::INDEX],
924
            ['string', 'show:c', Action::CREATE],
925
            ['string', 'show:r', Action::READ],
926
            ['string', 'show:u', Action::UPDATE],
927
            ['string', 'show:d', Action::DELETE],
928
            ['datetime', 'ca|show:a', Action::ALL],
929
            ['integer', 'cb|show:i', Action::INDEX],
930
            ['datetime', 'ua|show:c', Action::CREATE],
931
            ['integer', 'ub|show:r', Action::READ],
932
        ];
933
    }
934
935
    public function getHideConstraint(): array
936
    {
937
        return [
938
            ['string', '', '', false],
939
            ['datetime', 'ca', Action::ALL, false],
940
            ['datetime', 'ca', Action::INDEX, false],
941
            ['datetime', 'ca', Action::CREATE, false],
942
            ['datetime', 'ca', Action::READ, true],
943
            ['datetime', 'ca', Action::UPDATE, false],
944
            ['datetime', 'ca', Action::DELETE, false],
945
            ['integer', 'cb', Action::ALL, false],
946
            ['integer', 'cb', Action::INDEX, false],
947
            ['integer', 'cb', Action::CREATE, false],
948
            ['integer', 'cb', Action::READ, true],
949
            ['integer', 'cb', Action::UPDATE, false],
950
            ['integer', 'cb', Action::DELETE, false],
951
            ['string', 'hide:a', Action::ALL, false],
952
            ['string', 'hide:i', Action::INDEX, false],
953
            ['string', 'hide:c', Action::CREATE, false],
954
            ['string', 'hide:r', Action::READ, false],
955
            ['string', 'hide:u', Action::UPDATE, false],
956
            ['string', 'hide:d', Action::DELETE, false],
957
            ['datetime', 'ca|hide:r', Action::READ, false],
958
            ['integer', 'cb|hide:r', Action::READ, false],
959
            ['datetime', 'ua|hide:r', Action::READ, false],
960
            ['integer', 'ub|hide:r', Action::READ, false],
961
        ];
962
    }
963
964
    public function getDefaultConstraint(): array
965
    {
966
        return [
967
            ['string', '', null],
968
            ['string', 'default:', ''],
969
            ['string', 'default:A', 'A'],
970
            ['integer', 'default:-1', -1],
971
            ['double', 'default:0.0', 0.0],
972
            ['float', 'default:0.1', 0.1],
973
            ['datetime', 'default:NOW', 'NOW'],
974
        ];
975
    }
976
977
    public function getConstraintLogicError(): array
978
    {
979
        return [
980
            ['integer', 'pk|ai|required|min:10'],
981
            ['integer', 'pk|ai|required|fk:table'],
982
            ['integer', 'pk|required'],
983
            ['integer', 'ai'],
984
            ['integer', 'ai|pk'],
985
            ['string', 'ai|pk|required'],
986
            ['string', 'ca'],
987
            ['integer', 'ua'],
988
            ['datetime', 'ca|ua'],
989
            ['integer', 'fk:table|ai|pk|required'],
990
            ['integer', 'required:false|ai|pk'],
991
            ['integer', 'required:false|pk'],
992
            ['smallint', 'maxlength:100'],
993
            ['integer', 'maxlength:100'],
994
            ['bigint', 'maxlength:100'],
995
            ['double', 'maxlength:100'],
996
            ['float', 'maxlength:100'],
997
            ['smallint', 'minlength:10'],
998
            ['integer', 'minlength:10'],
999
            ['bigint', 'minlength:10'],
1000
            ['double', 'minlength:10'],
1001
            ['float', 'minlength:10'],
1002
            ['string', 'min:100'],
1003
            ['text', 'max:10'],
1004
            ['guid', 'min:10'],
1005
            ['binary', 'max:10'],
1006
            ['blob', 'maxlength:1'],
1007
            ['datetimetz', 'maxlength:1'],
1008
            ['time', 'mincheck:1'],
1009
            ['datetime', 'maxcheck:1'],
1010
            ['datetime', 'cb'],
1011
            ['bool', 'ub'],
1012
            ['binary', 'cb'],
1013
            ['blob', 'ub'],
1014
            ['integer', 'cb|ub'],
1015
            ['smallint', 'format:datetime'],
1016
            ['integer', 'format:datetime'],
1017
            ['float', 'format:datetime'],
1018
            ['double', 'format:datetime'],
1019
            ['blob', 'format:datetime'],
1020
            ['blob', 'format:money'],
1021
            ['blob', 'format:timeago'],
1022
            ['boolean', 'format:datetime'],
1023
            ['boolean', 'format:money'],
1024
            ['boolean', 'format:timeago'],
1025
            ['bool', 'format:datetime'],
1026
            ['bool', 'format:money'],
1027
            ['bool', 'format:timeago'],
1028
            ['datetime', 'format:money'],
1029
            ['datetime_immutable', 'format:money'],
1030
            ['datetimetz', 'format:money'],
1031
            ['datetimetz_immutable', 'format:money'],
1032
            ['time', 'format:money'],
1033
            ['time_immutable', 'format:money'],
1034
            ['array', 'format:money'],
1035
            ['array', 'format:datetime'],
1036
            ['array', 'format:timeago'],
1037
            ['simple_array', 'format:money'],
1038
            ['simple_array', 'format:datetime'],
1039
            ['simple_array', 'format:timeago'],
1040
            ['json', 'format:money'],
1041
            ['json', 'format:datetime'],
1042
            ['json', 'format:timeago'],
1043
            ['string', 'format:datetime'],
1044
            ['string', 'format:timeago'],
1045
            ['object', 'format:timeago'],
1046
            ['text', 'format:timeago'],
1047
            ['string', 'fchars:1'],
1048
            ['integer', 'fchars:2'],
1049
            ['datetime', 'fchars:3'],
1050
            ['bool', 'fchars:4'],
1051
            ['array', 'fchars:5'],
1052
            ['string', 'show|hide'],
1053
            ['string', 'show:a|hide'],
1054
            ['string', 'show|hide:a'],
1055
            ['string', 'show:a|hide:a'],
1056
            ['string', 'show:i|hide:i'],
1057
            ['string', 'show:c|hide:c'],
1058
            ['string', 'show:r|hide:r'],
1059
            ['string', 'show:u|hide:u'],
1060
            ['string', 'show:d|hide:d'],
1061
            ['string', 'show:i,d|hide:i,c'],
1062
            ['string', 'fkcheck'],
1063
            ['string', 'default:false'],
1064
            ['string', 'default:true'],
1065
            ['bool', 'default:ERROR'],
1066
            ['integer', 'default:ERROR'],
1067
            ['double', 'default:ERROR'],
1068
            ['date', 'default:ERROR'],
1069
            ['datetime', 'default:ERROR'],
1070
            ['text', 'default:ERROR'],
1071
            ['binary', 'default:ERROR'],
1072
            ['array', 'default:ERROR'],
1073
            ['simple_array', 'default:ERROR'],
1074
            ['json', 'default:ERROR'],
1075
            ['object', 'default:ERROR'],
1076
        ];
1077
    }
1078
}
1079