Passed
Pull Request — master (#360)
by Valentin
04:12
created

MessagesTest::testWithData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Validation;
13
14
class MessagesTest extends BaseTest
15
{
16
    public function testDefault(): void
17
    {
18
        $validator = $this->validation->validate([], ['name' => ['type::notEmpty']]);
19
        $this->assertSame(['name' => 'This value is required.'], $validator->getErrors());
20
    }
21
22
    public function testWithData(): void
23
    {
24
        $validator = $this->validation->validate([], ['name' => ['type::notEmpty']]);
25
        $this->assertSame(['name' => 'This value is required.'], $validator->getErrors());
26
27
        $validator = $validator->withData([]);
28
        $this->assertSame(['name' => 'This value is required.'], $validator->getErrors());
29
30
        $validator = $validator->withData(['name' => 'John']);
31
        $this->assertEmpty($validator->getErrors());
32
    }
33
34
    public function testMessage(): void
35
    {
36
        $validator = $this->validation->validate([], [
37
            'name' => [
38
                ['type::notEmpty', 'message' => 'Value is empty.']
39
            ]
40
        ]);
41
        $this->assertSame(['name' => 'Value is empty.'], $validator->getErrors());
42
    }
43
44
    public function testMsg(): void
45
    {
46
        $validator = $this->validation->validate([], [
47
            'name' => [
48
                ['type::notEmpty', 'msg' => 'Value is empty.']
49
            ]
50
        ]);
51
        $this->assertSame(['name' => 'Value is empty.'], $validator->getErrors());
52
    }
53
54
    public function testError(): void
55
    {
56
        $validator = $this->validation->validate([], [
57
            'name' => [
58
                ['type::notEmpty', 'error' => 'Value is empty.']
59
            ]
60
        ]);
61
        $this->assertSame(['name' => 'Value is empty.'], $validator->getErrors());
62
    }
63
64
    public function testErr(): void
65
    {
66
        $validator = $this->validation->validate([], [
67
            'name' => [
68
                ['type::notEmpty', 'err' => 'Value is empty.']
69
            ]
70
        ]);
71
        $this->assertSame(['name' => 'Value is empty.'], $validator->getErrors());
72
    }
73
}
74