ValidatorTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setUp() 0 4 1
A testContainerRegistration() 0 4 1
A testValidation() 0 14 1
1
<?php
2
3
namespace Symnedi\Validator\Tests;
4
5
use Nette\DI\Container;
6
use PHPUnit_Framework_TestCase;
7
use Symfony\Component\Validator\ConstraintViolation;
8
use Symfony\Component\Validator\ConstraintViolationList;
9
use Symfony\Component\Validator\Validator\RecursiveValidator;
10
use Symfony\Component\Validator\Validator\ValidatorInterface;
11
use Symnedi\Validator\Tests\ValidatorSource\SomeEntity;
12
13
14
class ValidatorTest extends PHPUnit_Framework_TestCase
15
{
16
17
	/**
18
	 * @var Container
19
	 */
20
	private $container;
21
22
	/**
23
	 * @var ValidatorInterface
24
	 */
25
	private $validator;
26
27
28
	public function __construct()
29
	{
30
		$this->container = (new ContainerFactory)->create();
31
	}
32
33
34
	protected function setUp()
35
	{
36
		$this->validator = $this->container->getByType(ValidatorInterface::class);
37
	}
38
39
40
	public function testContainerRegistration()
41
	{
42
		$this->assertInstanceOf(RecursiveValidator::class, $this->validator);
43
	}
44
45
46
	public function testValidation()
47
	{
48
		$violations = $this->validator->validate(new SomeEntity);
49
		$this->assertCount(2, $violations);
50
		$this->assertInstanceOf(ConstraintViolationList::class, $violations);
51
52
		$violation = $violations[0];
53
		$this->assertInstanceOf(ConstraintViolation::class, $violation);
54
		$this->assertSame('This value should not be blank.', $violation->getMessage());
55
56
		$violation = $violations[1];
57
		$this->assertInstanceOf(ConstraintViolation::class, $violation);
58
		$this->assertSame('This value should not be blank.', $violation->getMessage());
59
	}
60
61
}
62