JmsMetadataParserTest::testParseGroups()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Mathielen\ImportEngine\Storage\Parser;
3
4
use Doctrine\Common\Annotations\AnnotationReader;
5
use JMS\Serializer\Metadata\Driver\AnnotationDriver;
6
use JMS\Serializer\Annotation\Type;
7
use JMS\Serializer\Annotation\Groups;
8
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
9
use Metadata\MetadataFactory;
10
11
class JmsMetadataParserTest extends \PHPUnit_Framework_TestCase
12
{
13
14
    private $parser;
15
    private $metadataFactory;
16
17
    protected function setUp()
18
    {
19
        $this->metadataFactory = new MetadataFactory(
20
            new AnnotationDriver(
0 ignored issues
show
Bug introduced by
The call to AnnotationDriver::__construct() misses a required argument $namingStrategy.

This check looks for function calls that miss required arguments.

Loading history...
21
                new AnnotationReader()
22
            )
23
        );
24
25
        $this->parser = new JmsMetadataParser(
26
            $this->metadataFactory,
27
            new IdenticalPropertyNamingStrategy()
28
        );
29
    }
30
31
    public function testParse()
32
    {
33
        $classname = 'Mathielen\ImportEngine\Storage\Parser\JmsMetadataParserTestClass';
34
        $result = $this->parser->parse(array('class'=>$classname, 'groups'=>array()));
35
36
        $this->assertEquals(4, count($result));
37
        $this->assertEquals('object (NestedType)', $result['property']['dataType']);
38
        $this->assertEquals('custom handler result for (IamACustomHandler)', $result['customHandler']['dataType']);
39
        $this->assertEquals('array of integers', $result['array']['dataType']);
40
        $this->assertEquals('array of objects (NestedType)', $result['assocArray']['dataType']);
41
    }
42
43
    public function testParseGroups()
44
    {
45
        $classname = 'Mathielen\ImportEngine\Storage\Parser\JmsMetadataParserTestClass';
46
        $result = $this->parser->parse(array('class'=>$classname, 'groups'=>array('group1')));
47
48
        $this->assertEquals(1, count($result));
49
    }
50
51
}
52
53
class JmsMetadataParserTestClass
54
{
55
56
    /**
57
     * @Type("Mathielen\ImportEngine\Storage\Parser\NestedType")
58
     */
59
    private $property;
60
61
    /**
62
     * @Type("IamACustomHandler")
63
     * @Groups({"group1"})
64
     */
65
    private $customHandler;
66
67
    /**
68
     * @Type("array<integer>")
69
     */
70
    private $array;
71
72
    /**
73
     * @Type("array<string, Mathielen\ImportEngine\Storage\Parser\NestedType>")
74
     */
75
    private $assocArray;
76
77
}
78
79
class NestedType
80
{
81
82
    /**
83
     * @Type("string")
84
     */
85
    private $property;
86
87
}
88