Completed
Push — master ( 2e5350...f0c5b4 )
by Tobias
10:07
created

SerializedNameTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 76.47 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 3
c 5
b 1
f 1
lcom 1
cbo 2
dl 26
loc 34
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Happyr\SerializerBundle\Tests\Functional;
4
5
use Happyr\SerializerBundle\Tests\Fixtures\SerializedName\Car;
6
7
class SerializedNameTest extends SerializerTestCase
8
{
9
    public function testSerialize()
10
    {
11
        $data = $this->serialize(new Car(true));
12
13
        $this->assertTrue(isset($data['super_model']));
14
        $this->assertTrue(isset($data['car_size']));
15
        $this->assertTrue(isset($data['color']));
16
    }
17
18
    public function testDeserialize()
19
    {
20
        $data = ['super_model' => 'model_val', 'car_size' => 'size_val', 'color' => 'color_val'];
21
        $obj = $this->deserialize($data, Car::class);
22
23
        $this->assertPropertyValue($obj, 'model', 'model_val');
24
        $this->assertPropertyValue($obj, 'carSize', 'size_val');
25
        $this->assertPropertyValue($obj, 'color', 'color_val');
26
    }
27
28
    /**
29
     * Test when the json data is named as the properties. They should be ignored.
30
     */
31
    public function testDeserializeWhenIgnoringSerializedName()
32
    {
33
        $data = ['model' => 'model_val', 'carSize' => 'size_val', 'color' => 'color_val'];
34
        $obj = $this->deserialize($data, Car::class);
35
36
        $this->assertPropertyValue($obj, 'model', null);
37
        $this->assertPropertyValue($obj, 'carSize', null);
38
        $this->assertPropertyValue($obj, 'color', 'color_val');
39
    }
40
}
41