UnionTypeTest::testAcceptsNull()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
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\Metadata\Type;
6
7
use DateTimeImmutable;
8
use Doctrine\Annotations\Metadata\Type\IntegerType;
9
use Doctrine\Annotations\Metadata\Type\NullType;
10
use Doctrine\Annotations\Metadata\Type\ObjectType;
11
use Doctrine\Annotations\Metadata\Type\StringType;
12
use Doctrine\Annotations\Metadata\Type\Type;
13
use Doctrine\Annotations\Metadata\Type\UnionType;
14
use stdClass;
15
16
final class UnionTypeTest extends TypeTest
17
{
18
    protected function createType() : Type
19
    {
20
        return new UnionType(new IntegerType(), new ObjectType(stdClass::class), new NullType());
21
    }
22
23
    public function testDescribe() : void
24
    {
25
        self::assertSame('integer|stdClass|null', $this->getType()->describe());
26
    }
27
28
    /**
29
     * @return null[][]|object[][]|int[][]
30
     */
31
    public function validValidateValuesProvider() : iterable
32
    {
33
        yield [null];
0 ignored issues
show
Bug Best Practice introduced by
The expression yield array(null) returns the type Generator which is incompatible with the documented return type array<mixed,array<mixed,...|array<mixed,integer[]>.
Loading history...
34
        yield [new stdClass()];
35
        yield [123];
36
    }
37
38
    /**
39
     * @return mixed[][]
40
     */
41
    public function invalidValidateValuesProvider() : iterable
42
    {
43
        yield [true];
0 ignored issues
show
Bug Best Practice introduced by
The expression yield array(true) returns the type Generator which is incompatible with the documented return type array<mixed,array<mixed,mixed>>.
Loading history...
44
        yield [0.0];
45
        yield ['0'];
46
        yield [[0]];
47
        yield [new DateTimeImmutable()];
48
    }
49
50
    public function testAcceptsNull() : void
51
    {
52
        self::assertTrue($this->getType()->acceptsNull());
53
    }
54
55
    public function testNotAcceptsNullStoringNotNullAcceptingType() : void
56
    {
57
        $type = new UnionType(new StringType());
58
59
        self::assertFalse($type->acceptsNull());
60
    }
61
}
62