Completed
Push — master ( e4e8e1...017c51 )
by Alexis
02:26
created

ValidatorExtensionTest::testGetErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Awurth\SlimValidation\Tests;
4
5
use Awurth\SlimValidation\Validator;
6
use Awurth\SlimValidation\ValidatorExtension;
7
use PHPUnit\Framework\TestCase;
8
9
class ValidatorExtensionTest extends TestCase
10
{
11
    /**
12
     * @var Validator
13
     */
14
    protected $validator;
15
16
    /**
17
     * @var ValidatorExtension
18
     */
19
    protected $validatorExtension;
20
21
    public function setUp()
22
    {
23
        $this->validator = new Validator();
24
25
        $this->validatorExtension = new ValidatorExtension($this->validator);
26
    }
27
28 View Code Duplication
    public function testGetError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $this->assertEquals('', $this->validatorExtension->getError('username'));
31
32
        $this->validator->addError('username', 'Bad username');
33
        $this->validator->addError('username', 'Too short!');
34
35
        $this->assertEquals('Bad username', $this->validatorExtension->getError('username'));
36
    }
37
38
    public function testGetErrors()
39
    {
40
        $this->assertEquals([], $this->validatorExtension->getErrors());
41
        $this->assertEquals([], $this->validatorExtension->getErrors('username'));
42
43
        $this->validator->addError('username', 'Bad username');
44
        $this->validator->addError('password', 'Wrong password');
45
46
        $this->assertEquals([
47
            'username' => ['Bad username'],
48
            'password' => ['Wrong password']
49
        ], $this->validatorExtension->getErrors());
50
51
        $this->assertEquals(['Bad username'], $this->validatorExtension->getErrors('username'));
52
    }
53
54
    public function testGetRuleError()
55
    {
56
        $this->assertEquals('', $this->validatorExtension->getRuleError('username', 'notBlank'));
57
58
        $this->validator->setErrors([
59
            'username' => [
60
                'length' => 'Too short!',
61
                'notBlank' => 'Required'
62
            ]
63
        ]);
64
65
        $this->assertEquals('Required', $this->validatorExtension->getRuleError('username', 'notBlank'));
66
    }
67
68 View Code Duplication
    public function testGetValue()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $this->assertEquals('', $this->validatorExtension->getValue('username'));
71
72
        $this->validator->setValues(['username' => 'awurth']);
73
74
        $this->assertEquals('awurth', $this->validatorExtension->getValue('username'));
75
    }
76
77
    public function testHasError()
78
    {
79
        $this->assertFalse($this->validatorExtension->hasError('username'));
80
81
        $this->validator->addError('username', 'Bad username');
82
83
        $this->assertTrue($this->validatorExtension->hasError('username'));
84
    }
85
86
    public function testHasErrors()
87
    {
88
        $this->assertFalse($this->validatorExtension->hasErrors());
89
90
        $this->validator->addError('username', 'Bad username');
91
92
        $this->assertTrue($this->validatorExtension->hasErrors());
93
    }
94
}
95