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

testValidatesValuesMatchingType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
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\Metadata;
6
7
use Doctrine\Annotations\Metadata\InvalidPropertyValue;
8
use Doctrine\Annotations\Metadata\Type\StringType;
9
use Doctrine\Annotations\Metadata\Type\Type;
10
use Doctrine\Tests\Annotations\Metadata\Type\PropertyMetadataMother;
11
use PHPUnit\Framework\TestCase;
12
13
class PropertyMetadataTest extends TestCase
14
{
15
    /**
16
     * @param mixed $value
17
     *
18
     * @dataProvider validTypeValidationExamples
19
     */
20
    public function testValidatesValuesMatchingType(Type $type, $value) : void
21
    {
22
        $metadata = PropertyMetadataMother::withType($type);
23
24
        $metadata->validateValue($value);
25
26
        $this->assertTrue(true);
27
    }
28
29
    /**
30
     * @return mixed[]
31
     */
32
    public function validTypeValidationExamples() : iterable
33
    {
34
        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...
35
            new StringType(),
36
            'foo',
37
        ];
38
    }
39
40
    /**
41
     * @param mixed $value
42
     *
43
     * @dataProvider invalidTypeValidationExamples
44
     */
45
    public function testNotValidatesValuesNotMatchingTypeAndThrows(Type $type, $value) : void
46
    {
47
        $metadata = PropertyMetadataMother::withType($type);
48
49
        $this->expectException(InvalidPropertyValue::class);
50
51
        $metadata->validateValue($value);
52
    }
53
54
    /**
55
     * @return mixed[]
56
     */
57
    public function invalidTypeValidationExamples() : iterable
58
    {
59
        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...
60
            new StringType(),
61
            42,
62
        ];
63
    }
64
}
65