Completed
Pull Request — master (#294)
by
unknown
03:26
created

ValidatorStepTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testProcess() 0 22 1
A testPriority() 0 4 1
A setUp() 0 8 1
A testProcessWithExceptions() 0 21 1
1
<?php
2
3
namespace Ddeboer\DataImport\Tests\Step;
4
5
use Ddeboer\DataImport\Step\ValidatorStep;
6
use Symfony\Component\Validator\Constraints;
7
use Symfony\Component\Validator\ConstraintViolationList;
8
9
class ValidatorStepTest extends \PHPUnit_Framework_TestCase
10
{
11
    protected function setUp()
12
    {
13
        $this->validator = $this->getMockBuilder('Symfony\Component\Validator\Validator')
14
            ->disableOriginalConstructor()
15
            ->getMock();
16
17
        $this->filter = new ValidatorStep($this->validator);
18
    }
19
20
    public function testProcess()
21
    {
22
        $data = [
23
            'title' => null,
24
        ];
25
26
        $this->filter->add('title', $constraint = new Constraints\NotNull());
27
28
        $this->validator->expects($this->once())
29
            ->method('validateValue')
30
            ->will($this->returnValue(
31
                $list = new ConstraintViolationList([
32
                    $this->getMockBuilder('Symfony\Component\Validator\ConstraintViolation')
33
                        ->disableOriginalConstructor()
34
                        ->getMock()
35
                ])
36
            ));
37
38
        $this->assertFalse($this->filter->process($data));
39
40
        $this->assertEquals([1 => $list], $this->filter->getViolations());
41
    }
42
43
    /**
44
     * @expectedException Ddeboer\DataImport\Exception\ValidationException
45
     */
46
    public function testProcessWithExceptions()
47
    {
48
        $data = [
49
            'title' => null,
50
        ];
51
52
        $this->filter->add('title', $constraint = new Constraints\NotNull());
53
        $this->filter->throwExceptions();
54
55
        $this->validator->expects($this->once())
56
        ->method('validateValue')
57
        ->will($this->returnValue(
58
        $list = new ConstraintViolationList([
59
            $this->getMockBuilder('Symfony\Component\Validator\ConstraintViolation')
60
            ->disableOriginalConstructor()
61
            ->getMock()
62
            ])
63
        ));
64
65
        $this->assertFalse($this->filter->process($data));
66
    }
67
68
    public function testPriority()
69
    {
70
        $this->assertEquals(128, $this->filter->getPriority());
71
    }
72
}
73