Completed
Push — master ( 810e98...a03780 )
by Rafael
16:20
created

CNPJValidatorTest::getInvalidCNPJs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %
Metric Value
dl 8
loc 8
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Mero\BaseBundle\Tests\Validator\Constraints;
4
5
use Mero\BaseBundle\Validator\Constraints\CNPJ;
6
use Mero\BaseBundle\Validator\Constraints\CNPJValidator;
7
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
8
use Symfony\Component\Validator\Validation;
9
10 View Code Duplication
class CNPJValidatorTest extends AbstractConstraintValidatorTest
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    protected function getApiVersion()
13
    {
14
        return Validation::API_VERSION_2_5;
15
    }
16
17
    protected function createValidator()
18
    {
19
        return new CNPJValidator();
20
    }
21
22
    public function testNullIsValid()
23
    {
24
        $this->validator->validate(null, new CNPJ());
25
        $this->assertNoViolation();
26
    }
27
28
    public function testEmptyStringIsValid()
29
    {
30
        $this->validator->validate('', new CNPJ());
31
        $this->assertNoViolation();
32
    }
33
34
    public function getInvalidCNPJs()
35
    {
36
        return array(
37
            array('11.111.111/1111-11'),
38
            array('22.222.222/2222-22'),
39
            array('66.121.538/0001-00'),
40
        );
41
    }
42
43
    /**
44
     * @dataProvider getInvalidCNPJs
45
     */
46
    public function testInvalidCNPJs($cnpj)
47
    {
48
        $constraint = new CNPJ(array(
49
            'message' => 'testMessage',
50
        ));
51
        $this->validator->validate($cnpj, $constraint);
52
        $this->buildViolation('testMessage')
53
            ->setParameter('{{ value }}', '"'.$cnpj.'"')
54
            ->assertRaised();
55
    }
56
57
    public function getValidCNPJs()
58
    {
59
        return array(
60
            array('06.785.165/0001-00'),
61
            array('66.121.538/0001-62'),
62
            array('32.771.783/0001-01'),
63
        );
64
    }
65
66
    /**
67
     * @dataProvider getValidCNPJs
68
     */
69
    public function testValidCNPJs($cnpj)
70
    {
71
        $this->validator->validate($cnpj, new CNPJ());
72
        $this->assertNoViolation();
73
    }
74
}
75