Completed
Push — master ( 9c5fdf...27a5d2 )
by John
7s
created

ObjectSerializerTest::getTestSchema()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 23
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Tests\Serialize\Serializer;
10
11
use KleijnWeb\SwaggerBundle\Document\Specification;
12
use KleijnWeb\SwaggerBundle\Serialize\SerializationTypeResolver;
13
use KleijnWeb\SwaggerBundle\Serialize\Serializer\ObjectSerializer;
14
15
/**
16
 * @author John Kleijn <[email protected]>
17
 */
18
abstract class ObjectSerializerTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var \PHPUnit_Framework_MockObject_MockObject
22
     */
23
    protected $typeResolverMock;
24
25
    /**
26
     * @var ObjectSerializer
27
     */
28
    protected $serializer;
29
30
    /**
31
     * @var Specification
32
     */
33
    protected $specification;
34
35
    protected function setUp()
36
    {
37
        parent::setUp();
38
39
        /** @var SerializationTypeResolver $typeResolver */
40
        $typeResolver = $this->typeResolverMock = $this->getMockBuilder(SerializationTypeResolver::class)
41
            ->disableOriginalConstructor()
42
            ->getMock();
43
44
        /** @var \PHPUnit_Framework_MockObject_MockObject $specificationMock */
45
        $specificationMock = $this->specification = $this->getMockBuilder(Specification::class)
46
            ->disableOriginalConstructor()
47
            ->getMock();
48
49
        $specificationMock->expects($this->any())->method('getResourceDefinition')->willReturn(self::getTestSchema());
50
51
        $this->serializer = new ObjectSerializer($typeResolver);
52
    }
53
54
    /**
55
     * @return \stdClass
56
     */
57
    protected static function getTestSchema(): \stdClass
58
    {
59
        return (object)[
60
            'class'      => 'Foo',
61
            'type'       => 'object',
62
            'properties' => (object)[
63
                'a'         => (object)['type' => 'int'],
64
                'aDate'     => (object)['type' => 'string', 'format' => 'date'],
65
                'aDateTime' => (object)['type' => 'string', 'format' => 'date-time'],
66
                'bar'       => (object)[
67
                    'class'      => 'Bar',
68
                    'type'       => 'object',
69
                    'properties' => (object)[
70
                        'b'    => (object)['type' => 'int'],
71
                        'meh'  => (object)[
72
                            'class'      => 'Meh',
73
                            'type'       => 'object',
74
                            'properties' => (object)['a' => (object)['type' => 'int']]
75
                        ],
76
                        'mehs' => (object)[
77
                            'type'  => 'array',
78
                            'items' => (object)[
79
                                'class'      => 'Meh',
80
                                'type'       => 'object',
81
                                'properties' => (object)['a' => (object)['type' => 'int']]
82
                            ]
83
                        ]
84
                    ]
85
                ]
86
            ]
87
        ];
88
    }
89
}
90