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

CNPJValidatorTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 8
lcom 1
cbo 3
dl 65
loc 65
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getApiVersion() 4 4 1
A createValidator() 4 4 1
A testNullIsValid() 5 5 1
A testEmptyStringIsValid() 5 5 1
A getInvalidCNPJs() 8 8 1
A testInvalidCNPJs() 10 10 1
A getValidCNPJs() 8 8 1
A testValidCNPJs() 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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