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

ReadOnlyTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 44.74 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 2
cbo 3
dl 17
loc 38
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\ReadOnly\Car;
6
use Happyr\SerializerBundle\Tests\Fixtures\ReadOnly\ClassReadOnly;
7
8
class ReadOnlyTest extends SerializerTestCase
9
{
10
    public function testSerialize()
11
    {
12
        $data = $this->serialize(new Car(true));
13
14
        $this->assertTrue(isset($data['model']));
15
        $this->assertTrue(isset($data['size']));
16
    }
17
18
    public function testDeserialize()
19
    {
20
        $data = ['model' => 'model_value', 'size' => 'size_value'];
21
        $obj = $this->deserialize($data, Car::class);
22
23
        $this->assertPropertyValue($obj, 'model', null);
24
        $this->assertPropertyValue($obj, 'size', 'size_value');
25
    }
26
27
    public function testSerializeReadOnlyClass()
28
    {
29
        $data = $this->serialize(new ClassReadOnly(true));
30
31
        $this->assertTrue(isset($data['model']));
32
        $this->assertTrue(isset($data['size']));
33
        $this->assertTrue(isset($data['color']));
34
    }
35
36
    public function testDeserializeReadOnlyClass()
37
    {
38
        $data = ['model' => 'model_value', 'size' => 'size_value', 'color' => 'color_value'];
39
        $obj = $this->deserialize($data, ClassReadOnly::class);
40
41
        $this->assertPropertyValue($obj, 'model', 'model_value');
42
        $this->assertPropertyValue($obj, 'size', null);
43
        $this->assertPropertyValue($obj, 'color', null);
44
    }
45
}
46