1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the FreshVichUploaderSerializationBundle |
4
|
|
|
* |
5
|
|
|
* (c) Artem Genvald <[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 Genvald <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class VichSerializableFieldTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Test annotation with `value` option |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
public function testValueOption() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$annotation = new VichSerializableField(['value' => 'photoFile']); |
28
|
|
|
|
29
|
|
|
$this->assertEquals('photoFile', $annotation->getField()); |
30
|
|
|
$this->assertTrue($annotation->isIncludeHost()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Test annotation with `field` option |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function testFieldOption() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$annotation = new VichSerializableField(['field' => 'photoFile']); |
39
|
|
|
|
40
|
|
|
$this->assertEquals('photoFile', $annotation->getField()); |
41
|
|
|
$this->assertTrue($annotation->isIncludeHost()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Test annotation with `value` and `includeHost` options |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function testValueAndIncludeHostOptions() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$annotation = new VichSerializableField(['value' => 'photoFile', 'includeHost' => false]); |
50
|
|
|
|
51
|
|
|
$this->assertEquals('photoFile', $annotation->getField()); |
52
|
|
|
$this->assertFalse($annotation->isIncludeHost()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Test annotation without any option |
57
|
|
|
* |
58
|
|
|
* @expectedException \LogicException |
59
|
|
|
*/ |
60
|
|
|
public function testAnnotationWithoutOptions() |
61
|
|
|
{ |
62
|
|
|
new VichSerializableField([]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Test annotation without `value` or `field` options |
67
|
|
|
* |
68
|
|
|
* @expectedException \LogicException |
69
|
|
|
*/ |
70
|
|
|
public function testAnnotationWithoutIncludeHostOption() |
71
|
|
|
{ |
72
|
|
|
new VichSerializableField(['includeHost' => false]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Test annotation with wrong type for `value` option |
77
|
|
|
* |
78
|
|
|
* @expectedException \InvalidArgumentException |
79
|
|
|
*/ |
80
|
|
|
public function testWrongTypeForValueOption() |
81
|
|
|
{ |
82
|
|
|
new VichSerializableField(['value' => 123]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Test annotation with wrong type for `field` option |
87
|
|
|
* |
88
|
|
|
* @expectedException \InvalidArgumentException |
89
|
|
|
*/ |
90
|
|
|
public function testWrongTypeForFieldOption() |
91
|
|
|
{ |
92
|
|
|
new VichSerializableField(['field' => 123]); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Test annotation with wrong type for `includeHost` option |
97
|
|
|
* |
98
|
|
|
* @expectedException \InvalidArgumentException |
99
|
|
|
*/ |
100
|
|
|
public function testWrongTypeForFieldIncludeHost() |
101
|
|
|
{ |
102
|
|
|
new VichSerializableField(['value' => 'photoFile', 'includeHost' => 123]); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.