CommandTestCase   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValidator() 0 4 1
A validateAndCheckIfErrorExists() 0 4 1
A getInvalidPropertyNames() 0 8 2
A assertPropertyInvalid() 0 4 1
A assertPropertyValid() 0 4 1
1
<?php
2
3
namespace Tactics\CommandBusBundle\Tests\Command;
4
5
use Symfony\Component\Validator\Validation;
6
use Tactics\CommandBusBundle\Command\Command;
7
8
class CommandTestCase extends \PHPUnit_Framework_TestCase
9
{
10
    protected function getValidator()
11
    {
12
        return Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
13
    }
14
15
    protected function validateAndCheckIfErrorExists(Command $command, $propertyName)
16
    {
17
        return in_array($propertyName, $this->getInvalidPropertyNames($this->getValidator()->validate($command)));
18
    }
19
20
    protected function getInvalidPropertyNames($constraintViolationList)
21
    {
22
        $invalidPropertyNames = array();
23
        foreach ($constraintViolationList as $constraintViolation) {
24
            $invalidPropertyNames[] = $constraintViolation->getPropertyPath();
25
        }
26
        return $invalidPropertyNames;
27
    }
28
29
    public function assertPropertyInvalid(Command $command, $propertyName)
30
    {
31
        $this->assertTrue($this->validateAndCheckIfErrorExists($command, $propertyName));
32
    }
33
34
    public function assertPropertyValid(Command $command, $propertyName)
35
    {
36
        $this->assertFalse($this->validateAndCheckIfErrorExists($command, $propertyName));
37
    }
38
}