Failed Conditions
Push — metadata ( 75cc1c...c6c11e )
by Michael
01:50
created

AnnotationMetadataBuilderTest::testDefaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
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\Builder;
6
7
use Doctrine\Annotations\Metadata\AnnotationTarget;
8
use Doctrine\Annotations\Metadata\Builder\AnnotationMetadataBuilder;
9
use Doctrine\Annotations\Metadata\PropertyMetadata;
10
use PHPUnit\Framework\TestCase;
11
12
final class AnnotationMetadataBuilderTest extends TestCase
13
{
14
    public function testDefaults() : void
15
    {
16
        $metadata = (new AnnotationMetadataBuilder('Foo'))->build();
17
18
        self::assertSame('Foo', $metadata->getName());
19
        self::assertSame(AnnotationTarget::TARGET_ALL, $metadata->getTarget()->unwrap());
20
        self::assertFalse($metadata->usesConstructor());
21
        self::assertSame([], $metadata->getProperties());
22
        self::assertNull($metadata->getDefaultProperty());
23
    }
24
25
    public function testBuilding() : void
26
    {
27
        $propertyA = new PropertyMetadata('a', ['type' => 'string'], true, true);
28
        $propertyB = new PropertyMetadata('b', ['type' => 'boolean']);
29
30
        $metadata = (new AnnotationMetadataBuilder('Foo'))
31
            ->withTarget(AnnotationTarget::class())
32
            ->withUsingConstructor()
33
            ->withProperty($propertyA)
34
            ->withProperty($propertyB)
35
            ->build();
36
37
        self::assertSame('Foo', $metadata->getName());
38
        self::assertSame(AnnotationTarget::TARGET_CLASS, $metadata->getTarget()->unwrap());
39
        self::assertTrue($metadata->usesConstructor());
40
        self::assertSame(['a' => $propertyA, 'b' => $propertyB], $metadata->getProperties());
41
        self::assertSame($propertyA, $metadata->getDefaultProperty());
42
    }
43
}
44