Failed Conditions
Pull Request — new-parser-ast-metadata (#3)
by
unknown
02:14
created

ValueValidatorTest::validExamples()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\Annotations\Assembler\Validator;
6
7
use Doctrine\Annotations\Assembler\Validator\Exception\InvalidPropertyValue;
8
use Doctrine\Annotations\Assembler\Validator\ValueValidator;
9
use Doctrine\Annotations\Metadata\Type\StringType;
10
use Doctrine\Annotations\Metadata\Type\Type;
11
use Doctrine\Tests\Annotations\Metadata\Type\PropertyMetadataMother;
12
use PHPUnit\Framework\TestCase;
13
14
final class ValueValidatorTest extends TestCase
15
{
16
    /** @var ValueValidator */
17
    private $validator;
18
19
    protected function setUp() : void
20
    {
21
        $this->validator = new ValueValidator();
22
    }
23
24
    /**
25
     * @param mixed $value
26
     *
27
     * @dataProvider validTypeValidationProvider
28
     */
29
    public function testValidatesValuesMatchingType(Type $type, $value) : void
30
    {
31
        $metadata = PropertyMetadataMother::withType($type);
32
33
        $this->validator->validate($metadata, $value);
34
35
        self::assertTrue(true);
36
    }
37
38
    /**
39
     * @return mixed[]
40
     */
41
    public function validTypeValidationProvider() : iterable
42
    {
43
        yield 'valid string' => [
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'valid string' => ...pe\StringType(), 'foo') returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
44
            new StringType(),
45
            'foo',
46
        ];
47
    }
48
49
    /**
50
     * @param mixed $value
51
     *
52
     * @dataProvider invalidTypeValidationProvider
53
     */
54
    public function testNotValidatesValuesNotMatchingTypeAndThrows(Type $type, $value) : void
55
    {
56
        $metadata = PropertyMetadataMother::withType($type);
57
58
        $this->expectException(InvalidPropertyValue::class);
59
60
        $this->validator->validate($metadata, $value);
61
    }
62
63
    /**
64
     * @return mixed[]
65
     */
66
    public function invalidTypeValidationProvider() : iterable
67
    {
68
        yield 'value not matching property type' => [
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'value not matchin...\Type\StringType(), 42) returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
69
            new StringType(),
70
            42,
71
        ];
72
    }
73
}
74