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

ObjectSerializationTest::serializationProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 9.7692
c 0
b 0
f 0
cc 1
eloc 35
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Tests\Serialize\Serializer\Stubs\Bar;
13
use KleijnWeb\SwaggerBundle\Tests\Serialize\Serializer\Stubs\Foo;
14
use KleijnWeb\SwaggerBundle\Tests\Serialize\Serializer\Stubs\Meh;
15
16
/**
17
 * @author John Kleijn <[email protected]>
18
 */
19
class ObjectSerializationTest extends ObjectSerializerTest
20
{
21
    /**
22
     * @test
23
     *
24
     * @param Foo    $data
25
     * @param string $expected
26
     *
27
     * @dataProvider  serializationProvider
28
     */
29
    public function canSerialize(Foo $data, string $expected)
30
    {
31
        $actual = $this->serializer->serialize($data, $this->specification);
32
        $this->assertSame($expected, $actual);
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function serializationProvider(): array
39
    {
40
        return [
41
            [
42
                new Foo('5', new Bar(6, new Meh(1), new Meh(2), new Meh(3))),
43
                json_encode([
44
                    'a'   => '5',
45
                    'bar' => [
46
                        'b'    => 6,
47
                        'meh'  => ['c' => 1],
48
                        'mehs' => [
49
                            ['c' => 2],
50
                            ['c' => 3],
51
                        ]
52
                    ]
53
                ])
54
            ],
55
            [
56
                // Since this will not pass validation, were going to allow it
57
                new Foo('5', new Bar(6, new Meh([1]), new Meh(2), new Meh(3))),
58
                json_encode([
59
                    'a'   => '5',
60
                    'bar' => [
61
                        'b'    => 6,
62
                        'meh'  => ['c' => [1]],
63
                        'mehs' => [
64
                            ['c' => 2],
65
                            ['c' => 3],
66
                        ]
67
                    ]
68
                ])
69
            ],
70
            [
71
                new Foo(
72
                    '5',
73
                    new Bar(6, new Meh([1]), new Meh(2), new Meh(3)),
74
                    new \DateTime('midnight'),
75
                    new \DateTime()
76
                ),
77
                json_encode([
78
                    'a'         => '5',
79
                    'bar' => [
80
                        'b'    => 6,
81
                        'meh'  => ['c' => [1]],
82
                        'mehs' => [
83
                            ['c' => 2],
84
                            ['c' => 3],
85
                        ]
86
                    ],
87
                    'aDate'     => (new \DateTime('midnight'))->format('Y-m-d'),
88
                    'aDateTime' => (new \DateTime())->format(\DateTime::ISO8601),
89
                ]),
90
            ],
91
        ];
92
    }
93
}
94