Passed
Pull Request — new-parser-ast-metadata (#2)
by
unknown
02:09
created

ValueValidatorTest::invalidExamples()   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\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
     * @param mixed $value
27
     *
28
     * @dataProvider validExamples
29
     */
30
    public function testValidate(PropertyMetadata $propertyMetadata, $value) : void
31
    {
32
        $this->validator->validate(AnnotationMetadataMother::example(), $propertyMetadata, $value);
33
34
        $this->assertTrue(true);
35
    }
36
37
    /**
38
     * @return mixed[]
39
     */
40
    public function validExamples() : iterable
41
    {
42
        yield 'valid string' => [
0 ignored issues
show
Bug Best Practice introduced by
The expression yield 'valid string' => ...e\StringType()), 'foo') returns the type Generator which is incompatible with the documented return type array<mixed,mixed>.
Loading history...
43
            PropertyMetadataMother::withType(new StringType()),
44
            'foo',
45
        ];
46
    }
47
48
    /**
49
     * @param mixed $value
50
     *
51
     * @dataProvider invalidExamples
52
     */
53
    public function testNotValidatesInvalidExamplesAndThrows(PropertyMetadata $propertyMetadata, $value) : void
54
    {
55
        $this->expectException(InvalidValue::class);
56
57
        $this->validator->validate(AnnotationMetadataMother::example(), $propertyMetadata, $value);
58
    }
59
60
    /**
61
     * @return mixed[]
62
     */
63
    public function invalidExamples() : iterable
64
    {
65
        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...
66
            PropertyMetadataMother::withType(new StringType()),
67
            42,
68
        ];
69
    }
70
}
71