testInvalidValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace Tests\FOA\CronBundle\Validator\Constraints;
4
5
use FOA\CronBundle\Validator\Constraints\CronDayOfWeekFormat;
6
use FOA\CronBundle\Validator\Constraints\CronDayOfWeekFormatValidator;
7
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
8
9
/**
10
 * @author JM Leroux <[email protected]>
11
 */
12 View Code Duplication
class CronDayOfWeekFormatValidatorTest 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 CronDayOfWeekFormatValidator();
20
    }
21
22
    /**
23
     * @return array
24
     */
25
    public function getValidValues()
26
    {
27
        return [
28
            [0],
29
            [1],
30
            [7],
31
            ['2,4'],
32
            ['0-5'],
33
            ['1-2,4-6'],
34
            ['1,3-5'],
35
            ['*/3'],
36
            ['*'],
37
            ['*,2,*/5'],
38
        ];
39
    }
40
41
    /**
42
     * @dataProvider getValidValues
43
     *
44
     * @param string $value
45
     */
46
    public function testValidValue($value)
47
    {
48
        $constraint = new CronDayOfWeekFormat();
49
        $this->validator->validate($value, $constraint);
50
        $this->assertNoViolation();
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getInvalidValues()
57
    {
58
        return [
59
            [-1],
60
            [8],
61
            ['5,9'],
62
            ['3-10'],
63
            ['-1'],
64
            ['1-'],
65
            ['3,4-10'],
66
            ['1-3,5-10'],
67
            ['5/*'],
68
            ['2-3,5/*'],
69
            ['**'],
70
        ];
71
    }
72
73
    /**
74
     * @dataProvider getInvalidValues
75
     *
76
     * @param string $value
77
     */
78
    public function testInvalidValues($value)
79
    {
80
        $constraint = new CronDayOfWeekFormat();
81
        $this->validator->validate($value, $constraint);
82
        $this->buildViolation($constraint->message)
83
            ->setParameter('%string%', $value)
84
            ->assertRaised();
85
    }
86
}
87