Failed Conditions
Pull Request — new-parser-ast-metadata (#2)
by
unknown
01:43
created

ValueValidatorTest::testValidates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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