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
|
|
|
|