Completed
Push — master ( a06a95...a1d542 )
by dan
15s
created

CropFocusCoordinatesValidatorTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 45.59 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 31
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 19 1
A createValidator() 0 4 1
A testValidCoordinates() 0 6 1
A testNullIsInValid() 10 10 1
A testFocusIsLargerThanCrop() 10 10 1
A testNoFocusIsSet() 11 11 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
 * This file is part of the IrishDan\ResponsiveImageBundle package.
4
 *
5
 * (c) Daniel Byrne <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source
8
 * code.
9
 */
10
11
namespace IrishDan\ResponsiveImageBundle\Tests\Validator\Constraints;
12
13
14
use IrishDan\ResponsiveImageBundle\Validator\Constraints\CropFocusCoordinates;
15
use IrishDan\ResponsiveImageBundle\Validator\Constraints\CropFocusCoordinatesValidator;
16
use Symfony\Component\Validator\Constraints\NotNull;
17
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
18
19
class CropFocusCoordinatesValidatorTest extends ConstraintValidatorTestCase
20
{
21
    protected function setUp()
22
    {
23
        $this->group        = 'MyGroup';
24
        $this->metadata     = null;
25
        $this->object       = null;
26
        $this->value        = 'InvalidValue';
27
        $this->root         = 'root';
28
        $this->propertyPath = 'property.path';
29
30
        // Initialize the context with some constraint so that we can
31
        // successfully build a violation.
32
        $this->constraint = new NotNull();
33
34
        $this->context   = $this->createContext();
35
        $this->validator = $this->createValidator();
36
        $this->validator->initialize($this->context);
37
38
        $this->setDefaultTimezone('UTC');
39
    }
40
41
    protected function createValidator()
42
    {
43
        return new CropFocusCoordinatesValidator();
44
    }
45
46
    public function testValidCoordinates()
47
    {
48
        $this->validator->validate('10, 20, 80, 90: 11, 21, 79, 90', new CropFocusCoordinates());
49
50
        $this->assertNoViolation();
51
    }
52
53 View Code Duplication
    public function testNullIsInValid()
0 ignored issues
show
Duplication introduced by
This method 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...
54
    {
55
        $this->validator->validate(null, new CropFocusCoordinates());
56
57
        $this->assertSame(
58
            1,
59
            $violationsCount = count($this->context->getViolations()),
60
            sprintf('0 violation expected. Got %u.', $violationsCount)
61
        );
62
    }
63
64 View Code Duplication
    public function testFocusIsLargerThanCrop()
0 ignored issues
show
Duplication introduced by
This method 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...
65
    {
66
        $this->validator->validate('10, 20, 80, 90: 9, 21, 79, 90', new CropFocusCoordinates());
67
68
        $this->assertSame(
69
            1,
70
            $violationsCount = count($this->context->getViolations()),
71
            sprintf('0 violation expected. Got %u.', $violationsCount)
72
        );
73
    }
74
75 View Code Duplication
    public function testNoFocusIsSet()
0 ignored issues
show
Duplication introduced by
This method 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...
76
    {
77
        // @TODO: We need to allow for no focus to be set
78
        $this->validator->validate('10, 20, 80, 90:', new CropFocusCoordinates());
79
80
        $this->assertSame(
81
            1,
82
            $violationsCount = count($this->context->getViolations()),
83
            sprintf('0 violation expected. Got %u.', $violationsCount)
84
        );
85
    }
86
}