Failed Conditions
Pull Request — master (#63)
by Adrien
14:14
created

AttributeReaderAdapterTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 19
c 1
b 0
f 0
dl 0
loc 52
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetMethodAnnotation() 0 3 1
A testGetClassAnnotations() 0 3 1
A setUp() 0 12 2
A testGetClassAnnotation() 0 3 1
A testGetPropertyAnnotations() 0 3 1
A testGetPropertyAnnotation() 0 5 1
A testGetMethodAnnotations() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLTests\Doctrine\Factory\MetadataReader;
6
7
use Doctrine\ORM\Mapping\Column;
8
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
9
use Doctrine\ORM\Mapping\Driver\AttributeReader;
10
use Doctrine\ORM\Mapping\Entity;
11
use GraphQL\Doctrine\Factory\MetadataReader\AttributeReaderAdapter;
12
use GraphQLTests\Doctrine\AttributeBlog\Model\Post;
13
use GraphQLTests\Doctrine\TypesTrait;
14
use PHPUnit\Framework\TestCase;
15
use ReflectionClass;
16
use ReflectionMethod;
17
use ReflectionProperty;
18
use RuntimeException;
19
20
class AttributeReaderAdapterTest extends TestCase
21
{
22
    use TypesTrait {
23
        setUpWithAttributes as typeSetup;
24
    }
25
26
    private AttributeReaderAdapter $chainAdapter;
27
28
    protected function setUp(): void
29
    {
30
        $this->typeSetup();
31
32
        $config = $this->entityManager->getConfiguration();
33
        $mappingDriver = $config->getMetadataDriverImpl();
34
        if (!$mappingDriver instanceof AttributeDriver) {
35
            throw new RuntimeException('invalid runtime configuration: expected the metadata driver to be a ' . AttributeDriver::class);
36
        }
37
        /** @var AttributeReader $attributeReader */
38
        $attributeReader = $mappingDriver->getReader();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\Mapping\Dri...buteDriver::getReader() has been deprecated: no replacement planned. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

38
        $attributeReader = /** @scrutinizer ignore-deprecated */ $mappingDriver->getReader();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
39
        $this->chainAdapter = new AttributeReaderAdapter($attributeReader);
40
    }
41
42
    public function testGetClassAnnotations(): void
43
    {
44
        self::assertNotEmpty($this->chainAdapter->getClassAnnotations(new ReflectionClass(Post::class)));
45
    }
46
47
    public function testGetClassAnnotation(): void
48
    {
49
        self::assertNotNull($this->chainAdapter->getClassAnnotation(new ReflectionClass(Post::class), Entity::class));
50
    }
51
52
    public function testGetMethodAnnotations(): void
53
    {
54
        self::assertNotEmpty($this->chainAdapter->getMethodAnnotations(new ReflectionMethod(Post::class, 'getBody')));
55
    }
56
57
    public function testGetMethodAnnotation(): void
58
    {
59
        self::assertNotNull($this->chainAdapter->getMethodAnnotations(new ReflectionMethod(Post::class, 'getBody')));
60
    }
61
62
    public function testGetPropertyAnnotations(): void
63
    {
64
        self::assertNotEmpty($this->chainAdapter->getPropertyAnnotations(new ReflectionProperty(Post::class, 'body')));
65
    }
66
67
    public function testGetPropertyAnnotation(): void
68
    {
69
        self::assertNotNull($this->chainAdapter->getPropertyAnnotation(
70
            new ReflectionProperty(Post::class, 'body'),
71
            Column::class
72
        ));
73
    }
74
}
75