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

ExclusionPolicyTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 45.76 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 6
c 2
b 1
f 1
lcom 2
cbo 4
dl 27
loc 59
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\ExclusionPolicy\ExcludeAll;
6
use Happyr\SerializerBundle\Tests\Fixtures\ExclusionPolicy\ExcludeDefault;
7
use Happyr\SerializerBundle\Tests\Fixtures\ExclusionPolicy\ExcludeNone;
8
9
class ExclusionPolicyTest extends SerializerTestCase
10
{
11
    public function testSerializeDefault()
12
    {
13
        $data = $this->serialize(new ExcludeDefault(true));
14
15
        $this->assertFalse(isset($data['model']));
16
        $this->assertTrue(isset($data['size']));
17
        $this->assertTrue(isset($data['color']));
18
    }
19
20
    public function testSerializeNone()
21
    {
22
        $data = $this->serialize(new ExcludeNone(true));
23
24
        $this->assertFalse(isset($data['model']));
25
        $this->assertTrue(isset($data['size']));
26
        $this->assertTrue(isset($data['color']));
27
    }
28
29
    public function testSerializeAll()
30
    {
31
        $data = $this->serialize(new ExcludeAll(true));
32
33
        $this->assertFalse(isset($data['model']));
34
        $this->assertTrue(isset($data['size']));
35
        $this->assertFalse(isset($data['color']));
36
    }
37
38
    public function testDeserializeDefault()
39
    {
40
        $data = ['model' => 'model_value', 'size' => 'size_value', 'color' => 'color_value'];
41
        $obj = $this->deserialize($data, ExcludeDefault::class);
42
43
        $this->assertPropertyValue($obj, 'model', null);
44
        $this->assertPropertyValue($obj, 'size', 'size_value');
45
        $this->assertPropertyValue($obj, 'color', 'color_value');
46
    }
47
48
    public function testDeserializeNone()
49
    {
50
        $data = ['model' => 'model_value', 'size' => 'size_value', 'color' => 'color_value'];
51
        $obj = $this->deserialize($data, ExcludeNone::class);
52
53
        $this->assertPropertyValue($obj, 'model', null);
54
        $this->assertPropertyValue($obj, 'size', 'size_value');
55
        $this->assertPropertyValue($obj, 'color', 'color_value');
56
    }
57
58
    public function testDeserializeAll()
59
    {
60
        $data = ['model' => 'model_value', 'size' => 'size_value', 'color' => 'color_value'];
61
        $obj = $this->deserialize($data, ExcludeAll::class);
62
63
        $this->assertPropertyValue($obj, 'model', null);
64
        $this->assertPropertyValue($obj, 'size', 'size_value');
65
        $this->assertPropertyValue($obj, 'color', null);
66
    }
67
}
68