ValidatorValidationTest::testGetViolations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Mathielen\ImportEngine\Validation;
3
4
use Symfony\Component\Validator\Constraints\Email;
5
use Mathielen\DataImport\Filter\ValidatorFilter;
6
use Symfony\Component\Validator\Constraints\NotNull;
7
8
class ValidatorValidationTest extends \PHPUnit_Framework_TestCase
9
{
10
11
    /**
12
     * @var ValidatorValidation
13
     */
14
    private $validatorValidation;
15
16
    protected function setUp()
17
    {
18
        $this->validatorMock = $this->createMock('Symfony\Component\Validator\Validator\ValidatorInterface');
19
20
        $this->validatorValidation = ValidatorValidation::build($this->validatorMock);
21
    }
22
23
    public function testApply()
24
    {
25
        $this->validatorValidation->addSourceConstraint('sourceField', new Email());
26
        $this->validatorValidation->addTargetConstraint('targetField', new NotNull());
27
28
        $expectedSourceFilter = new ValidatorFilter($this->validatorMock);
29
        $expectedSourceFilter->setAllowExtraFields(true);
30
        $expectedSourceFilter->add('sourceField', new Email());
31
32
        $expectedTargetFilter = new ValidatorFilter($this->validatorMock);
33
        $expectedTargetFilter->setAllowExtraFields(true);
34
        $expectedTargetFilter->add('targetField', new NotNull());
35
36
        $workflow = $this->getMockBuilder('Ddeboer\DataImport\Workflow')->disableOriginalConstructor()->getMock();
37
        $workflow
38
            ->expects($this->once())
39
            ->method('addFilter')
40
            ->with($expectedSourceFilter);
41
        $workflow
42
            ->expects($this->once())
43
            ->method('addFilterAfterConversion')
44
            ->with($expectedTargetFilter);
45
46
        $this->validatorValidation->apply($workflow);
47
    }
48
49
    public function testGetViolations()
50
    {
51
        $sourceFilterMock = $this->getMockBuilder('Mathielen\DataImport\Filter\ValidatorFilter')->disableOriginalConstructor()->getMock();
52
        $sourceFilterMock
53
            ->expects($this->once())
54
            ->method('getViolations')
55
            ->will($this->returnValue('sourceViolation'));
56
57
        $targetFilterMock = $this->getMockBuilder('Mathielen\DataImport\Filter\ValidatorFilter')->disableOriginalConstructor()->getMock();
58
        $targetFilterMock
59
            ->expects($this->once())
60
            ->method('getViolations')
61
            ->will($this->returnValue('targetViolation'));
62
63
        $this->validatorValidation->setSourceValidatorFilter($sourceFilterMock);
64
        $this->validatorValidation->setTargetValidatorFilter($targetFilterMock);
65
66
        $workflow = $this->getMockBuilder('Ddeboer\DataImport\Workflow')->disableOriginalConstructor()->getMock();
0 ignored issues
show
Unused Code introduced by
$workflow is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
67
        $this->assertEquals(
68
            array('source' => 'sourceViolation', 'target' => 'targetViolation'),
69
            $this->validatorValidation->getViolations()
70
        );
71
    }
72
73
}
74