6
6
7
7
namespace Magento \Customer \Test \Unit \Model \Customer \Attribute \Backend ;
8
8
9
+ use Magento \Framework \DataObject ;
9
10
use Magento \Framework \Stdlib \StringUtils ;
10
11
use Magento \Customer \Model \Customer \Attribute \Backend \Password ;
11
12
@@ -25,14 +26,15 @@ protected function setUp()
25
26
public function testValidatePositive ()
26
27
{
27
28
$ password = 'password ' ;
28
- $ object = $ this ->getMockBuilder ('Magento\Framework\DataObject ' )
29
+
30
+ /** @var DataObject|\PHPUnit_Framework_MockObject_MockObject $object */
31
+ $ object = $ this ->getMockBuilder (DataObject::class)
29
32
->disableOriginalConstructor ()
30
33
->setMethods (['getPassword ' , 'getPasswordConfirm ' ])
31
34
->getMock ();
32
35
33
- $ object ->expects ($ this ->once ())->method ('getPassword ' )->will ($ this ->returnValue ($ password ));
34
- $ object ->expects ($ this ->once ())->method ('getPasswordConfirm ' )->will ($ this ->returnValue ($ password ));
35
- /** @var \Magento\Framework\DataObject $object */
36
+ $ object ->expects ($ this ->once ())->method ('getPassword ' )->willReturn ($ password );
37
+ $ object ->expects ($ this ->once ())->method ('getPasswordConfirm ' )->willReturn ($ password );
36
38
37
39
$ this ->assertTrue ($ this ->testable ->validate ($ object ));
38
40
}
@@ -52,13 +54,13 @@ public function passwordNegativeDataProvider()
52
54
*/
53
55
public function testBeforeSaveNegative ($ password )
54
56
{
55
- $ object = $ this ->getMockBuilder ('Magento\Framework\DataObject ' )
57
+ /** @var DataObject|\PHPUnit_Framework_MockObject_MockObject $object */
58
+ $ object = $ this ->getMockBuilder (DataObject::class)
56
59
->disableOriginalConstructor ()
57
60
->setMethods (['getPassword ' ])
58
61
->getMock ();
59
62
60
- $ object ->expects ($ this ->once ())->method ('getPassword ' )->will ($ this ->returnValue ($ password ));
61
- /** @var \Magento\Framework\DataObject $object */
63
+ $ object ->expects ($ this ->once ())->method ('getPassword ' )->willReturn ($ password );
62
64
63
65
$ this ->testable ->beforeSave ($ object );
64
66
}
@@ -67,16 +69,62 @@ public function testBeforeSavePositive()
67
69
{
68
70
$ password = 'more-then-6 ' ;
69
71
$ passwordHash = 'password-hash ' ;
70
- $ object = $ this ->getMockBuilder ('Magento\Framework\DataObject ' )
72
+
73
+ /** @var DataObject|\PHPUnit_Framework_MockObject_MockObject $object */
74
+ $ object = $ this ->getMockBuilder (DataObject::class)
71
75
->disableOriginalConstructor ()
72
76
->setMethods (['getPassword ' , 'setPasswordHash ' , 'hashPassword ' ])
73
77
->getMock ();
74
78
75
- $ object ->expects ($ this ->once ())->method ('getPassword ' )->will ($ this ->returnValue ($ password ));
76
- $ object ->expects ($ this ->once ())->method ('hashPassword ' )->will ($ this ->returnValue ($ passwordHash ));
77
- $ object ->expects ($ this ->once ())->method ('setPasswordHash ' )->with ($ passwordHash )->will ($ this ->returnSelf ());
78
- /** @var \Magento\Framework\DataObject $object */
79
+ $ object ->expects ($ this ->once ())->method ('getPassword ' )->willReturn ($ password );
80
+ $ object ->expects ($ this ->once ())->method ('hashPassword ' )->willReturn ($ passwordHash );
81
+ $ object ->expects ($ this ->once ())->method ('setPasswordHash ' )->with ($ passwordHash )->willReturnSelf ();
79
82
80
83
$ this ->testable ->beforeSave ($ object );
81
84
}
85
+
86
+ /**
87
+ * @return array
88
+ */
89
+ public function randomValuesProvider ()
90
+ {
91
+ return [
92
+ [false ],
93
+ [1 ],
94
+ ["23 " ],
95
+ [null ],
96
+ ["" ],
97
+ [-1 ],
98
+ [12.3 ],
99
+ [true ],
100
+ [0 ],
101
+ ];
102
+ }
103
+
104
+ /**
105
+ * @dataProvider randomValuesProvider
106
+ * @param mixed $randomValue
107
+ */
108
+ public function testCustomerGetPasswordAndGetPasswordConfirmAlwaysReturnsAString ($ randomValue )
109
+ {
110
+ /** @var \Magento\Customer\Model\Customer|\PHPUnit_Framework_MockObject_MockObject $customer */
111
+ $ customer = $ this ->getMockBuilder (\Magento \Customer \Model \Customer::class)
112
+ ->disableOriginalConstructor ()
113
+ ->setMethods (['getData ' ])
114
+ ->getMock ();
115
+
116
+ $ customer ->expects ($ this ->exactly (2 ))->method ('getData ' )->willReturn ($ randomValue );
117
+
118
+ $ this ->assertInternalType (
119
+ 'string ' ,
120
+ $ customer ->getPassword (),
121
+ 'Customer password should always return a string '
122
+ );
123
+
124
+ $ this ->assertInternalType (
125
+ 'string ' ,
126
+ $ customer ->getPasswordConfirm (),
127
+ 'Customer password-confirm should always return a string '
128
+ );
129
+ }
82
130
}
0 commit comments