Completed
Push — master ( 232324...f3371f )
by Artem
12s
created

VichSerializableFieldTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 21.21 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 14
loc 66
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
 * This file is part of the FreshVichUploaderSerializationBundle
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fresh\VichUploaderSerializationBundle\Tests\Annotation;
12
13
use Fresh\VichUploaderSerializationBundle\Annotation\VichSerializableField;
14
15
/**
16
 * VichSerializableFieldTest.
17
 *
18
 * @author Artem Henvald <[email protected]>
19
 */
20
class VichSerializableFieldTest extends \PHPUnit_Framework_TestCase
21
{
22
    public function testValueOption()
23
    {
24
        $annotation = new VichSerializableField(['value' => 'photoFile']);
25
26
        $this->assertEquals('photoFile', $annotation->getField());
27
        $this->assertTrue($annotation->isIncludeHost());
28
    }
29
30
    public function testFieldOption()
31
    {
32
        $annotation = new VichSerializableField(['field' => 'photoFile']);
33
34
        $this->assertEquals('photoFile', $annotation->getField());
35
        $this->assertTrue($annotation->isIncludeHost());
36
    }
37
38
    public function testValueAndIncludeHostOptions()
39
    {
40
        $annotation = new VichSerializableField(['value' => 'photoFile', 'includeHost' => false]);
41
42
        $this->assertEquals('photoFile', $annotation->getField());
43
        $this->assertFalse($annotation->isIncludeHost());
44
    }
45
46
    /**
47
     * @expectedException \LogicException
48
     */
49
    public function testAnnotationWithoutOptions()
50
    {
51
        new VichSerializableField([]);
52
    }
53
54
    /**
55
     * @expectedException \LogicException
56
     */
57
    public function testAnnotationWithoutIncludeHostOption()
58
    {
59
        new VichSerializableField(['includeHost' => false]);
60
    }
61
62
    /**
63
     * @expectedException \InvalidArgumentException
64
     */
65
    public function testWrongTypeForValueOption()
66
    {
67
        new VichSerializableField(['value' => 123]);
68
    }
69
70
    /**
71
     * @expectedException \InvalidArgumentException
72
     */
73
    public function testWrongTypeForFieldOption()
74
    {
75
        new VichSerializableField(['field' => 123]);
76
    }
77
78
    /**
79
     * @expectedException \InvalidArgumentException
80
     */
81
    public function testWrongTypeForFieldIncludeHost()
82
    {
83
        new VichSerializableField(['value' => 'photoFile', 'includeHost' => 123]);
84
    }
85
}
86