1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\AddressBundle\Tests\Unit\Form\Type; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\AddressBundle\Form\Type\TypedAddressType; |
6
|
|
|
|
7
|
|
|
class TypedAddressTypeTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|TypedAddressType |
11
|
|
|
*/ |
12
|
|
|
protected $type; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Setup test env |
16
|
|
|
*/ |
17
|
|
|
protected function setUp() |
18
|
|
|
{ |
19
|
|
|
$this->type = new TypedAddressType(); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @dataProvider buildFormDataProvider |
24
|
|
|
* |
25
|
|
|
* @param array $options |
26
|
|
|
* @param bool $expectAddSubscriber |
27
|
|
|
*/ |
28
|
|
|
public function testBuildForm(array $options, $expectAddSubscriber) |
29
|
|
|
{ |
30
|
|
|
$builder = $this->getMockBuilder('Symfony\Component\Form\FormBuilder') |
31
|
|
|
->disableOriginalConstructor() |
32
|
|
|
->getMock(); |
33
|
|
|
|
34
|
|
|
$at = 0; |
35
|
|
|
|
36
|
|
|
if ($expectAddSubscriber) { |
37
|
|
|
$builder->expects($this->at($at++)) |
38
|
|
|
->method('addEventSubscriber') |
39
|
|
|
->with( |
40
|
|
|
$this->isInstanceOf( |
41
|
|
|
'Oro\Bundle\AddressBundle\Form\EventListener\FixAddressesPrimarySubscriber' |
42
|
|
|
) |
43
|
|
|
) |
44
|
|
|
->will($this->returnSelf()); |
45
|
|
|
|
46
|
|
|
$builder->expects($this->at($at++)) |
47
|
|
|
->method('addEventSubscriber') |
48
|
|
|
->with( |
49
|
|
|
$this->isInstanceOf( |
50
|
|
|
'Oro\Bundle\AddressBundle\Form\EventListener\FixAddressesTypesSubscriber' |
51
|
|
|
) |
52
|
|
|
) |
53
|
|
|
->will($this->returnSelf()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$builder->expects($this->at($at++)) |
57
|
|
|
->method('add') |
58
|
|
|
->with( |
59
|
|
|
'types', |
60
|
|
|
'translatable_entity', |
61
|
|
|
array( |
62
|
|
|
'class' => 'OroAddressBundle:AddressType', |
63
|
|
|
'property' => 'label', |
64
|
|
|
'required' => false, |
65
|
|
|
'multiple' => true, |
66
|
|
|
'expanded' => true, |
67
|
|
|
) |
68
|
|
|
) |
69
|
|
|
->will($this->returnSelf()); |
70
|
|
|
|
71
|
|
|
$builder->expects($this->at($at++)) |
72
|
|
|
->method('add') |
73
|
|
|
->with( |
74
|
|
|
'primary', |
75
|
|
|
'checkbox', |
76
|
|
|
array( |
77
|
|
|
'required' => false |
78
|
|
|
) |
79
|
|
|
) |
80
|
|
|
->will($this->returnSelf()); |
81
|
|
|
|
82
|
|
|
$this->type->buildForm($builder, $options); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function buildFormDataProvider() |
86
|
|
|
{ |
87
|
|
|
return array( |
88
|
|
|
array( |
89
|
|
|
'options' => array( |
90
|
|
|
'single_form' => false, |
91
|
|
|
'all_addresses_property_path' => null, |
92
|
|
|
), |
93
|
|
|
'expectAddSubscriber' => false |
94
|
|
|
), |
95
|
|
|
array( |
96
|
|
|
'options' => array( |
97
|
|
|
'single_form' => true, |
98
|
|
|
'all_addresses_property_path' => null, |
99
|
|
|
), |
100
|
|
|
'expectAddSubscriber' => false |
101
|
|
|
), |
102
|
|
|
array( |
103
|
|
|
'options' => array( |
104
|
|
|
'single_form' => true, |
105
|
|
|
'all_addresses_property_path' => 'owner.addresses', |
106
|
|
|
), |
107
|
|
|
'expectAddSubscriber' => true |
108
|
|
|
) |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testGetParent() |
113
|
|
|
{ |
114
|
|
|
$this->assertEquals('oro_address', $this->type->getParent()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testGetName() |
118
|
|
|
{ |
119
|
|
|
$this->assertEquals('oro_typed_address', $this->type->getName()); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..