1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\Annotations\Assembler\Validator; |
6
|
|
|
|
7
|
|
|
use Doctrine\Annotations\Assembler\Validator\Exception\InvalidValue; |
8
|
|
|
use Doctrine\Annotations\Assembler\Validator\ValueValidator; |
9
|
|
|
use Doctrine\Annotations\Metadata\PropertyMetadata; |
10
|
|
|
use Doctrine\Annotations\Metadata\Type\StringType; |
11
|
|
|
use Doctrine\Tests\Annotations\Metadata\AnnotationMetadataMother; |
12
|
|
|
use Doctrine\Tests\Annotations\Metadata\Type\PropertyMetadataMother; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
class ValueValidatorTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** @var ValueValidator */ |
18
|
|
|
private $validator; |
19
|
|
|
|
20
|
|
|
protected function setUp() : void |
21
|
|
|
{ |
22
|
|
|
$this->validator = new ValueValidator(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @dataProvider validExamples |
27
|
|
|
*/ |
28
|
|
|
public function testValidates(PropertyMetadata $propertyMetadata, $value) : void |
29
|
|
|
{ |
30
|
|
|
$this->validator->validate(AnnotationMetadataMother::example(), $propertyMetadata, $value); |
31
|
|
|
|
32
|
|
|
$this->assertTrue(true); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function validExamples() : iterable |
36
|
|
|
{ |
37
|
|
|
yield 'valid string' => [ |
38
|
|
|
PropertyMetadataMother::withType(new StringType()), |
39
|
|
|
'foo', |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @dataProvider invalidExamples |
45
|
|
|
*/ |
46
|
|
|
public function testNotValidatesInvalidExamplesAndThrows(PropertyMetadata $propertyMetadata, $value) : void |
47
|
|
|
{ |
48
|
|
|
$this->expectException(InvalidValue::class); |
49
|
|
|
|
50
|
|
|
$this->validator->validate(AnnotationMetadataMother::example(), $propertyMetadata, $value); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function invalidExamples() : iterable |
54
|
|
|
{ |
55
|
|
|
yield 'value not matching property type' => [ |
56
|
|
|
PropertyMetadataMother::withType(new StringType()), |
57
|
|
|
42, |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|