Completed
Push — develop ( dc8379...716e11 )
by Alexandr
9s
created

CronDayOfWeekFormatValidatorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createValidator() 4 4 1
A getValidValues() 8 8 1
A testValidValue() 6 6 1
A getInvalidValues() 7 7 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\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
        ];
32
    }
33
34
    /**
35
     * @dataProvider getValidValues
36
     *
37
     * @param string $value
38
     */
39
    public function testValidValue($value)
40
    {
41
        $constraint = new CronDayOfWeekFormat();
42
        $this->validator->validate($value, $constraint);
43
        $this->assertNoViolation();
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    public function getInvalidValues()
50
    {
51
        return [
52
            [-1],
53
            [8],
54
        ];
55
    }
56
57
    /**
58
     * @dataProvider getInvalidValues
59
     *
60
     * @param string $value
61
     */
62
    public function testInvalidValues($value)
63
    {
64
        $constraint = new CronDayOfWeekFormat();
65
        $this->validator->validate($value, $constraint);
66
        $this->buildViolation($constraint->message)
67
            ->setParameter('%string%', $value)
68
            ->assertRaised();
69
    }
70
}
71