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

TypeConstraintTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 19
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidatesValueMatchingType() 0 7 1
A testValidatesValueNotMatchingTypeAndThrows() 0 7 1
A matchingProvider() 0 10 1
A notMatchingProvider() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\Annotations\Metadata\Constraint;
6
7
use Doctrine\Annotations\Annotation;
8
use Doctrine\Annotations\Assembler\Validator\Constraint\Exception\ConstraintNotFulfilled;
9
use Doctrine\Annotations\Assembler\Validator\Constraint\TypeConstraint;
10
use Doctrine\Annotations\Metadata\Type\ObjectType;
11
use Doctrine\Annotations\Metadata\Type\StringType;
12
use Doctrine\Annotations\Metadata\Type\Type;
13
use Doctrine\Tests\Annotations\Fixtures\AnnotationTargetAll;
14
use PHPUnit\Framework\TestCase;
15
16
final class TypeConstraintTest extends TestCase
17
{
18
    /**
19
     * @param mixed $value
20
     *
21
     * @dataProvider matchingProvider
22
     */
23
    public function testValidatesValueMatchingType(Type $type, $value) : void
24
    {
25
        $constraint = new TypeConstraint($type);
26
27
        $constraint->validate($value);
28
29
        self::assertTrue(true);
30
    }
31
32
    /**
33
     * @return mixed[]
34
     */
35
    public function matchingProvider() : iterable
36
    {
37
        yield 'a string' => [
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'a string' => arra...pe\StringType(), 'foo') returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
38
            new StringType(),
39
            'foo',
40
        ];
41
42
        yield 'an object' => [
43
            new ObjectType(Annotation::class),
44
            new Annotation([]),
45
        ];
46
    }
47
48
    /**
49
     * @param mixed $value
50
     *
51
     * @dataProvider notMatchingProvider
52
     */
53
    public function testValidatesValueNotMatchingTypeAndThrows(Type $type, $value) : void
54
    {
55
        $constraint = new TypeConstraint($type);
56
57
        $this->expectException(ConstraintNotFulfilled::class);
58
59
        $constraint->validate($value);
60
    }
61
62
    /**
63
     * @return mixed[]
64
     */
65
    public function notMatchingProvider() : iterable
66
    {
67
        yield 'not a string' => [
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'not a string' => ...\Type\StringType(), 42) returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
68
            new StringType(),
69
            42,
70
        ];
71
72
        yield 'a different object' => [
73
            new ObjectType(AnnotationTargetAll::class),
74
            new Annotation([]),
75
        ];
76
    }
77
}
78