1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\AddressBundle\Tests\Entity; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\AddressBundle\Entity\AbstractEmail; |
6
|
|
|
|
7
|
|
View Code Duplication |
class AbstractEmailTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var AbstractEmail |
11
|
|
|
*/ |
12
|
|
|
protected $email; |
13
|
|
|
|
14
|
|
|
protected function setUp() |
15
|
|
|
{ |
16
|
|
|
$this->email = $this->createEmail(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function tearDown() |
20
|
|
|
{ |
21
|
|
|
unset($this->email); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testConstructor() |
25
|
|
|
{ |
26
|
|
|
$this->email = $this->createEmail('[email protected]'); |
27
|
|
|
|
28
|
|
|
$this->assertEquals('[email protected]', $this->email->getEmail()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testId() |
32
|
|
|
{ |
33
|
|
|
$this->assertNull($this->email->getId()); |
34
|
|
|
$this->email->setId(100); |
35
|
|
|
$this->assertEquals(100, $this->email->getId()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testEmail() |
39
|
|
|
{ |
40
|
|
|
$this->assertNull($this->email->getEmail()); |
41
|
|
|
$this->email->setEmail('[email protected]'); |
42
|
|
|
$this->assertEquals('[email protected]', $this->email->getEmail()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testToString() |
46
|
|
|
{ |
47
|
|
|
$this->assertEquals('', (string)$this->email); |
48
|
|
|
$this->email->setEmail('[email protected]'); |
49
|
|
|
$this->assertEquals('[email protected]', (string)$this->email); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testPrimary() |
53
|
|
|
{ |
54
|
|
|
$this->assertFalse($this->email->isPrimary()); |
55
|
|
|
$this->email->setPrimary(true); |
56
|
|
|
$this->assertTrue($this->email->isPrimary()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testIsEmpty() |
60
|
|
|
{ |
61
|
|
|
$this->assertTrue($this->createEmail()->isEmpty()); |
62
|
|
|
$this->assertFalse($this->createEmail('[email protected]')->isEmpty()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider isEqualDataProvider |
67
|
|
|
* |
68
|
|
|
* @param AbstractEmail $first |
69
|
|
|
* @param mixed $second |
70
|
|
|
* @param bool $expectedResult |
71
|
|
|
*/ |
72
|
|
|
public function testIsEqual(AbstractEmail $first, $second, $expectedResult) |
73
|
|
|
{ |
74
|
|
|
$this->assertEquals($expectedResult, $first->isEqual($second)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function isEqualDataProvider() |
81
|
|
|
{ |
82
|
|
|
$emailEmpty = $this->createEmail(); |
83
|
|
|
$emailAddress = $this->createEmail('[email protected]'); |
84
|
|
|
|
85
|
|
|
return array( |
86
|
|
|
'both empty' => array($emailEmpty, $emailEmpty, true), |
87
|
|
|
'one empty one unset' => array($emailEmpty, null, false), |
88
|
|
|
'one empty' => array($this->createEmail(100), $emailEmpty, false), |
89
|
|
|
'both with same id' => array($this->createEmail('[email protected]', 100), $this->createEmail('[email protected]', 100), true), |
90
|
|
|
'equals not empty' => array($emailAddress, $emailAddress, true), |
91
|
|
|
'not equals not empty' => array($emailAddress, $this->createEmail('[email protected]'), false), |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string|null $email |
97
|
|
|
* @param int $id |
98
|
|
|
* @return AbstractEmail|\PHPUnit_Framework_MockObject_MockObject |
99
|
|
|
*/ |
100
|
|
|
protected function createEmail($email = null, $id = null) |
101
|
|
|
{ |
102
|
|
|
$arguments = array(); |
103
|
|
|
|
104
|
|
|
if ($email) { |
105
|
|
|
$arguments[] = $email; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** @var AbstractEmail $email */ |
109
|
|
|
$email = $this->getMockForAbstractClass('Oro\Bundle\AddressBundle\Entity\AbstractEmail', $arguments); |
110
|
|
|
|
111
|
|
|
if ($id) { |
|
|
|
|
112
|
|
|
$email->setId($id); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $email; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: