CronMinuteFormatValidatorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 75
loc 75
c 3
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createValidator() 4 4 1
A getValidValues() 15 15 1
A testValidValue() 6 6 1
A getInvalidValues() 16 16 1
A testInvalidValues() 8 8 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 Tests\FOA\CronBundle\Validator\Constraints;
4
5
use FOA\CronBundle\Validator\Constraints\CronMinuteFormat;
6
use FOA\CronBundle\Validator\Constraints\CronMinuteFormatValidator;
7
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
8
9
/**
10
 * @author JM Leroux <[email protected]>
11
 */
12 View Code Duplication
class CronMinuteFormatValidatorTest 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...
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected function createValidator()
18
    {
19
        return new CronMinuteFormatValidator();
20
    }
21
22
    /**
23
     * @return array
24
     */
25
    public function getValidValues()
26
    {
27
        return [
28
            [5],
29
            [0],
30
            [59],
31
            ['5,15'],
32
            ['5-15'],
33
            ['10-20,40-50'],
34
            ['5,15-20,30'],
35
            ['*/15'],
36
            ['*'],
37
            ['*,3,*/5'],
38
        ];
39
    }
40
41
    /**
42
     * @dataProvider getValidValues
43
     *
44
     * @param string $value
45
     */
46
    public function testValidValue($value)
47
    {
48
        $constraint = new CronMinuteFormat();
49
        $this->validator->validate($value, $constraint);
50
        $this->assertNoViolation();
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getInvalidValues()
57
    {
58
        return [
59
            [61],
60
            ['5,89'],
61
            ['95,9'],
62
            ['50-70'],
63
            ['-1'],
64
            ['1-'],
65
            ['25,50-70'],
66
            ['10-20,85'],
67
            ['10-20,50-65'],
68
            ['20/*'],
69
            ['**'],
70
        ];
71
    }
72
73
    /**
74
     * @dataProvider getInvalidValues
75
     *
76
     * @param string $value
77
     */
78
    public function testInvalidValues($value)
79
    {
80
        $constraint = new CronMinuteFormat();
81
        $this->validator->validate($value, $constraint);
82
        $this->buildViolation($constraint->message)
83
            ->setParameter('%string%', $value)
84
            ->assertRaised();
85
    }
86
}
87