1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\AddressBundle\Tests\Entity; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\AddressBundle\Entity\AbstractTypedAddress; |
6
|
|
|
use Oro\Bundle\AddressBundle\Entity\AddressType; |
7
|
|
|
|
8
|
|
|
class AbstractTypedAddressTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var AbstractTypedAddress |
12
|
|
|
*/ |
13
|
|
|
protected $address; |
14
|
|
|
|
15
|
|
|
protected function setUp() |
16
|
|
|
{ |
17
|
|
|
$this->address = $this->getMockForAbstractClass('Oro\Bundle\AddressBundle\Entity\AbstractTypedAddress'); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
protected function tearDown() |
21
|
|
|
{ |
22
|
|
|
unset($this->address); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testAddType() |
26
|
|
|
{ |
27
|
|
|
$this->assertEmpty($this->address->getTypes()->toArray()); |
28
|
|
|
|
29
|
|
|
$type = new AddressType('testAddressType'); |
30
|
|
|
|
31
|
|
|
// add type in first time |
32
|
|
|
$this->address->addType($type); |
33
|
|
|
$types = $this->address->getTypes(); |
34
|
|
|
$this->assertCount(1, $types); |
35
|
|
|
$this->assertContains($type, $types); |
36
|
|
|
|
37
|
|
|
// type should be added only once |
38
|
|
|
$this->address->addType($type); |
39
|
|
|
$types = $this->address->getTypes(); |
40
|
|
|
$this->assertCount(1, $types); |
41
|
|
|
$this->assertContains($type, $types); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGetTypeNames() |
45
|
|
|
{ |
46
|
|
|
$this->assertEquals(array(), $this->address->getTypeNames()); |
47
|
|
|
|
48
|
|
|
$this->address->addType(new AddressType('billing')); |
49
|
|
|
$this->address->addType(new AddressType('shipping')); |
50
|
|
|
|
51
|
|
|
$this->assertEquals(array('billing', 'shipping'), $this->address->getTypeNames()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetTypeLabels() |
55
|
|
|
{ |
56
|
|
|
$this->assertEquals(array(), $this->address->getTypeLabels()); |
57
|
|
|
|
58
|
|
|
$billing = new AddressType('billing'); |
59
|
|
|
$billing->setLabel('Billing'); |
60
|
|
|
$this->address->addType($billing); |
61
|
|
|
|
62
|
|
|
$shipping = new AddressType('shipping'); |
63
|
|
|
$shipping->setLabel('Shipping'); |
64
|
|
|
$this->address->addType($shipping); |
65
|
|
|
|
66
|
|
|
$this->assertEquals(array('Billing', 'Shipping'), $this->address->getTypeLabels()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetTypeByName() |
70
|
|
|
{ |
71
|
|
|
$addressType = new AddressType('billing'); |
72
|
|
|
$this->address->addType($addressType); |
73
|
|
|
|
74
|
|
|
$this->assertSame($addressType, $this->address->getTypeByName('billing')); |
75
|
|
|
$this->assertNull($this->address->getTypeByName('shipping')); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testHasTypeWithName() |
79
|
|
|
{ |
80
|
|
|
$this->address->addType(new AddressType('billing')); |
81
|
|
|
|
82
|
|
|
$this->assertTrue($this->address->hasTypeWithName('billing')); |
83
|
|
|
$this->assertFalse($this->address->hasTypeWithName('shipping')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testPrimary() |
87
|
|
|
{ |
88
|
|
|
$this->assertFalse($this->address->isPrimary()); |
89
|
|
|
|
90
|
|
|
$this->address->setPrimary(true); |
91
|
|
|
|
92
|
|
|
$this->assertTrue($this->address->isPrimary()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testRemoveType() |
96
|
|
|
{ |
97
|
|
|
$type = new AddressType('testAddressType'); |
98
|
|
|
$this->address->addType($type); |
99
|
|
|
$this->assertCount(1, $this->address->getTypes()); |
100
|
|
|
|
101
|
|
|
$this->address->removeType($type); |
102
|
|
|
$this->assertEmpty($this->address->getTypes()->toArray()); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testIsEmpty() |
106
|
|
|
{ |
107
|
|
|
$this->assertTrue($this->address->isEmpty()); |
108
|
|
|
$this->address->setPrimary(true); |
109
|
|
|
$this->assertFalse($this->address->isEmpty()); |
110
|
|
|
$this->address->setPrimary(false); |
111
|
|
|
$this->address->addType(new AddressType('billing')); |
112
|
|
|
$this->assertFalse($this->address->isEmpty()); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
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..